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: nil, bracketed: false) ⇒ ListLiteral

Creates a new list literal.

Parameters:



26
27
28
29
30
# File 'lib/sass/script/tree/list_literal.rb', line 26

def initialize(elements, separator: nil, bracketed: false)
  @elements = elements
  @separator = separator
  @bracketed = bracketed
end

Instance Attribute Details

#bracketedBoolean (readonly)

Whether the list is surrounded by square brackets.

Returns:

  • (Boolean)


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

def bracketed
  @bracketed
end

#elementsArray<Node> (readonly)

The parse nodes for members of this list.

Returns:



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.

Returns:

  • (Symbol)


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

def separator
  @separator
end

Instance Method Details

#_perform(environment) (protected)



73
74
75
76
77
78
79
80
81
# File 'lib/sass/script/tree/list_literal.rb', line 73

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

#children

See Also:



33
# File 'lib/sass/script/tree/list_literal.rb', line 33

def children; elements; end

#deep_copy

See Also:



55
56
57
58
59
# File 'lib/sass/script/tree/list_literal.rb', line 55

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

#force_division!



67
68
69
# File 'lib/sass/script/tree/list_literal.rb', line 67

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

#inspect



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

def inspect
  (bracketed ? '[' : '(') +
    elements.map {|e| e.inspect}.join(separator == :space ? ' ' : ', ') +
    (bracketed ? ']' : ')')
end

#to_sass(opts = {})

See Also:

  • Value#to_sass


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/sass/script/tree/list_literal.rb', line 36

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

  if separator == :comma && members.length == 1
    return "#{bracketed ? '[' : '('}#{members.first},#{bracketed ? ']' : ')'}"
  end

  contents = members.join(sep_str(nil))
  bracketed ? "[#{contents}]" : contents
end