RSS for Content Elements

1 view
Skip to first unread message

Jono

unread,
Mar 19, 2011, 7:10:52 PM3/19/11
to Skyline CMS
Hi,

We've got a simple website for a buddhist community built using
Skyline CMS, which integrated into a simple Ruby on Rails directory.
We'd like to know what the Skyline Way is for creating an RSS feed of
content elements eg., for news and events.

Thanks,

Jonathan

Luis

unread,
Mar 21, 2011, 5:03:40 AM3/21/11
to Skyline CMS
Hi Jonathan,
It's nice to see other people using SkylineCMS and I hope it's been
working well for you.

Here's what we do to implement rss into content elements.

1. Create a controller for the rss feeds
---------
class RssFeedsController < ApplicationController
def show
if %w{news}.include?(params[:model])
@klass = params[:model].singularize.camelcase.constantize
@klass = @klass.published if @klass.respond_to?(:published)
@items = @klass.all(:limit => 20)
render :partial => "#{params[:model]}/index"
end
end
end
---------
2. Modify your pages_controller to assign the rss_feed link to a
variable when displaying items
---------
if @page_version.page.id ==
Settings.get(:news, :news_page_id).andand.to_i
renderer.assigns[:rss_feed] = rss_path(:model =>
"blog_entries", :format => :xml)
end
---------
3. Add the views, in this case it would be views/news/
_index.xml.builder
---------
xml.instruct!

xml.rss "version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/
1.1/" do
xml.channel do

xml.title "News"
xml.link request.protocol + request.host_with_port +
Settings.get_page(:news, :news_page_id).andand.url
xml.pubDate CGI.rfc1123_date @items.first.updated_at if
@items.any?
xml.description "News"

@items.each do |item|
xml.item do

if (item.url) && item.published?
url = "#{item.url}"
else
url = ""
end

xml.title item.title
xml.link request.protocol + request.host_with_port +
url
xml.description item.published_publication_data.abstract
xml.pubDate CGI.rfc1123_date
item.published_publication_data.date ?
item.published_publication_data.date.to_time : item.updated_at
xml.guid request.protocol + request.host_with_port +
url
xml.author "SkylineCMS"
end
end

end
end
---------
4. Add the rss link to the html head of your page template to display
the rss icon in the address bar
---------
<% if @rss_feed.present? %>
<%= auto_discovery_link_tag(:rss, @rss_feed) %>
<% end %>
---------

Hope this helps. Let me know how you get on.

Cheers,
Luis
Reply all
Reply to author
Forward
0 new messages