Class: Sass::Script::Tree::MapLiteral

Inherits:
Node
  • Object
show all
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)

Attributes inherited from Node

#filename, #line, #options, #source_range

Instance Method Summary (collapse)

Methods inherited from Node

#force_division!, #perform

Constructor Details

#initialize(pairs) ⇒ MapLiteral

Creates a new map literal.

Parameters:



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.

Parameters:



14
15
16
# File '.ruby-sass/lib/sass/script/tree/map_literal.rb', line 14

def initialize(pairs)
  @pairs = pairs
end

Instance Attribute Details

#pairsArray<(Node, Node)> (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.

Returns:



9
10
11
# File '.ruby-sass/lib/sass/script/tree/map_literal.rb', line 9

def pairs
  @pairs
end

Instance Method Details

#childrenObject

See Also:



19
20
21
# File '.ruby-sass/lib/sass/script/tree/map_literal.rb', line 19

def children
  @pairs.flatten
end

#deep_copyObject

See Also:



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

See Also:



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