Created
May 20, 2013 15:44
-
-
Save keating/5613080 to your computer and use it in GitHub Desktop.
blog_feed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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