Permalink
Browse files

remove attributeremover

  • Loading branch information...
1 parent b617985 commit 796092e6e0f58a53c30b2ff8687dbf970928aad1 @minad minad committed Sep 7, 2012
Showing with 0 additions and 92 deletions.
  1. +0 −1 lib/temple.rb
  2. +0 −47 lib/temple/html/attribute_remover.rb
  3. +0 −44 test/html/test_attribute_remover.rb
View
@@ -48,6 +48,5 @@ module HTML
autoload :Pretty, 'temple/html/pretty'
autoload :AttributeMerger, 'temple/html/attribute_merger'
autoload :AttributeSorter, 'temple/html/attribute_sorter'
- autoload :AttributeRemover, 'temple/html/attribute_remover'
end
end
@@ -1,47 +0,0 @@
-module Temple
- module HTML
- # This filter removes empty dynamic attributes
- # @api public
- class AttributeRemover < Filter
- default_options[:remove_empty_attrs] = true
-
- def call(exp)
- options[:remove_empty_attrs] ? super : exp
- end
-
- def on_html_attrs(*attrs)
- [:multi, *attrs.map {|attr| compile(attr) }]
- end
-
- def on_html_attr(name, value)
- if empty_exp?(value)
- value
- elsif contains_static?(value)
- [:html, :attr, name, value]
- else
- tmp = unique_name
- [:multi,
- [:capture, tmp, compile(value)],
- [:if, "!#{tmp}.empty?",
- [:html, :attr, name, [:dynamic, tmp]]]]
- end
- end
-
- private
-
- # Contains static
- def contains_static?(exp)
- case exp.first
- when :multi
- exp[1..-1].any? {|e| contains_static?(e) }
- when :escape
- contains_static?(exp.last)
- when :static
- true
- else
- false
- end
- end
- end
- end
-end
@@ -1,44 +0,0 @@
-require 'helper'
-
-describe Temple::HTML::AttributeRemover do
- before do
- @remover = Temple::HTML::AttributeRemover.new
- @disabled_remover = Temple::HTML::AttributeRemover.new :remove_empty_attrs => false
- end
-
- it 'should pass static attributes through' do
- @remover.call([:html, :tag,
- 'div',
- [:html, :attrs, [:html, :attr, 'class', [:static, 'b']]],
- [:content]
- ]).should.equal [:html, :tag, "div",
- [:multi,
- [:html, :attr, "class", [:static, "b"]]],
- [:content]]
- end
-
- it 'should check for empty dynamic attribute if :remove_empty_attrs is true' do
- @remover.call([:html, :tag,
- 'div',
- [:html, :attrs, [:html, :attr, 'class', [:dynamic, 'b']]],
- [:content]
- ]).should.equal [:html, :tag, "div",
- [:multi,
- [:multi,
- [:capture, "_temple_html_attributeremover1", [:dynamic, "b"]],
- [:if, "!_temple_html_attributeremover1.empty?",
- [:html, :attr, "class", [:dynamic, "_temple_html_attributeremover1"]]]]],
- [:content]]
- end
-
- it 'should not check for empty dynamic attribute if :remove_empty_attrs is false' do
- @disabled_remover.call([:html, :tag,
- 'div',
- [:html, :attrs, [:html, :attr, 'class', [:dynamic, 'b']]],
- [:content]
- ]).should.equal [:html, :tag, "div",
- [:html, :attrs,
- [:html, :attr, "class", [:dynamic, "b"]]],
- [:content]]
- end
-end

0 comments on commit 796092e

Please sign in to comment.