| Module | ActionView::Helpers::AtomFeedHelper |
| In: |
lib/action_view/helpers/atom_feed_helper.rb
|
Full usage example:
config/routes.rb:
ActionController::Routing::Routes.draw do |map|
map.resources :posts
map.root :controller => "posts"
end
app/controllers/posts_controller.rb:
class PostsController < ApplicationController::Base
# GET /posts.html
# GET /posts.atom
def index
@posts = Post.find(:all)
respond_to do |format|
format.html
format.atom
end
end
end
app/views/posts/index.atom.builder:
atom_feed do |feed|
feed.title("My great blog!")
feed.updated((@posts.first.created_at))
for post in @posts
feed.entry(post) do |entry|
entry.title(post.title)
entry.content(post.body, :type => 'html')
entry.author do |author|
author.name("DHH")
end
end
end
end
The options for atom_feed are:
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|
feed.title("My great blog!")
feed.updated((@posts.first.created_at))
feed.tag!(openSearch:totalResults, 10)
for post in @posts
feed.entry(post) do |entry|
entry.title(post.title)
entry.content(post.body, :type => 'html')
entry.tag!('app:edited', Time.now)
entry.author do |author|
author.name("DHH")
end
end
end
end
The Atom spec defines five elements (content rights title subtitle summary) which may directly contain xhtml content if :type => ‘xhtml’ is specified as an attribute. If so, this helper will take care of the enclosing div and xhtml namespace declaration. Example usage:
entry.summary :type => 'xhtml' do |xhtml|
xhtml.p pluralize(order.line_items.count, "line item")
xhtml.p "Shipped to #{order.address}"
xhtml.p "Paid by #{order.pay_type}"
end
atom_feed yields an AtomFeedBuilder instance. Nested elements yield an AtomBuilder instance.