class Haml::Buffer
def self.merge_attrs(to, from)
-
({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['data'].is_a?(Hash) to_data = to['data'].is_a?(Hash) if from_data && to_data to['data'] = to['data'].merge(from['data']) elsif to_data to = Haml::Util.map_keys(to.delete('data')) {|name| "data-#{name}"}.merge(to) elsif from_data from = Haml::Util.map_keys(from.delete('data')) {|name| "data-#{name}"}.merge(from) end to.merge!(from) end