Class: Sass::Script::List
- 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
-
#separator ⇒ Symbol
readonly
The operator separating the values of the list.
-
#value ⇒ Array<Literal>
(also: #children, #to_a)
readonly
The Ruby array containing the contents of the list.
Attributes inherited from Node
Instance Method Summary collapse
- #_perform(environment) protected
- #eq(other)
-
#initialize(value, separator) ⇒ List
constructor
Creates a new list.
- #inspect
- #to_s(opts = {})
- #to_sass(opts = {})
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
Constructor Details
#initialize(value, separator) ⇒ List
Creates a new list.
22 23 24 25 |
# File 'lib/sass/script/list.rb', line 22
def initialize(value, separator)
super(value)
@separator = separator
end
|
Instance Attribute Details
#separator ⇒ Symbol (readonly)
The operator separating the values of the list.
Either :comma
or :space
.
16 17 18 |
# File 'lib/sass/script/list.rb', line 16
def separator
@separator
end
|
#value ⇒ Array<Literal> (readonly) Also known as: children, to_a
The Ruby array containing the contents of the list.
8 9 10 |
# File 'lib/sass/script/list.rb', line 8
def value
@value
end
|
Instance Method Details
#_perform(environment) (protected)
60 61 62 63 64 65 66 |
# File 'lib/sass/script/list.rb', line 60
def _perform(environment)
list = Sass::Script::List.new(
value.map {|e| e.perform(environment)},
separator)
list.options = self.options
list
end
|
#eq(other)
28 29 30 31 32 |
# File 'lib/sass/script/list.rb', line 28
def eq(other)
Sass::Script::Bool.new(
self.class == other.class && self.value == other.value &&
self.separator == other.separator)
end
|
#inspect
53 54 55 |
# File 'lib/sass/script/list.rb', line 53
def inspect
"(#{to_sass})"
end
|
#to_s(opts = {})
35 36 37 38 |
# File 'lib/sass/script/list.rb', line 35
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 = {})
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/sass/script/list.rb', line 41
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
|