class SassC::Script::Value::List

def self.assert_valid_index(list, n)

Parameters:
  • n (Sass::Script::Value::Number) -- The index being checked.
  • list (Sass::Script::Value::List) -- The list for which the index should be checked.

Other tags:
    Private: -
def self.assert_valid_index(list, n)
  if !n.int? || n.to_i == 0
    raise ArgumentError.new("List index #{n} must be a non-zero integer")
  elsif list.to_a.size == 0
    raise ArgumentError.new("List index is #{n} but list has no items")
  elsif n.to_i.abs > (size = list.to_a.size)
    raise ArgumentError.new(
      "List index is #{n} but list is only #{size} item#{'s' if size != 1} long")
  end
end

def element_needs_parens?(element)

def element_needs_parens?(element)
  if element.is_a?(List)
    return false if element.value.length < 2
    return false if element.bracketed
    precedence = Sass::Script::Parser.precedence_of(separator || :space)
    return Sass::Script::Parser.precedence_of(element.separator || :space) <= precedence
  end
  return false unless separator == :space
  return false unless element.is_a?(Sass::Script::Tree::UnaryOperation)
  element.operator == :minus || element.operator == :plus
end

def eq(other)

Other tags:
    See: Value#eq -
def eq(other)
  SassC::Script::Value::Bool.new(
    other.is_a?(List) && value == other.value &&
    separator == other.separator && bracketed == other.bracketed
  )
end

def hash

def hash
  @hash ||= [value, separator, bracketed].hash
end

def initialize(value, separator: nil, bracketed: false)

Parameters:
  • bracketed (Boolean) -- See \{#bracketed}
  • separator (Symbol) -- See \{#separator}
  • value (Array) -- See \{#value}
def initialize(value, separator: nil, bracketed: false)
  super(value)
  @separator = separator
  @bracketed = bracketed
end

def inspect

Other tags:
    See: Value#inspect -
def inspect
  (bracketed ? '[' : '(') + value.map {|e| e.inspect}.join(sep_str(nil)) + (bracketed ? ']' : ')')
end

def options=(options)

Other tags:
    See: Value#options= -
def options=(options)
  super
  value.each {|v| v.options = options}
end

def sep_str(opts = options)

def sep_str(opts = options)
  return ' ' if separator == :space
  return ',' if opts && opts[:style] == :compressed
  ', '
end

def to_h

Other tags:
    See: Value#to_h -
def to_h
  return {} if value.empty?
  super
end

def to_s(opts = {})

Other tags:
    See: Value#to_s -
def to_s(opts = {})
  if !bracketed && value.empty?
    raise SassC::SyntaxError.new("#{inspect} isn't a valid CSS value.")
  end
  members = value.
    reject {|e| e.is_a?(Null) || e.is_a?(List) && e.value.empty?}.
    map {|e| e.to_s(opts)}
  contents = members.join(sep_str)
  bracketed ? "[#{contents}]" : contents
end

def to_sass(opts = {})

Other tags:
    See: Value#to_sass -
def to_sass(opts = {})
  return bracketed ? "[]" : "()" if value.empty?
  members = value.map do |v|
    if element_needs_parens?(v)
      "(#{v.to_sass(opts)})"
    else
      v.to_sass(opts)
    end
  end
  if separator == :comma && members.length == 1
    return "#{bracketed ? '[' : '('}#{members.first},#{bracketed ? ']' : ')'}"
  end
  contents = members.join(sep_str(nil))
  bracketed ? "[#{contents}]" : contents
end