Sha256: 727377ba8d5d0378cf0da179ea095596ab815aac9d3406f7330e2239f2110c4d

Contents?: true

Size: 890 Bytes

Versions: 11

Compression:

Stored size: 890 Bytes

Contents

class SCSSBeautifier::Formatters::Color < Sass::Tree::Visitors::Base
  def visit_prop(node)
    if node.value.respond_to?(:each)
      node.value.each{ |item| format_color(item) }
    else
      format_color(node.value)
    end
  end

  def format_color(item)
    if Sass::Script::Tree::Literal === item && Sass::Script::Value::String === item.value
      if color = Sass::Script::Value::Color::COLOR_NAMES[item.value.value]
        color_value = Sass::Script::Value::Color.new(color)
        color_value.options = {}
        item.instance_variable_set(:@value, Sass::Script::Value::String.new(color_value.inspect))
      elsif item.value.value =~ /(#\h{3})(?!\h)/
        hex = item.value.value
        long_form = [hex[0..1], hex[1], hex[2], hex[2], hex[3], hex[3]].join
        item.instance_variable_set(:@value, Sass::Script::Value::String.new(long_form))
      end
    end
  end

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
scss_beautifier-0.1.11 lib/scss_beautifier/formatters/color.rb
scss_beautifier-0.1.10 lib/scss_beautifier/formatters/color.rb
scss_beautifier-0.1.8 lib/scss_beautifier/formatters/color.rb
scss_beautifier-0.1.7 lib/scss_beautifier/formatters/color.rb
scss_beautifier-0.1.6 lib/scss_beautifier/formatters/color.rb
scss_beautifier-0.1.5 lib/scss_beautifier/formatters/color.rb
scss_beautifier-0.1.4 lib/scss_beautifier/formatters/color.rb
scss_beautifier-0.1.3 lib/scss_beautifier/formatters/color.rb
scss_beautifier-0.1.2 lib/scss_beautifier/formatters/color.rb
scss_beautifier-0.1.1 lib/scss_beautifier/formatters/color.rb
scss_beautifier-0.1.0 lib/scss_beautifier/formatters/color.rb