From 43c81e5af383d52aed0d005eed18db54f1637487 Mon Sep 17 00:00:00 2001 From: Matthew Boedicker Date: Thu, 28 Aug 2008 09:29:32 -0700 Subject: [PATCH] add support for xml processing instructions in atom_feed_helper --- .../lib/action_view/helpers/atom_feed_helper.rb | 4 +++ actionpack/test/template/atom_feed_helper_test.rb | 25 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 0 deletions(-) diff --git a/actionpack/lib/action_view/helpers/atom_feed_helper.rb b/actionpack/lib/action_view/helpers/atom_feed_helper.rb index e65d5d1..64f1c9f 100644 --- a/actionpack/lib/action_view/helpers/atom_feed_helper.rb +++ b/actionpack/lib/action_view/helpers/atom_feed_helper.rb @@ -51,6 +51,7 @@ module ActionView # * :schema_date: The date at which the tag scheme for the feed was first used. A good default is the year you # created the feed. See http://feedvalidator.org/docs/error/InvalidTAG.html for more information. If not specified, # 2005 is used (as an "I don't care" value). + # * :instruct: Array of XML processing instructions in the form [[target, {attribute => value, }], ] # # Other namespaces can be added to the root element: # @@ -85,6 +86,9 @@ module ActionView xml = options[:xml] || eval("xml", block.binding) xml.instruct! + if options[:instruct] + options[:instruct].each { |target,attrs| xml.instruct! target, attrs } + end feed_opts = {"xml:lang" => options[:language] || "en-US", "xmlns" => 'http://www.w3.org/2005/Atom'} feed_opts.merge!(options).reject!{|k,v| !k.to_s.match(/^xml/)} diff --git a/actionpack/test/template/atom_feed_helper_test.rb b/actionpack/test/template/atom_feed_helper_test.rb index ef31ab2..dedcccd 100644 --- a/actionpack/test/template/atom_feed_helper_test.rb +++ b/actionpack/test/template/atom_feed_helper_test.rb @@ -92,6 +92,24 @@ class ScrollsController < ActionController::Base end end EOT + FEEDS["feed_with_xml_processing_instructions"] = <<-EOT + atom_feed(:schema_date => '2008', + :instruct => [['xml-stylesheet', { :href=> 't.css', :type => 'text/css' }]]) do |feed| + feed.title("My great blog!") + feed.updated((@scrolls.first.created_at)) + + for scroll in @scrolls + feed.entry(scroll) do |entry| + entry.title(scroll.title) + entry.content(scroll.body, :type => 'html') + + entry.author do |author| + author.name("DHH") + end + end + end + end + EOT def index @scrolls = [ Scroll.new(1, "1", "Hello One", "Something COOL!", Time.utc(2007, 12, 12, 15), Time.utc(2007, 12, 12, 15)), @@ -194,6 +212,13 @@ class AtomFeedTest < Test::Unit::TestCase end end + def test_feed_xml_processing_instructions + with_restful_routing(:scrolls) do + get :index, :id => 'feed_with_xml_processing_instructions' + assert_match %r{<\?xml-stylesheet type="text/css" href="t.css"\?>}, @response.body + end + end + private def with_restful_routing(resources) with_routing do |set| -- 1.5.4.1