AtomFeedHelperを使ってネームスペース定義
Posted under: [Tips] | 3月 11th, 2008
結構はまった。結局のところバグのようで。次のリリースでは修正されるはずです。
views/hoge/index.atom.builder内において、
atom_feed({’xmlns:openSearch’ => ‘http://a9.com/-/spec/opensearch/1.1/’}) do |feed|
等と定義しても無視されます。ソースは「actionpack-2.0.2/lib/action_view/helpers/atom_feed_helper.rb」で、ネームスペースっぽい定義が見つからない。
Module: ActionView::Helpers::AtomFeedHelper
http://caboo.se/doc/classes/ActionView/Helpers/AtomFeedHelper.html#M006099
ここを見る限り、
Other namespaces can be added to the root element:
app/views/posts/index.atom.builder:
atom_feed({'xmlns:app' => 'http://www.w3.org/2007/app',
'xmlns:openSearch' => 'http://a9.com/-/spec/opensearch/1.1/'}) do |feed|
と書かれてはいるのだが、ソースを見る限りできそうにない。で、探してみたらパッチがあった。
#10304 ([PATCH] Atom feed helper should allow to add new namespaces to the feed root element) – Rails Trac – Trac
http://dev.rubyonrails.org/ticket/10304
86 feed_opts = {"xml:lang" => options[:language] || "en-US", "xmlns" => 'http://www.w3.org/2005/Atom'}
87 feed_opts.merge!(options).reject!{|k,v| !k.to_s.match(/^xml/)}
88
89 xml.feed(feed_opts) do
この辺りが修正範囲。xml〜ではじまっていればネームスペースとして見なす模様。これで無事、Atomフィードに任意のネームスペースが追加できるようになる。