Class: Sass::Script::List
Overview
A SassScript object representing a CSS list. This includes both comma-separated lists and space-separated lists.
Direct Known Subclasses
Instance Attribute Summary
- - (Symbol) separator readonly The operator separating the values of the list.
- - (Array<Literal>) value (also: #children, #to_a) readonly The Ruby array containing the contents of the list.
Instance Method Summary
- - _perform(environment) protected
- - deep_copy
- - eq(other)
- - (List) initialize(value, separator) constructor Creates a new list.
- - inspect
- - to_s(opts = {})
- - to_sass(opts = {})
Methods inherited from Literal
#==, #assert_int!, #div, #minus, #neq, #null?, #options, #plus, #single_eq, #to_bool, #to_i, #unary_div, #unary_minus, #unary_not, #unary_plus
Methods inherited from Node
Constructor Details
- (List) initialize(value, separator)
Creates a new list.
22 23 24 25 |
# File '/var/www/sass-pages/.sass/lib/sass/script/list.rb', line 22
def initialize(value, separator)
super(value)
@separator = separator
end
|
Instance Attribute Details
- (Symbol) separator (readonly)
The operator separating the values of the list. Either :comma or :space.
16 17 18 |
# File '/var/www/sass-pages/.sass/lib/sass/script/list.rb', line 16
def separator
@separator
end
|
- (Array<Literal>) value (readonly) Also known as: children, to_a
The Ruby array containing the contents of the list.
8 9 10 |
# File '/var/www/sass-pages/.sass/lib/sass/script/list.rb', line 8
def value
@value
end
|
Instance Method Details
- _perform(environment) (protected)
68 69 70 71 72 73 74 |
# File '/var/www/sass-pages/.sass/lib/sass/script/list.rb', line 68
def _perform(environment)
list = Sass::Script::List.new(
value.map {|e| e.perform(environment)},
separator)
list.options = self.options
list
end
|
- deep_copy
28 29 30 31 32 |
# File '/var/www/sass-pages/.sass/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)
35 36 37 38 39 |
# File '/var/www/sass-pages/.sass/lib/sass/script/list.rb', line 35
def eq(other)
Sass::Script::Bool.new(
other.is_a?(List) && self.value == other.value &&
self.separator == other.separator)
end
|
- inspect
61 62 63 |
# File '/var/www/sass-pages/.sass/lib/sass/script/list.rb', line 61
def inspect
"(#{to_sass})"
end
|
- to_s(opts = {})
42 43 44 45 |
# File '/var/www/sass-pages/.sass/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?(Null) || e.is_a?(List) && e.value.empty?}.map {|e| e.to_s(opts)}.join(sep_str)
end
|
- to_sass(opts = {})
48 49 50 51 52 53 54 55 56 57 58 |
# File '/var/www/sass-pages/.sass/lib/sass/script/list.rb', line 48
def to_sass(opts = {})
return "()" if value.empty?
precedence = Sass::Script::Parser.precedence_of(separator)
value.reject {|e| e.is_a?(Null)}.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
|