Sha256: 6bf1b9bd97512a61b1acb65be2aad61ea92e6b6eb30b3cb36aa4452af31f5bf7

Contents?: true

Size: 1007 Bytes

Versions: 106

Compression:

Stored size: 1007 Bytes

Contents

module Temple
  module HTML
    # This filter removes empty attributes
    # @api public
    class AttributeRemover < Filter
      define_options remove_empty_attrs: %w(id class)

      def initialize(opts = {})
        super
        raise ArgumentError, "Option :remove_empty_attrs must be an Array of Strings" unless Array === options[:remove_empty_attrs] &&
          options[:remove_empty_attrs].all? {|a| String === a }
      end

      def on_html_attrs(*attrs)
        [:multi, *attrs.map {|attr| compile(attr) }]
      end

      def on_html_attr(name, value)
        return super unless options[:remove_empty_attrs].include?(name.to_s)

        if empty_exp?(value)
          value
        elsif contains_nonempty_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

106 entries across 92 versions & 7 rubygems

Version Path
zuora_connect_ui-0.8.1 vendor/ruby/2.6.0/gems/brakeman-4.5.1/bundle/ruby/2.5.0/gems/temple-0.8.1/lib/temple/html/attribute_remover.rb
zuora_connect_ui-0.8.0 vendor/ruby/2.6.0/gems/brakeman-4.6.1/bundle/ruby/2.6.0/gems/temple-0.8.1/lib/temple/html/attribute_remover.rb
zuora_connect_ui-0.8.0 vendor/ruby/2.6.0/gems/brakeman-4.5.1/bundle/ruby/2.5.0/gems/temple-0.8.1/lib/temple/html/attribute_remover.rb
brakeman-4.6.1 bundle/ruby/2.6.0/gems/temple-0.8.1/lib/temple/html/attribute_remover.rb
brakeman-4.6.0 bundle/ruby/2.6.0/gems/temple-0.8.1/lib/temple/html/attribute_remover.rb
zuora_connect_ui-0.7.1 vendor/ruby/2.6.0/gems/brakeman-4.5.1/bundle/ruby/2.5.0/gems/temple-0.8.1/lib/temple/html/attribute_remover.rb
zuora_connect_ui-0.7.0 vendor/ruby/2.6.0/gems/brakeman-4.5.1/bundle/ruby/2.5.0/gems/temple-0.8.1/lib/temple/html/attribute_remover.rb
brakeman-4.5.1 bundle/ruby/2.5.0/gems/temple-0.8.1/lib/temple/html/attribute_remover.rb
brakeman-4.5.0 bundle/ruby/2.5.0/gems/temple-0.8.1/lib/temple/html/attribute_remover.rb
temple-0.8.1 lib/temple/html/attribute_remover.rb
brakeman-4.4.0 bundle/ruby/2.5.0/gems/temple-0.8.0/lib/temple/html/attribute_remover.rb
brakeman-4.3.1 bundle/ruby/2.5.0/gems/temple-0.7.7/lib/temple/html/attribute_remover.rb
brakeman-4.3.0 bundle/ruby/2.5.0/gems/temple-0.7.7/lib/temple/html/attribute_remover.rb
brakeman-4.2.1 bundle/ruby/2.5.0/gems/temple-0.7.7/lib/temple/html/attribute_remover.rb
brakeman-4.2.0 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/html/attribute_remover.rb
brakeman-4.1.1 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/html/attribute_remover.rb
brakeman-4.1.0 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/html/attribute_remover.rb
brakeman-4.0.1 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/html/attribute_remover.rb
brakeman-4.0.1.pre1 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/html/attribute_remover.rb
brakeman-4.0.0 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/html/attribute_remover.rb