Skip to content

Instantly share code, notes, and snippets.

@mattetti
Forked from tenderlove/index.nxml
Created February 21, 2010 01:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattetti/310045 to your computer and use it in GitHub Desktop.
Save mattetti/310045 to your computer and use it in GitHub Desktop.
xml.root do
xml.foo do
xml.bar
end
end
require 'nokogiri'
require 'action_view'
class NokogiriBuilder < ActionView::TemplateHandler
include ActionView::TemplateHandlers::Compilable
def compile template
"_set_controller_content_type(Mime::XML);" +
"xml = ::Nokogiri::XML::Builder.new { |xml|" +
template.source +
"}.to_xml; self.output_buffer = xml;"
end
end
ActionView::Template.register_template_handler :nxml, NokogiriBuilder
class TestyController < ApplicationController
def index
respond_to do |format|
format.xml
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment