Module: Erector::Attributes

Included in:
AbstractWidget, Promise
Defined in:
lib/erector/attributes.rb

Instance Method Summary collapse

Instance Method Details

#format_attributes(attributes) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/erector/attributes.rb', line 3

def format_attributes(attributes)
  return "" if !attributes || attributes.empty?

  results = ['']

  attributes.each do |key, value|
    if value
      if value.is_a?(Array)
        value = value.flatten
        next if value.empty?
        value = value.join(' ')
      end

      if value.is_a?(TrueClass)
        results << "#{key}"
      elsif value.nil? || value.is_a?(FalseClass)
        # Nothing is generated in this case
      else
        results << "#{key}=\"#{h(value)}\""
      end
    end
  end

  results.join(' ')
end