Created
November 1, 2010 19:10
-
-
Save raecoo/658700 to your computer and use it in GitHub Desktop.
xml builder by Nokogiri
This file contains 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.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") | |
} |
This file contains 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 :nokogiri, NokogiriBuilder |
This file contains 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
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