lib/ahcx_template_handler.rb in ahc-0.2.4 vs lib/ahcx_template_handler.rb in ahc-0.2.5

- old
+ new

@@ -1,10 +1,14 @@ require 'nokogiri' require 'htmlcompressor' class AhcxTemplateHandler + ESCAPED_SYMBOLS = { + '&' => '(|escapeahx|and|)' + } + def self.call(template) erb = ActionView::Template.registered_template_handler(:erb) source = erb.call(template) source + ";AhcxTemplateHandler.render(@output_buffer.to_s)" end @@ -26,14 +30,21 @@ attr_value += node_content(inside_node) end params[child_node_attr] = attr_value end end - Ahc.render(tag, params) + html = Ahc.render(tag, params) + ESCAPED_SYMBOLS.each do |sym, escaped_sym| + html.gsub!(escaped_sym, sym) + end + html end def self.render(xml) ahcx_source = "<document>#{xml}</document>" + ESCAPED_SYMBOLS.each do |sym, escaped_sym| + ahcx_source.gsub!(sym, escaped_sym) + end ahcx = Nokogiri.parse(ahcx_source) content = '' ahcx.children.first.children.each do |node| content += node_content(node) end