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.3.5 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.3.4 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.3.3 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.3.2 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.3.1 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.3.0 vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
classiccms-0.2.4.pre vendor/bundle/gems/temple-0.4.0/lib/temple/html/attribute_remover.rb
temple-0.4.0 lib/temple/html/attribute_remover.rb