Sha256: 0393cbf79af5ef0426fc9ecef489bdc5b5581c245d664c1649ec4dc66a69e837

Contents?: true

Size: 991 Bytes

Versions: 7

Compression:

Stored size: 991 Bytes

Contents

class SCSSBeautifier::Formatters::NameFormat < SCSSBeautifier::Formatters::Base

  NODES_WITH_NAME = [
    :function,
    :mixin,
    :placeholder,
    :mixindef,
    :script_funcall,
    :script_variable,
    :variable
  ].freeze

  NODES_WITH_NAME.each do |type|
    define_method "visit_#{type}" do |node|
      return if disable_for.include?(type.to_s)
      check_name(node)
    end
  end

  def visit_rule(node)
    return if disable_for.include?("rule")
    check_rule(node)
  end

  private

  def disable_for
    @disable_for ||= @options["disable_for"] || []
  end

  def check_name(node)
    node.instance_variable_set(:@name, Sass::Script::Value::String.new(node.name.to_s.gsub(/[[:upper:]]/) { "-#{$&}" }.downcase.gsub(/(?<!_)_(?!_)/, '-')))
  end

  def check_rule(node)
    node.rule = Sass::Util.strip_string_array(node.rule.map { |r| r.to_s.gsub(/[[:upper:]]/) { "-#{$&}" }.downcase.gsub(/(?<!_)_(?!_)/, '-') })
    node.send(:try_to_parse_non_interpolated_rules)
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
scss_beautifier-0.1.19 lib/scss_beautifier/formatters/name_format.rb
scss_beautifier-0.1.18 lib/scss_beautifier/formatters/name_format.rb
scss_beautifier-0.1.17 lib/scss_beautifier/formatters/name_format.rb
scss_beautifier-0.1.16 lib/scss_beautifier/formatters/name_format.rb
scss_beautifier-0.1.15 lib/scss_beautifier/formatters/name_format.rb
scss_beautifier-0.1.14 lib/scss_beautifier/formatters/name_format.rb
scss_beautifier-0.1.13 lib/scss_beautifier/formatters/name_format.rb