Sha256: 74f4d8605fa0c9f6fe76899ee212f36523aad5eab2bd991f0a8133e61467cca8

Contents?: true

Size: 632 Bytes

Versions: 11

Compression:

Stored size: 632 Bytes

Contents

class SCSSBeautifier::Formatters::DeclarationOrder < Sass::Tree::Visitors::Base
  # TODO: Account for if/else blocks and include blocks
  NODE_ORDER = ["ExtendNode", "MixinNode", "PropNode", "RuleNode"]

  def visit_rule(node)
    order_children(node)
    visit_children(node)
  end

  def order_children(node)
    node_hash = Hash.new { |h, k| h[k] = [] }
    node.children.each do |child|
      hash_key = child.class.to_s.split("::").last
      node_hash[hash_key] << child
    end

    compiled_array = NODE_ORDER.reduce([]) do |memo, key|
      memo.concat(node_hash[key])
    end

    node.children = compiled_array
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

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