Sha256: 323d064e756348765078c6d9b5701c8a7dea0aaba72d729d43ee0a214c35b35c

Contents?: true

Size: 1.35 KB

Versions: 93

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

class SassC::Script::Value::Map < SassC::Script::Value

  # 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 = SassC::Script::Value::List.new([k, v], separator: :space)
      list.options = options
      list
    end
  end

  # @see Value#eq
  def eq(other)
    SassC::Script::Value::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 SassC::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

Version data entries

93 entries across 77 versions & 7 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/sassc-2.4.0/lib/sassc/script/value/map.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/sassc-2.4.0/lib/sassc/script/value/map.rb
sassc-embedded-1.80.2 vendor/github.com/sass/sassc-ruby/lib/sassc/script/value/map.rb
sassc-embedded-1.80.1 vendor/github.com/sass/sassc-ruby/lib/sassc/script/value/map.rb
sassc-embedded-1.80.0 vendor/github.com/sass/sassc-ruby/lib/sassc/script/value/map.rb
sassc-embedded-1.79.0 vendor/github.com/sass/sassc-ruby/lib/sassc/script/value/map.rb
sassc-embedded-1.78.0 vendor/github.com/sass/sassc-ruby/lib/sassc/script/value/map.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/sassc-2.4.0/lib/sassc/script/value/map.rb
sassc-embedded-1.77.8 vendor/github.com/sass/sassc-ruby/lib/sassc/script/value/map.rb
sassc-embedded-1.77.7 vendor/github.com/sass/sassc-ruby/lib/sassc/script/value/map.rb
sassc-embedded-1.77.6 vendor/github.com/sass/sassc-ruby/lib/sassc/script/value/map.rb
sassc-embedded-1.77.5 vendor/github.com/sass/sassc-ruby/lib/sassc/script/value/map.rb
sassc-embedded-1.77.4 vendor/github.com/sass/sassc-ruby/lib/sassc/script/value/map.rb
sassc-embedded-1.77.3 vendor/github.com/sass/sassc-ruby/lib/sassc/script/value/map.rb
sassc-embedded-1.77.2 vendor/github.com/sass/sassc-ruby/lib/sassc/script/value/map.rb
sassc-embedded-1.77.1 vendor/github.com/sass/sassc-ruby/lib/sassc/script/value/map.rb
sassc-embedded-1.77.0 vendor/github.com/sass/sassc-ruby/lib/sassc/script/value/map.rb
sassc-embedded-1.76.0 vendor/github.com/sass/sassc-ruby/lib/sassc/script/value/map.rb
sassc-embedded-1.75.2 vendor/github.com/sass/sassc-ruby/lib/sassc/script/value/map.rb
sassc-embedded-1.75.1 vendor/github.com/sass/sassc-ruby/lib/sassc/script/value/map.rb