Skip to content

Instantly share code, notes, and snippets.

@johnivanoff
Created December 10, 2012 00:34
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 johnivanoff/4247677 to your computer and use it in GitHub Desktop.
Save johnivanoff/4247677 to your computer and use it in GitHub Desktop.
require 'sinatra'
require 'nokogiri'
feed = File.read('test/fixtures/feed.xml')
def parse feed
doc = Nokogiri::XML feed
doc.search('item').map do |doc_item|
item = {}
item[:link] = doc_item.at('link').text
item[:thumbnail] = doc_item.at('media|thumbnail').attr('url')
item[:title] = doc_item.at('title').text
item
end
end
get '/' do
@pictures = parse feed
erb :index
end
__END__
@@index
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="user-scalable=yes, width=device-width" />
<title>Lovely Sunsets</title>
</head>
<body>
<h1>Feed Aggregator</h1>
<dl>
<% @pictures.each do |picture| %>
<dt><a href="<%= picture[:link] %>"><%= picture[:title] %></a></dt>
<dd><img src="<%= picture[:thumbnail] %>" /></dd>
<% end %>
</dl>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment