class Haml::Buffer

def self.merge_attrs(to, from)

Returns:
  • ({String => String}) - `to`, after being merged

Parameters:
  • from ({String => #to_s}) -- The attribute hash to merge from
  • to ({String => String}) -- The attribute hash to merge into
def self.merge_attrs(to, from)
  from['id'] = Compiler.filter_and_join(from['id'], '_') if from['id']
  if to['id'] && from['id']
    to['id'] << '_' << from.delete('id').to_s
  elsif to['id'] || from['id']
    from['id'] ||= to['id']
  end
  from['class'] = Compiler.filter_and_join(from['class'], ' ') if from['class']
  if to['class'] && from['class']
    # Make sure we don't duplicate class names
    from['class'] = (from['class'].to_s.split(' ') | to['class'].split(' ')).sort.join(' ')
  elsif to['class'] || from['class']
    from['class'] ||= to['class']
  end
  from_data = from.delete('data') || {}
  to_data = to.delete('data') || {}
  # forces to_data & from_data into a hash
  from_data = { nil => from_data } unless from_data.is_a?(Hash)
  to_data = { nil => to_data } unless to_data.is_a?(Hash)
  merged_data = to_data.merge(from_data)
  to['data'] = merged_data unless merged_data.empty?
  to.merge!(from)
end