Sha256: 27688123a50c7d0208ba3f5e5fb80a647f5476e74567cc4d4141fe2cf2ef3cef
Contents?: true
Size: 692 Bytes
Versions: 1
Compression:
Stored size: 692 Bytes
Contents
# frozen_string_literal: true module Arbre module HTML class Attributes < Hash def to_s flatten_hash.compact.map do |name, value| "#{html_escape(name)}=\"#{html_escape(value)}\"" end.compact.join ' ' end protected def flatten_hash(hash = self, old_path = [], accumulator = {}) hash.each do |key, value| path = old_path + [key] if value.is_a? Hash flatten_hash(value, path, accumulator) else accumulator[path.join('-')] = value end end accumulator end def html_escape(s) ERB::Util.html_escape(s) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
arbre-2.0.0 | lib/arbre/html/attributes.rb |