Class: Sass::Script::Tree::ListLiteral

Inherits:
Node
  • Object
show all
Defined in:
/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/list_literal.rb

Overview

A parse tree node representing a list literal. When resolved, this returns a Tree::Value::List.

Instance Attribute Summary (collapse)

Attributes inherited from Node

#css_variable_warning, #filename, #line, #options, #source_range

Instance Method Summary (collapse)

Methods inherited from Node

#dasherize, #opts, #perform

Constructor Details

- (ListLiteral) initialize(elements, separator)

Creates a new list literal.

Parameters:



20
21
22
23
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/list_literal.rb', line 20

def initialize(elements, separator)
  @elements = elements
  @separator = separator
end

Instance Attribute Details

- (Array<Node>) elements (readonly)

The parse nodes for members of this list.

Returns:



8
9
10
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/list_literal.rb', line 8

def elements
  @elements
end

- (Symbol) separator (readonly)

The operator separating the values of the list. Either :comma or :space.

Returns:

  • (Symbol)


14
15
16
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/list_literal.rb', line 14

def separator
  @separator
end

Instance Method Details

- _perform(environment) (protected)



61
62
63
64
65
66
67
68
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/list_literal.rb', line 61

def _perform(environment)
  list = Sass::Script::Value::List.new(
    elements.map {|e| e.perform(environment)},
    separator)
  list.source_range = source_range
  list.options = options
  list
end

- children

See Also:



26
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/list_literal.rb', line 26

def children; elements; end

- deep_copy

See Also:



45
46
47
48
49
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/list_literal.rb', line 45

def deep_copy
  node = dup
  node.instance_variable_set('@elements', elements.map {|e| e.deep_copy})
  node
end

- force_division!



55
56
57
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/list_literal.rb', line 55

def force_division!
  # Do nothing. Lists prevent division propagation.
end

- inspect



51
52
53
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/list_literal.rb', line 51

def inspect
  "(#{elements.map {|e| e.inspect}.join(separator == :space ? ' ' : ', ')})"
end

- to_sass(opts = {})

See Also:

  • Value#to_sass


29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/list_literal.rb', line 29

def to_sass(opts = {})
  return "()" if elements.empty?
  members = elements.map do |v|
    if element_needs_parens?(v)
      "(#{v.to_sass(opts)})"
    else
      v.to_sass(opts)
    end
  end

  return "(#{members.first},)" if separator == :comma && members.length == 1

  members.join(sep_str(nil))
end