Class: Temple::HTML::AttributeSorter

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

Overview

This filter sorts html attributes.

Constant Summary

Constants included from Utils

Utils::ESCAPE_HTML, Utils::ESCAPE_HTML_PATTERN

Instance Attribute Summary

Attributes included from Mixins::Options

#options

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

Methods included from Mixins::Options

included, #initialize

Methods included from Mixins::ControlFlowDispatcher

#on_block, #on_case, #on_cond, #on_if

Methods included from Mixins::EscapeDispatcher

#on_escape

Methods included from Mixins::CoreDispatcher

#on_capture, #on_multi

Methods included from Mixins::CompiledDispatcher

#compile

Methods included from Utils

#empty_exp?, #escape_html, #escape_html_safe, #indent_dynamic, #unique_name

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