On Wed, 5 Oct 2011 11:20:31 +1100, Jenna Fox <[email protected]> wrote:
> [1 <multipart/alternative (7bit)>]
> [1.1 <text/plain; windows-1252 (quoted-printable)>]
>
> [1.2 <text/html; windows-1252 (quoted-printable)>]
> I'm looking to make rss feeds of some of my controller data - what's the
> simplest way to render some? Is there some way I can feed a json-like arrays
> of hashes type of structure in to some gem and get out an xml feed? Would it
> be more of a builder sort of operation?
An example. Succinct. RSS:Maker. For your reference. (from my blogging
engine written with Camping 1.9):
Firstly, need to require rss/maker, then
module Blogg::Controllers
class Index < R '/', '/tag/([-\w]+)', '/(rss)', '/(rss)/([-\w]+)'
def get ( format='html', *rest )
...
then later on:
# Produce RSS feed
if format == 'rss'
content = RSS::Maker.make('2.0') do |m|
m.channel.title = @@config[:title]
m.channel.about = URL().to_s + '/rss'
m.channel.link = URL().to_s
m.channel.description = @@config[:descr]
m.items.do_sort = true # sort items by date
for post in @posts
if post.okayed == true && tag_matches?(post, @tagg)
i = m.items.new_item
i.title = post.title
i.link = URL(View, post.slug).to_s
i.guid.content = URL(View, post.id).to_s
i.guid.isPermaLink = true
ar = post.body.split(/^---!/)
i.description = RedCloth.new(ar[1]).to_html
i.description << RedCloth.new(ar[2]).to_html if (ar[2] != nil &&
ar[2] != "\r\n" && ar[2] != "")
i.date = post.when
end
end
end
r 200, content.to_s, 'Content-Type' => 'application/rss+xml;
charset=UTF-8'
Notes: I use ---! to mark a block at the beginning of a post - this block
is the description of the post. Redcloth markdown is used.
Cheers,
Jonathan
--
jjg: Jonathan J. Groll : groll co za
has_one { :blog => "http://bloggroll.com" }
Sent from my computer device which runs on free software
_______________________________________________
Camping-list mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/camping-list