Sha256: 728ccc0b29976a6a4f11af74b8621e2da1f3c70f8d6e504b790dd807f743ac46

Contents?: true

Size: 1.68 KB

Versions: 25

Compression:

Stored size: 1.68 KB

Contents

module Sass::Script::Tree
  # A parse tree node representing a list literal. When resolved, this returns a
  # {Sass::Tree::Value::List}.
  class ListLiteral < Node
    # The parse nodes for members of this list.
    #
    # @return [Array<Node>]
    attr_reader :elements

    # The operator separating the values of the list. Either `:comma` or
    # `:space`.
    #
    # @return [Symbol]
    attr_reader :separator

    # Creates a new list literal.
    #
    # @param elements [Array<Node>] See \{#elements}
    # @param separator [Symbol] See \{#separator}
    def initialize(elements, separator)
      @elements = elements
      @separator = separator
    end

    # @see Node#children
    def children; elements; end

    # @see Node#to_sass
    def to_sass(opts = {})
      return "()" if elements.empty?
      precedence = Sass::Script::Parser.precedence_of(separator)
      elements.map do |v|
        if v.is_a?(ListLiteral) && Sass::Script::Parser.precedence_of(v.separator) <= precedence
          "(#{v.to_sass(opts)})"
        else
          v.to_sass(opts)
        end
      end.join(separator == :space ? ' ' : ', ')
    end

    # @see Node#deep_copy
    def deep_copy
      node = dup
      node.instance_variable_set('@elements', elements.map {|e| e.deep_copy})
      node
    end

    def inspect
      "(#{elements.map {|e| e.inspect}.join(separator == :space ? ' ' : ', ')})"
    end

    protected

    def _perform(environment)
      list = Sass::Script::Value::List.new(
        elements.map {|e| e.perform(environment)},
        separator)
      list.line = line
      list.source_range = source_range
      list.filename = filename
      list.options = self.options
      list
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
sass-3.3.0.alpha.174 lib/sass/script/tree/list_literal.rb
sass-3.3.0.alpha.173 lib/sass/script/tree/list_literal.rb
sass-3.3.0.alpha.167 lib/sass/script/tree/list_literal.rb
sass-3.3.0.alpha.165 lib/sass/script/tree/list_literal.rb
sass-3.3.0.alpha.162 lib/sass/script/tree/list_literal.rb