class Hpricot::Elem
def haml_attributes
Returns a string representation of an attributes hash
def haml_attributes attrs = attributes.map do |name, value| name = name.index(/\W/) ? name.inspect : ":#{name}" "#{name} => #{value.inspect}" end "{ #{attrs.join(', ')} }" end
def to_haml(tabs = 0)
def to_haml(tabs = 0) output = "#{tabulate(tabs)}" if HTML.options[:rhtml] && name[0...5] == 'haml:' return output + HTML.send("haml_tag_#{name[5..-1]}", CGI.unescapeHTML(self.innerHTML)) end output += "%#{name}" unless name == 'div' && (attributes.include?('id') || attributes.include?('class')) if attributes output += "##{attributes['id']}" if attributes['id'] attributes['class'].split(' ').each { |c| output += ".#{c}" } if attributes['class'] remove_attribute('id') remove_attribute('class') output += haml_attributes if attributes.length > 0 end output += "/" if children.length == 0 output += "\n" self.children.each do |child| output += child.to_haml(tabs + 1) end output end