Class: Hpricot::Elem

Inherits:
Object show all
Defined in:
lib/haml/html.rb

Instance Method Summary collapse

Instance Method Details

#to_haml(tabs = 0) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/haml/html.rb', line 131

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.inner_text))
  end

  output += "%#{name}" unless name == 'div' && (static_id? || static_classname?)

  if attributes
    if static_id?
      output += "##{attributes['id']}"
      remove_attribute('id')
    end
    if static_classname?
      attributes['class'].split(' ').each { |c| output += ".#{c}" }
      remove_attribute('class')
    end
    output += haml_attributes if attributes.length > 0
  end

  (self.children || []).inject(output + "\n") do |output, child|
    output + child.to_haml(tabs + 1)
  end
end