| 1 |
AtomFeedHelper |
|---|
| 2 |
============== |
|---|
| 3 |
|
|---|
| 4 |
Makes it easier to create atom feeds through Builder. |
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
Example |
|---|
| 8 |
======= |
|---|
| 9 |
|
|---|
| 10 |
# from PostsController |
|---|
| 11 |
def index |
|---|
| 12 |
@posts = Post.find(:all, :limit => 25) |
|---|
| 13 |
|
|---|
| 14 |
respond_to do |format| |
|---|
| 15 |
format.html |
|---|
| 16 |
format.atom |
|---|
| 17 |
end |
|---|
| 18 |
end |
|---|
| 19 |
|
|---|
| 20 |
# from posts/index.atom.builder |
|---|
| 21 |
|
|---|
| 22 |
atom_feed(:url => formatted_people_url(:atom)) do |feed| |
|---|
| 23 |
feed.title("Address book") |
|---|
| 24 |
feed.updated(@people.first ? @people.first.created_at : Time.now.utc) |
|---|
| 25 |
|
|---|
| 26 |
for post in @posts |
|---|
| 27 |
feed.entry(post) do |entry| |
|---|
| 28 |
entry.title(post.title) |
|---|
| 29 |
entry.content(post.body, :type => 'html') |
|---|
| 30 |
|
|---|
| 31 |
entry.author do |author| |
|---|
| 32 |
author.name(post.creator.name) |
|---|
| 33 |
author.email(post.creator.email_address) |
|---|
| 34 |
end |
|---|
| 35 |
end |
|---|
| 36 |
end |
|---|
| 37 |
end |
|---|
| 38 |
|
|---|
| 39 |
...returns: |
|---|
| 40 |
|
|---|
| 41 |
<?xml version="1.0" encoding="UTF-8"?> |
|---|
| 42 |
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom"> |
|---|
| 43 |
<id>tag:localhost:people</id> |
|---|
| 44 |
<link type="application/atom+xml" rel="self" href="http://example.com/people.atom"/> |
|---|
| 45 |
<title>Address book</title> |
|---|
| 46 |
<updated></updated> |
|---|
| 47 |
<entry> |
|---|
| 48 |
<id>tag:localhost:3000,2007-05-18T16:35:00-07:00:Person1</id> |
|---|
| 49 |
<published>2007-05-18T16:35:00-07:00</published> |
|---|
| 50 |
<link type="text/html" rel="alternate" href="http://example.com/people/1" /> |
|---|
| 51 |
<title>The future is now</title> |
|---|
| 52 |
<content type="html">Once upon a time</content> |
|---|
| 53 |
<author> |
|---|
| 54 |
<name>DHH</name> |
|---|
| 55 |
<email>david@loudthinking.com</email> |
|---|
| 56 |
</author> |
|---|
| 57 |
</entry> |
|---|
| 58 |
<entry> |
|---|
| 59 |
<id>tag:localhost:3000,2007-05-18T09:36:00-07:00:Person2</id> |
|---|
| 60 |
<published>2007-05-18T09:36:00-07:00</published> |
|---|
| 61 |
<link type="text/html" rel="alternate" href="http://example.com/people/1" /> |
|---|
| 62 |
<title>Matz</title> |
|---|
| 63 |
<content type="html">This is Matz</content> |
|---|
| 64 |
<author> |
|---|
| 65 |
<name>Matz</name> |
|---|
| 66 |
<email>Matz</email> |
|---|
| 67 |
</author> |
|---|
| 68 |
</entry> |
|---|
| 69 |
</feed> |
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
Copyright (c) 2007 David Heinemeier Hansson, released under the MIT license |
|---|