Created
February 21, 2010 01:12
-
-
Save tenderlove/310038 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| xml.root do | |
| xml.foo do | |
| xml.bar | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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