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.5.13 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
temple-0.4.1 lib/temple/html/attribute_remover.rb
classiccms-0.5.12 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.5.11 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.5.10 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.5.9 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.5.8 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.5.7 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.5.6 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.5.5 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.5.2 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.5.1 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.5.0 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.4.2 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.4.1 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.4.0 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.3.9 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.3.8 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.3.7 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.3.6 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb