Class: Sass::Script::List

Inherits:
Literal show all
Defined in:
lib/sass/script/list.rb

Overview

A SassScript object representing a CSS list. This includes both comma-separated lists and space-separated lists.

Instance Attribute Summary collapse

Attributes inherited from Node

#line, #options

Instance Method Summary collapse

Methods inherited from Literal

#==, #and, #assert_int!, #comma, #div, #minus, #neq, #options, #or, #plus, #single_eq, #space, #to_bool, #to_i, #unary_div, #unary_minus, #unary_not, #unary_plus

Methods inherited from Node

#dasherize, #opts, #perform

Constructor Details

#initialize(value, separator) ⇒ List

Creates a new list.

Parameters:



22
23
24
25
# File 'lib/sass/script/list.rb', line 22

def initialize(value, separator)
  super(value)
  @separator = separator
end

Instance Attribute Details

#separatorSymbol (readonly)

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

Returns:

  • (Symbol)


16
17
18
# File 'lib/sass/script/list.rb', line 16

def separator
  @separator
end

#valueArray<Literal> (readonly) Also known as: children, to_a

The Ruby array containing the contents of the list.

Returns:



8
9
10
# File 'lib/sass/script/list.rb', line 8

def value
  @value
end

Instance Method Details

#_perform(environment) (protected)

See Also:



67
68
69
70
71
72
73
# File 'lib/sass/script/list.rb', line 67

def _perform(environment)
  list = Sass::Script::List.new(
    value.map {|e| e.perform(environment)},
    separator)
  list.options = self.options
  list
end

#deep_copy

See Also:



28
29
30
31
32
# File 'lib/sass/script/list.rb', line 28

def deep_copy
  node = dup
  node.instance_variable_set('@value', value.map {|c| c.deep_copy})
  node
end

#eq(other)

See Also:

  • Node#eq


35
36
37
38
39
# File 'lib/sass/script/list.rb', line 35

def eq(other)
  Sass::Script::Bool.new(
    self.class == other.class && self.value == other.value &&
    self.separator == other.separator)
end

#inspect

See Also:

  • Node#inspect


60
61
62
# File 'lib/sass/script/list.rb', line 60

def inspect
  "(#{to_sass})"
end

#to_s(opts = {})

Raises:

See Also:

  • Node#to_s


42
43
44
45
# File 'lib/sass/script/list.rb', line 42

def to_s(opts = {})
  raise Sass::SyntaxError.new("() isn't a valid CSS value.") if value.empty?
  return value.reject {|e| e.is_a?(List) && e.value.empty?}.map {|e| e.to_s(opts)}.join(sep_str)
end

#to_sass(opts = {})

See Also:



48
49
50
51
52
53
54
55
56
57
# File 'lib/sass/script/list.rb', line 48

def to_sass(opts = {})
  precedence = Sass::Script::Parser.precedence_of(separator)
  value.map do |v|
    if v.is_a?(List) && Sass::Script::Parser.precedence_of(v.separator) <= precedence
      "(#{v.to_sass(opts)})"
    else
      v.to_sass(opts)
    end
  end.join(sep_str(nil))
end