Sha256: 236e29fa5d5bf107428d660d6b09967772e5934fab92f509d0be8c9a9d52e919

Contents?: true

Size: 693 Bytes

Versions: 11

Compression:

Stored size: 693 Bytes

Contents

class SCSSBeautifier::Formatters::PropertySortOrder < Sass::Tree::Visitors::Base
  def visit_rule(node)
    order_children(node)
    visit_children(node)
  end

  def order_children(node)
    prop_node_indices = []
    prop_nodes = []
    node.children.each_with_index do |child, index|
      hash_key = child.class.to_s.split("::").last
      if hash_key == 'PropNode'
        prop_node_indices << index
        prop_nodes << child
      end
    end
    prop_nodes.sort! { |x,y| x.name[0] <=> y.name[0] }
    # Replace children being respective of other types of props/funcs/etc
    prop_nodes.each_with_index do |n, index|
      node.children[prop_node_indices[index]] = n
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

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