Class: Hpricot::Elem

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

Overview

See Also:

Instance Method Summary collapse

Instance Method Details

#to_haml(tabs, options) ⇒ Object



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/haml/html.rb', line 175

def to_haml(tabs, options)
  output = tab_prefix = "#{tabulate(tabs)}"
  if options[:rhtml] && name[0...5] == 'haml:'
    output = (self.children || []).inject("") do |out, child|
      if child.text?
        text = CGI.unescapeHTML(child.inner_text).strip
        text.gsub!(/(^[- ]+)|([- ]+$)/, '')
        next out if text.empty?
        out + tab_prefix + send("haml_tag_#{name[5..-1]}", text, tab_prefix)
      elsif child.name[0...10] == 'haml:block'
        out + child.to_haml(tabs + 1, options)
      elsif child.name[0...5] == 'haml:'
        out + child.to_haml(tabs, options)
      else
        out + child.to_haml(tabs, options)
      end
    end
    return output
  end

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

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

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