class Sass::Script::List

A SassScript object representing a CSS list. This includes both comma-separated lists and space-separated lists.

Attributes

children[R]

The Ruby array containing the contents of the list.

@return [Array<Literal>]

separator[R]

The operator separating the values of the list. Either `:comma` or `:space`.

@return [Symbol]

to_a[R]

The Ruby array containing the contents of the list.

@return [Array<Literal>]

value[R]

The Ruby array containing the contents of the list.

@return [Array<Literal>]

Public Class Methods

new(value, separator) click to toggle source

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

Public Instance Methods

deep_copy() click to toggle source

@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
eq(other) click to toggle source

@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
inspect() click to toggle source

@see Node#inspect

# File lib/sass/script/list.rb, line 61
def inspect
  "(#{to_sass})"
end
to_s(opts = {}) click to toggle source

@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
to_sass(opts = {}) click to toggle source

@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
      "(#{v.to_sass(opts)})"
    else
      v.to_sass(opts)
    end
  end.join(sep_str(nil))
end

Protected Instance Methods

_perform(environment) click to toggle source

@see Node#_perform

# File 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