Skip to content

Commit

Permalink
Add support for xml processing instructions in atom_feed_helper [#926
Browse files Browse the repository at this point in the history
…state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information
mmb authored and lifo committed Oct 13, 2008
1 parent b47c76b commit 42cbd71
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
10 changes: 10 additions & 0 deletions actionpack/lib/action_view/helpers/atom_feed_helper.rb
Expand Up @@ -51,6 +51,7 @@ module AtomFeedHelper
# * <tt>:schema_date</tt>: 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).
# * <tt>:instruct</tt>: Hash of XML processing instructions in the form {target => {attribute => value, }} or {target => [{attribute => value, }, ]}
#
# Other namespaces can be added to the root element:
#
Expand Down Expand Up @@ -85,6 +86,15 @@ def atom_feed(options = {}, &block)

xml = options[:xml] || eval("xml", block.binding)
xml.instruct!
if options[:instruct]
options[:instruct].each do |target,attrs|
if attrs.respond_to?(:keys)
xml.instruct!(target, attrs)
elsif attrs.respond_to?(:each)
attrs.each { |attr_group| xml.instruct!(target, attr_group) }
end
end
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/)}
Expand Down
51 changes: 51 additions & 0 deletions actionpack/test/template/atom_feed_helper_test.rb
Expand Up @@ -85,6 +85,42 @@ class ScrollsController < ActionController::Base
entry.content(scroll.body, :type => 'html')
entry.tag!('app:edited', Time.now)
entry.author do |author|
author.name("DHH")
end
end
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
FEEDS["feed_with_xml_processing_instructions_duplicate_targets"] = <<-EOT
atom_feed(:schema_date => '2008',
:instruct => {'target1' => [{ :a => '1', :b => '2' }, { :c => '3', :d => '4' }]}) 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
Expand Down Expand Up @@ -194,6 +230,21 @@ def test_feed_should_allow_overriding_ids
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

def test_feed_xml_processing_instructions_duplicate_targets
with_restful_routing(:scrolls) do
get :index, :id => 'feed_with_xml_processing_instructions_duplicate_targets'
assert_match %r{<\?target1 (a="1" b="2"|b="2" a="1")\?>}, @response.body
assert_match %r{<\?target1 (c="3" d="4"|d="4" c="3")\?>}, @response.body
end
end

private
def with_restful_routing(resources)
with_routing do |set|
Expand Down

0 comments on commit 42cbd71

Please sign in to comment.