Skip to content

Instantly share code, notes, and snippets.

@keating
Created May 20, 2013 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keating/5613080 to your computer and use it in GitHub Desktop.
Save keating/5613080 to your computer and use it in GitHub Desktop.
blog_feed
require 'rss/2.0'
require 'open-uri'
require 'timeout'
module PagesHelper
def blog_feed
html = ""
begin
status = Timeout::timeout(5) {
source = BLOG_URL # url or local file
content = "" # raw content of rss feed will be loaded here
open(source) do |s|
content = s.read
end
rss = RSS::Parser.parse(content, false)
rss.items.first(5).each do |i|
html << "<div class='pills-content'>"
html << "<div>#{i.title}</div><div class='pills-content-link'><a href='#{i.link}' target='_blank'>View More</a></div>"
html << "</div>"
end
}
rescue Timeout::Error
html << "That took too long, exiting..."
end
html
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment