Skip to content

Commit

Permalink
merge builder and rss into one guide
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Scott committed Mar 18, 2013
1 parent 7ed6c7c commit 024a9da
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 62 deletions.
29 changes: 0 additions & 29 deletions views/builder.md

This file was deleted.

33 changes: 0 additions & 33 deletions views/rss.md

This file was deleted.

43 changes: 43 additions & 0 deletions views/rss_feed_with_builder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
RSS Feed
--------

The [builder](https://github.com/jimweirich/builder) gem used for creating XML
markup is required in this recipe.

Let's first write our basic app to begin with:

```ruby
require 'sinatra'
require 'builder' # dont for get this!

get '/rss' do
@posts = # ... find posts
builder :rss
end
```

Then, assuming that your site url is `http://liftoff.msfc.nasa.gov/`, we will
set up our view at `views/rss.builder`:

```ruby
xml.instruct! :xml, :version => '1.0'
xml.rss :version => "2.0" do
xml.channel do
xml.title "Liftoff News"
xml.description "Liftoff to Space Exploration."
xml.link "http://liftoff.msfc.nasa.gov/"

@posts.each do |post|
xml.item do
xml.title post.title
xml.link "http://liftoff.msfc.nasa.gov/posts/#{post.id}"
xml.description post.body
xml.pubDate Time.parse(post.created_at.to_s).rfc822()
xml.guid "http://liftoff.msfc.nasa.gov/posts/#{post.id}"
end
end
end
end
```

This will render the RSS inline, directly from the handler.

0 comments on commit 024a9da

Please sign in to comment.