In Files

Hpricot::Node

@see Hpricot

Attributes

converted_to_haml[RW]

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

@return [Boolean]

Public Instance Methods

to_haml(tabs, options) click to toggle source

Returns the Haml representation of the given node.

@param tabs [Fixnum] The indentation level of the resulting Haml. @option options (see Haml::HTML#initialize)

    # File lib/haml/html.rb, line 24
24:     def to_haml(tabs, options)
25:       return "" if converted_to_haml || to_s.strip.empty?
26:       text = uninterp(self.to_s)
27:       node = next_node
28:       while node.is_a?(::Hpricot::Elem) && node.name == "haml:loud"
29:         node.converted_to_haml = true
30:         text << '#{' <<
31:           CGI.unescapeHTML(node.inner_text).gsub(/\n\s*/, ' ').strip << '}'
32: 
33:         if node.next_node.is_a?(::Hpricot::Text)
34:           node = node.next_node
35:           text << uninterp(node.to_s)
36:           node.converted_to_haml = true
37:         end
38: 
39:         node = node.next_node
40:       end
41:       return parse_text_with_interpolation(text, tabs)
42:     end

Private Instance Methods

attr_hash() click to toggle source
    # File lib/haml/html.rb, line 67
67:     def attr_hash
68:       attributes.to_hash
69:     end
erb_to_interpolation(text, options) click to toggle source
    # File lib/haml/html.rb, line 46
46:     def erb_to_interpolation(text, options)
47:       return text unless options[:erb]
48:       text = CGI.escapeHTML(uninterp(text))
49:       ]<haml:loud> </haml:loud>].each {|str| text.gsub!(CGI.escapeHTML(str), str)}
50:       ::Hpricot::XML(text).children.inject("") do |str, elem|
51:         if elem.is_a?(::Hpricot::Text)
52:           str + CGI.unescapeHTML(elem.to_s)
53:         else # <haml:loud> element
54:           str + '#{' + CGI.unescapeHTML(elem.innerText.strip) + '}'
55:         end
56:       end
57:     end
parse_text(text, tabs) click to toggle source
    # File lib/haml/html.rb, line 71
71:     def parse_text(text, tabs)
72:       parse_text_with_interpolation(uninterp(text), tabs)
73:     end
parse_text_with_interpolation(text, tabs) click to toggle source
    # File lib/haml/html.rb, line 75
75:     def parse_text_with_interpolation(text, tabs)
76:       text.strip!
77:       return "" if text.empty?
78: 
79:       text.split("\n").map do |line|
80:         line.strip!
81:         "#{tabulate(tabs)}#{'\\' if Haml::Engine::SPECIAL_CHARACTERS.include?(line[0])}#{line}\n"
82:       end.join
83:     end
tabulate(tabs) click to toggle source
    # File lib/haml/html.rb, line 59
59:     def tabulate(tabs)
60:       '  ' * tabs
61:     end
uninterp(text) click to toggle source
    # File lib/haml/html.rb, line 63
63:     def uninterp(text)
64:       text.gsub('#{', '\#{') #'
65:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.