bogdanrada
5/27/2014 - 2:07 PM

nokogiri_template_handler.rb

require 'nokogiri'

module ActionView
  module TemplateHandlers
    class Nokogiri < TemplateHandler
      include Compilable

      def compile template
        <<-eotemplate
_set_controller_content_type(Mime::XML)
builder = ::Nokogiri::XML::Builder.new do |xml|
  #{template.source}
end
builder.to_xml
        eotemplate
      end
    end
  end
end

ActionView::Template.register_template_handler :nokogiri,
  ActionView::TemplateHandlers::Nokogiri