Class: Nokogiri::XML::Node

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

Overview

See Also:

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)

17
18
19
# File 'lib/html2haml/html.rb', line 17

def converted_to_haml
  @converted_to_haml
end

Instance Method Details

#to_haml(tabs, options) ⇒ Object

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


23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/html2haml/html.rb', line 23

def to_haml(tabs, options)
  return "" if converted_to_haml || to_s.strip.empty?
  text = uninterp(self.to_s)

  #ending in a newline stops the inline nodes
  if text.end_with?("\n")
    parse_text_with_interpolation(text, tabs)
  else
    text << process_inline_nodes(next_sibling)
    parse_text_with_interpolation(text, tabs)
  end
end