Skip to content

Instantly share code, notes, and snippets.

@jpowell
Forked from sishen/gist:1019347
Created April 21, 2012 18:58
Show Gist options
  • Save jpowell/2439120 to your computer and use it in GitHub Desktop.
Save jpowell/2439120 to your computer and use it in GitHub Desktop.
Nokogiri Template Builder. (Rails 3.0)
require 'action_view'
module ActionView::Template::Handlers
class NokogiriBuilder
class_attribute :default_format
self.default_format = Mime::XML
def call template
require 'nokogiri'
"xml = ::Nokogiri::XML::Builder.new { |xml|" +
template.source + "}.to_xml;"
end
end
end
ActionView::Template.register_template_handler :nxml, ActionView::Template::Handlers::NokogiriBuilder.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment