Class: Sass::Script::Tree::ListLiteral
- 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
-
#bracketed ⇒ Boolean
readonly
Whether the list is surrounded by square brackets.
-
#elements ⇒ Array<Node>
readonly
The parse nodes for members of this list.
-
#separator ⇒ Symbol
readonly
The operator separating the values of the list.
Attributes inherited from Node
#filename, #line, #options, #source_range
Instance Method Summary collapse
- #_perform(environment) protected
- #children
- #deep_copy
- #force_division!
-
#initialize(elements, separator: nil, bracketed: false) ⇒ ListLiteral
constructor
Creates a new list literal.
- #inspect
- #to_sass(opts = {})
Methods inherited from Node
Constructor Details
#initialize(elements, separator: nil, bracketed: false) ⇒ ListLiteral
Creates a new list literal.
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
#bracketed ⇒ Boolean (readonly)
Whether the list is surrounded by square brackets.
19 20 21 |
# File 'lib/sass/script/tree/list_literal.rb', line 19
def bracketed
@bracketed
end
|
#elements ⇒ Array<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
|
#separator ⇒ Symbol (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)
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
33 |
# File 'lib/sass/script/tree/list_literal.rb', line 33
def children; elements; end
|
#deep_copy
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 = {})
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
|