A SassScript object representing a CSS list. This includes both comma-separated lists and space-separated lists.
The Ruby array containing the contents of the list.
@return [Array<Literal>]
The operator separating the values of the list. Either `:comma` or `:space`.
@return [Symbol]
The Ruby array containing the contents of the list.
@return [Array<Literal>]
The Ruby array containing the contents of the list.
@return [Array<Literal>]
Creates a new list.
@param value [Array<Literal>] See {#value} @param separator [String] See {#separator}
# File lib/sass/script/list.rb, line 22 def initialize(value, separator) super(value) @separator = separator end
@see Sass::Script::Node#deep_copy
# 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
@see Node#eq
# File 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
@see Node#inspect
# File lib/sass/script/list.rb, line 62 def inspect "(#{to_sass})" end
@see Node#to_s
# 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?(Null) || e.is_a?(List) && e.value.empty?}.map {|e| e.to_s(opts)}.join(sep_str) end
@see Sass::Script::Node#to_sass
# File 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 || separator == :space && v.is_a?(UnaryOperation) && (v.operator == :minus || v.operator == :plus) "(#{v.to_sass(opts)})" else v.to_sass(opts) end end.join(sep_str(nil)) end
@see Node#_perform
# File lib/sass/script/list.rb, line 69 def _perform(environment) list = Sass::Script::List.new( value.map {|e| e.perform(environment)}, separator) list.options = self.options list end
# File lib/sass/script/list.rb, line 79 def sep_str(opts = self.options) return ' ' if separator == :space return ',' if opts && opts[:style] == :compressed return ', ' end