mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
I heard class attribute should be first
This commit is contained in:
parent
96cd8c56ed
commit
0ea20644c8
4 changed files with 26 additions and 3 deletions
21
lib/hamlit/attribute_sorter.rb
Normal file
21
lib/hamlit/attribute_sorter.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
require 'hamlit/filter'
|
||||
|
||||
# Haml-spec specifies attribute order inspite of an original order.
|
||||
# Because temple's parser should return a result as original as possible,
|
||||
# the ordering delegated to this filter.
|
||||
module Hamlit
|
||||
class AttributeSorter < Hamlit::Filter
|
||||
def on_haml_attrs(*attrs)
|
||||
[:html, :attrs, *pull_class_first(attrs)]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def pull_class_first(attrs)
|
||||
class_attr = attrs.select do |html, attr, name, content|
|
||||
name == 'class'
|
||||
end
|
||||
class_attr + (attrs - class_attr)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,5 +1,6 @@
|
|||
require 'temple'
|
||||
require 'hamlit/attribute_compiler'
|
||||
require 'hamlit/attribute_sorter'
|
||||
require 'hamlit/dynamic_formatter'
|
||||
require 'hamlit/doctype_compiler'
|
||||
require 'hamlit/filter_compiler'
|
||||
|
@ -24,6 +25,7 @@ module Hamlit
|
|||
use DoctypeCompiler
|
||||
use AttributeCompiler
|
||||
use NewAttributeCompier
|
||||
use AttributeSorter
|
||||
use FilterFormatter
|
||||
use FilterCompiler
|
||||
use ScriptCompiler
|
||||
|
|
|
@ -17,7 +17,7 @@ module Hamlit
|
|||
attrs << compile(exp)
|
||||
end
|
||||
end
|
||||
[:html, :attrs, *attrs]
|
||||
[:haml, :attrs, *attrs]
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -94,7 +94,7 @@ describe Hamlit::Engine do
|
|||
assert_render(<<-HAML, <<-HTML)
|
||||
%span#a.b#c.d hello
|
||||
HAML
|
||||
<span id='c' class='b d'>hello</span>
|
||||
<span class='b d' id='c'>hello</span>
|
||||
HTML
|
||||
end
|
||||
|
||||
|
@ -102,7 +102,7 @@ describe Hamlit::Engine do
|
|||
assert_render(<<-HAML, <<-HTML)
|
||||
#hello.world
|
||||
HAML
|
||||
<div id='hello' class='world'></div>
|
||||
<div class='world' id='hello'></div>
|
||||
HTML
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue