@see Hpricot
Whether this node has already been converted to Haml. Only used for text nodes and elements.
@return [Boolean]
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 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
# File lib/haml/html.rb, line 67 def attr_hash attributes.to_hash end
# File lib/haml/html.rb, line 46 def erb_to_interpolation(text, options) return text unless options[:erb] text = CGI.escapeHTML(uninterp(text)) %w[<haml:loud> </haml:loud>].each {|str| text.gsub!(CGI.escapeHTML(str), str)} ::Hpricot::XML(text).children.inject("") do |str, elem| if elem.is_a?(::Hpricot::Text) str + CGI.unescapeHTML(elem.to_s) else # <haml:loud> element str + '#{' + CGI.unescapeHTML(elem.innerText.strip) + '}' end end end
# File lib/haml/html.rb, line 71 def parse_text(text, tabs) parse_text_with_interpolation(uninterp(text), tabs) end
# File lib/haml/html.rb, line 75 def parse_text_with_interpolation(text, tabs) text.strip! return "" if text.empty? text.split("\n").map do |line| line.strip! "#{tabulate(tabs)}#{'\\' if Haml::Engine::SPECIAL_CHARACTERS.include?(line[0])}#{line}\n" end.join end
# File lib/haml/html.rb, line 59 def tabulate(tabs) ' ' * tabs end
# File lib/haml/html.rb, line 63 def uninterp(text) text.gsub('#{', '\#{') #' end