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

Inherits:
Node
  • Object
show all
Defined in:
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

#filename, #line, #options, #source_range

Instance Method Summary collapse

Methods inherited from Node

#dasherize, #opts, #perform

Constructor Details

#initialize(elements, separator) ⇒ ListLiteral

Creates a new list literal.


20
21
22
23
# File 'lib/sass/script/tree/list_literal.rb', line 20

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

Instance Attribute Details

#elementsArray<Node> (readonly)

The parse nodes for members of this list.


8
9
10
# File 'lib/sass/script/tree/list_literal.rb', line 8

def elements
  @elements
end

#separatorSymbol (readonly)

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


14
15
16
# File 'lib/sass/script/tree/list_literal.rb', line 14

def separator
  @separator
end

Instance Method Details

#_perform(environment) (protected)


60
61
62
63
64
65
66
67
# File 'lib/sass/script/tree/list_literal.rb', line 60

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 'lib/sass/script/tree/list_literal.rb', line 26

def children; elements; end

#deep_copy

See Also:


48
49
50
51
52
# File 'lib/sass/script/tree/list_literal.rb', line 48

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

#inspect


54
55
56
# File 'lib/sass/script/tree/list_literal.rb', line 54

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
43
44
45
# File 'lib/sass/script/tree/list_literal.rb', line 29

def to_sass(opts = {})
  return "()" if elements.empty?
  precedence = Sass::Script::Parser.precedence_of(separator)
  members = elements.map do |v|
    if v.is_a?(ListLiteral) && Sass::Script::Parser.precedence_of(v.separator) <= precedence ||
        separator == :space && v.is_a?(UnaryOperation) &&
        (v.operator == :minus || v.operator == :plus)
      "(#{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