Class: Sass::Script::Value::List

Inherits:
Base
  • Object
show all
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

ArgList

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

#initialize(value, separator) ⇒ List

Creates a new list.

Parameters:



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

#separatorSymbol (readonly)

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

Returns:

  • (Symbol)


15
16
17
# File 'lib/sass/script/value/list.rb', line 15

def separator
  @separator
end

#valueArray<Value> (readonly) Also known as: to_a

The Ruby array containing the contents of the list.

Returns:



8
9
10
# File 'lib/sass/script/value/list.rb', line 8

def value
  @value
end

Instance Method Details

#eq(other)

See Also:

  • Value#eq


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

See Also:

  • Value#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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


75
76
77
# File 'lib/sass/script/value/list.rb', line 75

def needs_map_warning?
  [email protected]? && !@map
end

#options=(options)

See Also:

  • Value#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

See Also:

  • Value#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 = {})

Raises:

See Also:

  • Value#to_s


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 = {})

See Also:

  • Value#to_sass


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