Class: Sass::Script::Value::List
- Defined in:
- lib/sass/script/value/list.rb
Overview
A SassScript object representing a CSS list. This includes both comma-separated lists and space-separated lists.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#separator ⇒ Symbol
readonly
The operator separating the values of the list.
-
#value ⇒ Array<Value>
(also: #to_a)
readonly
The Ruby array containing the contents of the list.
Attributes inherited from Base
Instance Method Summary collapse
- #eq(other)
- #hash
-
#initialize(value, separator) ⇒ List
constructor
Creates a new list.
- #inspect
-
#is_pseudo_map? ⇒ Boolean
Returns whether this is a list of pairs that can be used as a map.
-
#needs_map_warning? ⇒ Boolean
Returns whether a warning still needs to be printed for this list being used as a map.
- #options=(options)
- #to_h
- #to_s(opts = {})
- #to_sass(opts = {})
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
#initialize(value, separator) ⇒ List
Creates a new list.
21 22 23 24 |
# File 'lib/sass/script/value/list.rb', line 21
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
.
15 16 17 |
# File 'lib/sass/script/value/list.rb', line 15
def separator
@separator
end
|
#value ⇒ Array<Value> (readonly) Also known as: to_a
The Ruby array containing the contents of the list.
8 9 10 |
# File 'lib/sass/script/value/list.rb', line 8
def value
@value
end
|
Instance Method Details
#eq(other)
33 34 35 36 37 |
# File '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 'lib/sass/script/value/list.rb', line 39
def hash
@hash ||= [value, separator].hash
end
|
#inspect
87 88 89 |
# File 'lib/sass/script/value/list.rb', line 87
def inspect
"(#{value.map {|e| e.inspect}.join(sep_str(nil))})"
end
|
#is_pseudo_map? ⇒ Boolean
Returns whether this is a list of pairs that can be used as a map.
82 83 84 |
# File 'lib/sass/script/value/list.rb', line 82
def is_pseudo_map?
@is_pseudo_map ||= value.all? {|e| e.is_a?(Sass::Script::Value::List) && e.to_a.length == 2}
end
|
#needs_map_warning? ⇒ Boolean
Returns whether a warning still needs to be printed for this list being used as a map.
75 76 77 |
# File 'lib/sass/script/value/list.rb', line 75 def needs_map_warning? [email protected]? && !@map end |
#options=(options)
27 28 29 30 |
# File '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 70 |
# File 'lib/sass/script/value/list.rb', line 66
def to_h
return Sass::Util.ordered_hash if value.empty?
return @map ||= Sass::Util.to_hash(value.map {|e| e.to_a}) if is_pseudo_map?
super
end
|
#to_s(opts = {})
44 45 46 47 48 49 |
# File '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 '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
|