Sha256: 2048fd7ef172bd1520539843c5670c9509eb7feebf6448b0304b9220d155d78f

Contents?: true

Size: 607 Bytes

Versions: 106

Compression:

Stored size: 607 Bytes

Contents

module Temple
  module HTML
    # This filter sorts html attributes.
    # @api public
    class AttributeSorter < Filter
      define_options sort_attrs: true

      def call(exp)
        options[:sort_attrs] ? super : exp
      end

      def on_html_attrs(*attrs)
        n = 0 # Use n to make sort stable. This is important because the merger could be executed afterwards.
        [:html, :attrs, *attrs.sort_by do |attr|
          raise(InvalidExpression, 'Attribute is not a html attr') if attr[0] != :html || attr[1] != :attr
          [attr[2].to_s, n += 1]
        end]
      end
    end
  end
end

Version data entries

106 entries across 92 versions & 7 rubygems

Version Path
brakeman-3.7.2 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/html/attribute_sorter.rb
brakeman-3.7.1 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/html/attribute_sorter.rb
brakeman-3.7.0 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/html/attribute_sorter.rb
brakeman-3.6.2 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/html/attribute_sorter.rb
brakeman-3.6.1 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/html/attribute_sorter.rb
brakeman-3.6.0 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/html/attribute_sorter.rb
temple-0.8.0 lib/temple/html/attribute_sorter.rb
brakeman-3.5.0 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/html/attribute_sorter.rb
brakeman-3.4.1 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/html/attribute_sorter.rb
brakeman-3.4.0 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/html/attribute_sorter.rb
brakeman-3.3.5 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/html/attribute_sorter.rb
brakeman-3.3.4 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/html/attribute_sorter.rb
brakeman-3.3.3 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/html/attribute_sorter.rb
brakeman-3.3.2 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/html/attribute_sorter.rb
brakeman-3.3.1 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/html/attribute_sorter.rb
temple-0.7.7 lib/temple/html/attribute_sorter.rb
brakeman-3.3.0 bundle/ruby/2.3.0/gems/temple-0.7.6/lib/temple/html/attribute_sorter.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/temple-0.7.6/lib/temple/html/attribute_sorter.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/temple-0.7.6/lib/temple/html/attribute_sorter.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/temple-0.7.6/lib/temple/html/attribute_sorter.rb