Sha256: 1f43dcd2abbde0a53323fbb16ed0573e08030b418be62bb0b9bf7e6347fe3e2b

Contents?: true

Size: 896 Bytes

Versions: 4

Compression:

Stored size: 896 Bytes

Contents

class SCSSBeautifier::Formatters::Color < SCSSBeautifier::Formatters::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

4 entries across 4 versions & 1 rubygems

Version Path
scss_beautifier-0.1.15 lib/scss_beautifier/formatters/color.rb
scss_beautifier-0.1.14 lib/scss_beautifier/formatters/color.rb
scss_beautifier-0.1.13 lib/scss_beautifier/formatters/color.rb
scss_beautifier-0.1.12 lib/scss_beautifier/formatters/color.rb