Sha256: e9c2b3123f370c785bab3054697cfb4d595344f373fbb3e2c5a60e96c47aaacc

Contents?: true

Size: 1.5 KB

Versions: 27

Compression:

Stored size: 1.5 KB

Contents

module Sass::Script::Value
  # A SassScript object representing a map from keys to values. Both keys and
  # values can be any SassScript object.
  class Map < Base
    # The Ruby hash containing the contents of this map.
    #
    # @return [Hash<Node, Node>]
    attr_reader :value
    alias_method :to_h, :value

    # Creates a new map.
    #
    # @param hash [Hash<Node, Node>]
    def initialize(hash)
      super(hash)
    end

    # @see Value#options=
    def options=(options)
      super
      value.each do |k, v|
        k.options = options
        v.options = options
      end
    end

    # @see Value#separator
    def separator
      :comma unless value.empty?
    end

    # @see Value#to_a
    def to_a
      value.map do |k, v|
        list = List.new([k, v], separator: :space)
        list.options = options
        list
      end
    end

    # @see Value#eq
    def eq(other)
      Bool.new(other.is_a?(Map) && value == other.value)
    end

    def hash
      @hash ||= value.hash
    end

    # @see Value#to_s
    def to_s(opts = {})
      raise Sass::SyntaxError.new("#{inspect} isn't a valid CSS value.")
    end

    def to_sass(opts = {})
      return "()" if value.empty?

      to_sass = lambda do |value|
        if value.is_a?(List) && value.separator == :comma
          "(#{value.to_sass(opts)})"
        else
          value.to_sass(opts)
        end
      end

      "(#{value.map {|(k, v)| "#{to_sass[k]}: #{to_sass[v]}"}.join(', ')})"
    end
    alias_method :inspect, :to_sass
  end
end

Version data entries

27 entries across 27 versions & 3 rubygems

Version Path
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/map.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/map.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/script/value/map.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/script/value/map.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/map.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/map.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/map.rb
zuora_connect_ui-0.8.2 vendor/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/map.rb
zuora_connect_ui-0.8.1 vendor/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/map.rb
zuora_connect_ui-0.8.0 vendor/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/map.rb
zuora_connect_ui-0.7.1 vendor/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/map.rb
zuora_connect_ui-0.7.0 vendor/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/map.rb
sass-3.7.4 lib/sass/script/value/map.rb
sass-3.7.3 lib/sass/script/value/map.rb
sass-3.7.2 lib/sass/script/value/map.rb
sass-3.7.1 lib/sass/script/value/map.rb
sass-3.7.0 lib/sass/script/value/map.rb
sass-3.6.0 lib/sass/script/value/map.rb
sass-3.5.7 lib/sass/script/value/map.rb
sass-3.5.6 lib/sass/script/value/map.rb