Class: Sass::Script::Tree::MapLiteral
- Inherits:
-
Node
- Object
- Node
- Sass::Script::Tree::MapLiteral
- Defined in:
- .ruby-sass/lib/sass/script/tree/map_literal.rb
Overview
A class representing a map literal. When resolved, this returns a Node::Map.
Instance Attribute Summary (collapse)
-
#pairs ⇒ Array<(Node, Node)>
readonly
The key/value pairs that make up this map node.
Attributes inherited from Node
#filename, #line, #options, #source_range
Instance Method Summary (collapse)
- #children ⇒ Object
- #deep_copy ⇒ Object
-
#initialize(pairs) ⇒ MapLiteral
constructor
Creates a new map literal.
- #to_sass(opts = {}) ⇒ Object (also: #inspect)
Methods inherited from Node
Constructor Details
#initialize(pairs) ⇒ MapLiteral
Creates a new map literal.
14 15 16 |
# File '.ruby-sass/lib/sass/script/tree/map_literal.rb', line 14 def initialize(pairs) @pairs = pairs end |
Constructor Details
#initialize(pairs) ⇒ MapLiteral
Creates a new map literal.
14 15 16 |
# File '.ruby-sass/lib/sass/script/tree/map_literal.rb', line 14 def initialize(pairs) @pairs = pairs end |
Instance Attribute Details
Instance Method Details
#children ⇒ Object
19 20 21 |
# File '.ruby-sass/lib/sass/script/tree/map_literal.rb', line 19 def children @pairs.flatten end |
#deep_copy ⇒ Object
40 41 42 43 44 45 |
# File '.ruby-sass/lib/sass/script/tree/map_literal.rb', line 40 def deep_copy node = dup node.instance_variable_set('@pairs', pairs.map {|(k, v)| [k.deep_copy, v.deep_copy]}) node end |
#to_sass(opts = {}) ⇒ Object Also known as: inspect
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File '.ruby-sass/lib/sass/script/tree/map_literal.rb', line 24 def to_sass(opts = {}) return "()" if pairs.empty? to_sass = lambda do |value| if value.is_a?(ListLiteral) && value.separator == :comma "(#{value.to_sass(opts)})" else value.to_sass(opts) end end "(" + pairs.map {|(k, v)| "#{to_sass[k]}: #{to_sass[v]}"}.join(', ') + ")" end |