Class: Sass::Script::Tree::ListLiteral

Inherits:
Node
  • Object
show all
Defined in:
/home/nweiz/code/sass-site/.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)

Attributes inherited from Node

#filename, #line, #options, #source_range

Instance Method Summary (collapse)

Methods inherited from Node

#dasherize, #opts, #perform

Constructor Details

- (ListLiteral) initialize(elements, separator: nil, bracketed: false)

Creates a new list literal.

Parameters:



26
27
28
29
30
# File '/home/nweiz/code/sass-site/.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

- (Boolean) bracketed (readonly)

Whether the list is surrounded by square brackets.

Returns:

  • (Boolean)


19
20
21
# File '/home/nweiz/code/sass-site/.sass/lib/sass/script/tree/list_literal.rb', line 19

def bracketed
  @bracketed
end

- (Array<Node>) elements (readonly)

The parse nodes for members of this list.

Returns:



8
9
10
# File '/home/nweiz/code/sass-site/.sass/lib/sass/script/tree/list_literal.rb', line 8

def elements
  @elements
end

- (Symbol) separator (readonly)

The operator separating the values of the list. Either :comma or :space.

Returns:

  • (Symbol)


14
15
16
# File '/home/nweiz/code/sass-site/.sass/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 '/home/nweiz/code/sass-site/.sass/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

See Also:



33
# File '/home/nweiz/code/sass-site/.sass/lib/sass/script/tree/list_literal.rb', line 33

def children; elements; end

- deep_copy

See Also:



55
56
57
58
59
# File '/home/nweiz/code/sass-site/.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!



67
68
69
# File '/home/nweiz/code/sass-site/.sass/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 '/home/nweiz/code/sass-site/.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 = {})

See Also:

  • Value#to_sass


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File '/home/nweiz/code/sass-site/.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