Module: Hamlit::Concerns::AttributeBuilder

Included in:
Attribute, Hamlit::Compilers::OldAttribute
Defined in:
lib/hamlit/concerns/attribute_builder.rb

Instance Method Summary collapse

Instance Method Details

#flatten_attributes(attributes) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/hamlit/concerns/attribute_builder.rb', line 4

def flatten_attributes(attributes)
  flattened = {}

  attributes.each do |key, value|
    case value
    when Hash
      flatten_attributes(value).each do |k, v|
        k = k.to_s.gsub(/_/, '-')
        flattened["#{key}-#{k}"] = v if v
      end
    else
      flattened[key] = value if value
    end
  end
  flattened
end