Sha256: b8ff075a21972e24adf565bcbd83332f5d2b513c207006e67b27c6ec075e6894

Contents?: true

Size: 637 Bytes

Versions: 10

Compression:

Stored size: 637 Bytes

Contents

# frozen_string_literal: true
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

10 entries across 9 versions & 3 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/temple-0.10.3/lib/temple/html/attribute_sorter.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/temple-0.10.3/lib/temple/html/attribute_sorter.rb
brakeman-7.0.0 bundle/ruby/3.1.0/gems/temple-0.10.3/lib/temple/html/attribute_sorter.rb
brakeman-6.2.2 bundle/ruby/3.1.0/gems/temple-0.10.3/lib/temple/html/attribute_sorter.rb
brakeman-6.2.2.rc1 bundle/ruby/3.3.0/gems/temple-0.10.3/lib/temple/html/attribute_sorter.rb
brakeman-6.2.1 bundle/ruby/3.1.0/gems/temple-0.10.3/lib/temple/html/attribute_sorter.rb
brakeman-6.2.0 bundle/ruby/3.1.0/gems/temple-0.10.3/lib/temple/html/attribute_sorter.rb
temple-0.10.3 lib/temple/html/attribute_sorter.rb
temple-0.10.2 lib/temple/html/attribute_sorter.rb
temple-0.10.1 lib/temple/html/attribute_sorter.rb