module Erector::Attributes

Public Instance Methods

format_attributes(attributes) click to toggle source
# File lib/erector/attributes.rb, line 3
def format_attributes(attributes)
  if !attributes || attributes.empty?
    ""
  else
    format_sorted(sort_attributes(attributes))
  end
end
format_sorted(sorted) click to toggle source
# File lib/erector/attributes.rb, line 11
def format_sorted(sorted)
  results = ['']
  sorted.each do |key, value|
    if value
      if value.is_a?(Array)
        value = value.flatten
        next if value.empty?
        value = value.join(' ')
      end
      results << "#{key}=\"#{h(value)}\""
    end
  end
  results.join(' ')
end
sort_attributes(attributes) click to toggle source
# File lib/erector/attributes.rb, line 26
def sort_attributes(attributes)
  stringized = []
  attributes.each do |key, value|
    stringized << [key.to_s, value]
  end
  stringized.sort
end