Class: Sass::Script::Tree::ListLiteral
- Inherits:
-
Node
- Object
- Node
- Sass::Script::Tree::ListLiteral
- Defined in:
- .ruby-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)
-
#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)
- #children ⇒ Object
- #deep_copy ⇒ Object
- #force_division! ⇒ Object
-
#initialize(elements, separator: nil, bracketed: false) ⇒ ListLiteral
constructor
Creates a new list literal.
- #inspect ⇒ Object
- #to_sass(opts = {}) ⇒ Object
Methods inherited from Node
Constructor Details
#initialize(elements, separator: nil, bracketed: false) ⇒ ListLiteral
Creates a new list literal.
26 27 28 29 30 |
# File '.ruby-sass/lib/sass/script/tree/list_literal.rb', line 26 def initialize(elements, separator: nil, bracketed: false) @elements = elements @separator = separator @bracketed = bracketed end |
Constructor Details
#initialize(elements, separator: nil, bracketed: false) ⇒ ListLiteral
Creates a new list literal.
26 27 28 29 30 |
# File '.ruby-sass/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 '.ruby-sass/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 '.ruby-sass/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 '.ruby-sass/lib/sass/script/tree/list_literal.rb', line 14 def separator @separator end |
Instance Method Details
#children ⇒ Object
33 |
# File '.ruby-sass/lib/sass/script/tree/list_literal.rb', line 33 def children; elements; end |
#deep_copy ⇒ Object
55 56 57 58 59 |
# File '.ruby-sass/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! ⇒ Object
67 68 69 |
# File '.ruby-sass/lib/sass/script/tree/list_literal.rb', line 67 def force_division! # Do nothing. Lists prevent division propagation. end |
#inspect ⇒ Object
61 62 63 64 65 |
# File '.ruby-sass/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 = {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File '.ruby-sass/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 |