Module: Haml::HTML::Node

Defined in:
lib/haml/html.rb

Overview

A module containing utility methods that every Hpricot node should have.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#converted_to_hamlBoolean

Whether this node has already been converted to Haml. Only used for text nodes and elements.

Returns:

  • (Boolean)


16
17
18
# File 'lib/haml/html.rb', line 16

def converted_to_haml
  @converted_to_haml
end

Instance Method Details

#to_haml(tabs, options)

Returns the Haml representation of the given node.

Parameters:

  • tabs (Fixnum)

    The indentation level of the resulting Haml.

Options Hash (options):

  • :erb (Boolean) — default: false

    Whether or not to parse ERB's <%= %> and <% %> into Haml's = and -

  • :xhtml (Boolean) — default: false

    Whether or not to parse the HTML strictly as XHTML



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/haml/html.rb', line 22

def to_haml(tabs, options)
  return "" if converted_to_haml || to_s.strip.empty?
  text = uninterp(self.to_s)
  node = next_node
  while node.is_a?(::Hpricot::Elem) && node.name == "haml:loud"
    node.converted_to_haml = true
    text << '#{' <<
      CGI.unescapeHTML(node.inner_text).gsub(/\n\s*/, ' ').strip << '}'

    if node.next_node.is_a?(::Hpricot::Text)
      node = node.next_node
      text << uninterp(node.to_s)
      node.converted_to_haml = true
    end

    node = node.next_node
  end
  return parse_text_with_interpolation(text, tabs)
end