Skip to content

Instantly share code, notes, and snippets.

@dchentech
Forked from raecoo/action.xml.nokogiri
Created June 2, 2011 08:50
Show Gist options
  • Save dchentech/1004132 to your computer and use it in GitHub Desktop.
Save dchentech/1004132 to your computer and use it in GitHub Desktop.
xml builder by Nokogiri
xml.feed(:xmlns => "http://www.w3.org/2005/Atom") { |feed|
feed.title("#{user.name}'s Private Notification Feed")
feed.link(:href => "http://#{account.subdomain}.domain.com/feeds/#{user.email_alias}.xml", :rel => "self")
feed.link(:href => "http://#{account.subdomain}.domain.com")
}
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 :nokogiri, NokogiriBuilder
def feed
...
respond_to do |format|
format.xml
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment