Class: Sass::Script::Tree::MapLiteral
- Inherits:
-  Node - Object
- Node
- Sass::Script::Tree::MapLiteral
 
- Defined in:
- /Users/ceppstei/Projects/sass-lang/.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)
-   - (Array<(Node, Node)>) pairs   readonly The key/value pairs that make up this map node. 
Attributes inherited from Node
#css_variable_warning, #filename, #line, #options, #source_range
Instance Method Summary (collapse)
- - _perform(environment) protected
- - children
- - deep_copy
-   - (MapLiteral) initialize(pairs)   constructor Creates a new map literal. 
- - to_sass(opts = {}) (also: #inspect)
Methods inherited from Node
#dasherize, #force_division!, #opts, #perform
Constructor Details
- (MapLiteral) initialize(pairs)
Creates a new map literal.
| 14 15 16 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/map_literal.rb', line 14
def initialize(pairs)
  @pairs = pairs
end | 
Instance Attribute Details
- (Array<(Node, Node)>) pairs (readonly)
The key/value pairs that make up this map node. This isn’t a Hash so that we can detect key collisions once all the keys have been performed.
| 9 10 11 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/map_literal.rb', line 9
def pairs
  @pairs
end | 
Instance Method Details
- _perform(environment) (protected)
| 50 51 52 53 54 55 56 57 58 59 60 61 62 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/map_literal.rb', line 50
def _perform(environment)
  keys = Set.new
  map = Sass::Script::Value::Map.new(Sass::Util.to_hash(pairs.map do |(k, v)|
    k, v = k.perform(environment), v.perform(environment)
    if keys.include?(k)
      raise Sass::SyntaxError.new("Duplicate key #{k.inspect} in map #{to_sass}.")
    end
    keys << k
    [k, v]
  end))
  map.options = options
  map
end | 
- children
| 19 20 21 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/map_literal.rb', line 19
def children
  @pairs.flatten
end | 
- deep_copy
| 40 41 42 43 44 45 | # File '/Users/ceppstei/Projects/sass-lang/.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 = {}) Also known as: inspect
| 24 25 26 27 28 29 30 31 32 33 34 35 36 | # File '/Users/ceppstei/Projects/sass-lang/.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 |