Sha256: 44fe0fda57e118c2ccb4e851105edbcc49ccaa6dd14a9382bcf34ea76117e026

Contents?: true

Size: 508 Bytes

Versions: 10

Compression:

Stored size: 508 Bytes

Contents

module Arbre
  module HTML

    class Attributes < Hash

      def to_s
        map do |name, value|
          next if value_empty?(value)
          "#{html_escape(name)}=\"#{html_escape(value)}\""
        end.compact.join ' '
      end

      def any?
        super{ |k,v| !value_empty?(v) }
      end

      protected

      def value_empty?(value)
        value.respond_to?(:empty?) ? value.empty? : !value
      end

      def html_escape(s)
        ERB::Util.html_escape(s)
      end
    end

  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/arbre-1.4.0/lib/arbre/html/attributes.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/arbre-1.4.0/lib/arbre/html/attributes.rb
arbre-1.4.0 lib/arbre/html/attributes.rb
arbre-1.3.0 lib/arbre/html/attributes.rb
arbre-1.2.1 lib/arbre/html/attributes.rb
arbre-1.2.0 lib/arbre/html/attributes.rb
arbre-1.2.0.rc1 lib/arbre/html/attributes.rb
arbre-1.1.1 lib/arbre/html/attributes.rb
arbre-1.0.3 lib/arbre/html/attributes.rb
arbre-1.0.2 lib/arbre/html/attributes.rb