Class: Sass::Script::Value::List
- Inherits:
- Base
- Object
- Base
- Sass::Script::Value::List
show all - Defined in:
- /Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/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 Base
#options, #source_range
Instance Method Summary (collapse)
Methods inherited from Base
#==, #_perform, #assert_int!, #div, #eql?, #minus, #neq, #null?, #plus, #single_eq, #to_bool, #to_i, #unary_div, #unary_minus, #unary_not, #unary_plus
Constructor Details
- (List) initialize(value, separator)
21
22
23
24 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/list.rb', line 21
def initialize(value, separator)
super(value)
@separator = separator
end |
Instance Attribute Details
- (Symbol) separator
The operator separating the values of the list. Either :comma
or :space
.
15
16
17 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/list.rb', line 15
def separator
@separator
end |
- (Array<Value>) value Also known as: to_a
The Ruby array containing the contents of the list.
8
9
10 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/list.rb', line 8
def value
@value
end |
Instance Method Details
- eq(other)
33
34
35
36
37 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/list.rb', line 33
def eq(other)
Sass::Script::Value::Bool.new(
other.is_a?(List) && value == other.value &&
separator == other.separator)
end |
- hash
39
40
41 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/list.rb', line 39
def hash
@hash ||= [value, separator].hash
end |
- inspect
72
73
74 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/list.rb', line 72
def inspect
"(#{value.map {|e| e.inspect}.join(sep_str(nil))})"
end |
- options=(options)
27
28
29
30 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/list.rb', line 27
def options=(options)
super
value.each {|v| v.options = options}
end |
- to_h
66
67
68
69 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/list.rb', line 66
def to_h
return Sass::Util.ordered_hash if value.empty?
super
end |
- to_s(opts = {})
44
45
46
47
48
49 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/list.rb', line 44
def to_s(opts = {})
raise Sass::SyntaxError.new("() isn't a valid CSS value.") if value.empty?
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 = {})
52
53
54
55
56
57
58
59
60
61
62
63 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/value/list.rb', line 52
def to_sass(opts = {})
return "()" if value.empty?
members = value.map do |v|
if element_needs_parens?(v)
"(#{v.to_sass(opts)})"
else
v.to_sass(opts)
end
end
return "(#{members.first},)" if members.length == 1 && separator == :comma
members.join(sep_str(nil))
end |