Class: Temple::HTML::AttributeSorter

Inherits:
Filter show all
Defined in:
lib/temple/html/attribute_sorter.rb

Overview

This filter sorts html attributes.

Instance Method Summary collapse

Methods inherited from Filter

#contains_nonempty_static?

Methods included from Dispatcher

#on_html_attr, #on_html_comment, #on_html_condcomment, #on_html_js, #on_html_tag

Instance Method Details

#call(exp) ⇒ Object



9
10
11
# File 'lib/temple/html/attribute_sorter.rb', line 9

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

#on_html_attrs(*attrs) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/temple/html/attribute_sorter.rb', line 13

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