Sha256: ea0bc553dbfee2b9700476e24d70bdf305285ce941d681e6c9cc0447d5e71e63

Contents?: true

Size: 720 Bytes

Versions: 48

Compression:

Stored size: 720 Bytes

Contents

module Temple
  module HTML
    # This filter removes empty attributes
    # @api public
    class AttributeRemover < Filter
      default_options[:remove_empty_attrs] = true

      def on_html_attrs(*attrs)
        [:multi, *(options[:remove_empty_attrs] ?
                   attrs.map {|attr| compile(attr) } : attrs)]
      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
    end
  end
end

Version data entries

48 entries across 48 versions & 2 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.7.4 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.7.3 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.7.2 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.7.1 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.7.0 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.6.9 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.6.8 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.6.7 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.6.6 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.6.5 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.6.4 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.6.3 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.6.2 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.6.1 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.6.0 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.5.17 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.5.16 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.5.15 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.5.14 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb