Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7211fd7
commit 84eb90a
Showing
23 changed files
with
350 additions
and
48 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
config/database.yml | ||
log | ||
tmp | ||
*.sqlite3 | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
class BlogsController < ApplicationController | ||
# GET /blogs | ||
# GET /blogs.xml | ||
def index | ||
@blogs = Blog.all | ||
|
||
respond_to do |format| | ||
format.html # index.html.erb | ||
format.xml { render :xml => @blogs } | ||
end | ||
end | ||
|
||
# GET /blogs/1 | ||
# GET /blogs/1.xml | ||
def show | ||
@blog = Blog.find(params[:id]) | ||
|
||
respond_to do |format| | ||
format.html # show.html.erb | ||
format.xml { render :xml => @blog } | ||
end | ||
end | ||
|
||
# GET /blogs/new | ||
# GET /blogs/new.xml | ||
def new | ||
@blog = Blog.new | ||
|
||
respond_to do |format| | ||
format.html # new.html.erb | ||
format.xml { render :xml => @blog } | ||
end | ||
end | ||
|
||
# GET /blogs/1/edit | ||
def edit | ||
@blog = Blog.find(params[:id]) | ||
end | ||
|
||
# POST /blogs | ||
# POST /blogs.xml | ||
def create | ||
@blog = Blog.new(params[:blog]) | ||
|
||
respond_to do |format| | ||
if @blog.save | ||
format.html { redirect_to(@blog, :notice => 'Blog was successfully created.') } | ||
format.xml { render :xml => @blog, :status => :created, :location => @blog } | ||
else | ||
format.html { render :action => "new" } | ||
format.xml { render :xml => @blog.errors, :status => :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PUT /blogs/1 | ||
# PUT /blogs/1.xml | ||
def update | ||
@blog = Blog.find(params[:id]) | ||
|
||
respond_to do |format| | ||
if @blog.update_attributes(params[:blog]) | ||
format.html { redirect_to(@blog, :notice => 'Blog was successfully updated.') } | ||
format.xml { head :ok } | ||
else | ||
format.html { render :action => "edit" } | ||
format.xml { render :xml => @blog.errors, :status => :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /blogs/1 | ||
# DELETE /blogs/1.xml | ||
def destroy | ||
@blog = Blog.find(params[:id]) | ||
@blog.destroy | ||
|
||
respond_to do |format| | ||
format.html { redirect_to(blogs_url) } | ||
format.xml { head :ok } | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class FeedsController < ApplicationController | ||
def index | ||
@entries = Blog.all. | ||
map(&:entries). | ||
flatten. | ||
compact. | ||
sort_by(&:date_published). | ||
reverse | ||
render :layout => false | ||
response.headers["Content-Type"] = "application/xml; charset=utf-8" | ||
end | ||
end | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module BlogsHelper | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module FeedsHelper | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require 'open-uri' | ||
require 'feed-normalizer' | ||
|
||
class Blog < ActiveRecord::Base | ||
validates_presence_of :url | ||
validates_uniqueness_of :url | ||
|
||
def entries | ||
feeds = FeedNormalizer::FeedNormalizer.parse(open(url.strip)).entries | ||
feeds.each do |feed| | ||
feed.date_published ||= Date.today - 100.years | ||
end | ||
feeds | ||
end | ||
end | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<h1>Editing blog</h1> | ||
|
||
<% form_for(@blog) do |f| %> | ||
<%= f.error_messages %> | ||
|
||
<p> | ||
<%= f.label :url %><br /> | ||
<%= f.text_field :url %> | ||
</p> | ||
<p> | ||
<%= f.submit 'Update' %> | ||
</p> | ||
<% end %> | ||
<%= link_to 'Show', @blog %> | | ||
<%= link_to 'Back', blogs_path %> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<h1>Listing blogs</h1> | ||
|
||
<table> | ||
<tr> | ||
<th>Url</th> | ||
</tr> | ||
|
||
<% @blogs.each do |blog| %> | ||
<tr> | ||
<td><%=h blog.url %></td> | ||
<td><%= link_to 'Show', blog %></td> | ||
<td><%= link_to 'Edit', edit_blog_path(blog) %></td> | ||
<td><%= link_to 'Destroy', blog, :confirm => 'Are you sure?', :method => :delete %></td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
|
||
<br /> | ||
|
||
<%= link_to 'New blog', new_blog_path %> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<h1>New blog</h1> | ||
|
||
<% form_for(@blog) do |f| %> | ||
<%= f.error_messages %> | ||
|
||
<p> | ||
<%= f.label :url %><br /> | ||
<%= f.text_field :url %> | ||
</p> | ||
<p> | ||
<%= f.submit 'Create' %> | ||
</p> | ||
<% end %> | ||
<%= link_to 'Back', blogs_path %> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<p> | ||
<b>Url:</b> | ||
<%=h @blog.url %> | ||
</p> | ||
|
||
|
||
<%= link_to 'Edit', edit_blog_path(@blog) %> | | ||
<%= link_to 'Back', blogs_path %> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
xml.instruct! | ||
|
||
xml.rss "version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/" do | ||
xml.channel do | ||
xml.title "Planeta NSI" | ||
xml.link url_for :only_path => false, :controller => 'index' | ||
xml.description "Textos e artigos dos membros do NSI" | ||
|
||
@entries.each do |article| | ||
xml.item do | ||
author = article.author.include?('(') ? article.author.split('(')[1].chop : article.author | ||
xml.title "[#{author}] #{article.title}]" | ||
xml.link article.url | ||
xml.description article.content | ||
xml.guid article.url | ||
xml.pubDate article.date_published || Date.today - 100.years | ||
end | ||
end | ||
end | ||
end | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | ||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
|
||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | ||
<head> | ||
<meta http-equiv="content-type" content="text/html;charset=UTF-8" /> | ||
<title>Blogs: <%= controller.action_name %></title> | ||
<%= stylesheet_link_tag 'scaffold' %> | ||
</head> | ||
<body> | ||
|
||
<p style="color: green"><%= notice %></p> | ||
|
||
<%= yield %> | ||
|
||
</body> | ||
</html> |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class CreateBlogs < ActiveRecord::Migration | ||
def self.up | ||
create_table :blogs do |t| | ||
t.string :url | ||
|
||
t.timestamps | ||
end | ||
end | ||
|
||
def self.down | ||
drop_table :blogs | ||
end | ||
end | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# This file is auto-generated from the current state of the database. Instead of editing this file, | ||
# please use the migrations feature of Active Record to incrementally modify your database, and | ||
# then regenerate this schema definition. | ||
# | ||
# Note that this schema.rb definition is the authoritative source for your database schema. If you need | ||
# to create the application database on another system, you should be using db:schema:load, not running | ||
# all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations | ||
# you'll amass, the slower it'll run and the greater likelihood for issues). | ||
# | ||
# It's strongly recommended to check this file into your version control system. | ||
|
||
ActiveRecord::Schema.define(:version => 20100820042939) do | ||
|
||
create_table "blogs", :force => true do |t| | ||
t.string "url" | ||
t.datetime "created_at" | ||
t.datetime "updated_at" | ||
end | ||
|
||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
body { background-color: #fff; color: #333; } | ||
|
||
body, p, ol, ul, td { | ||
font-family: verdana, arial, helvetica, sans-serif; | ||
font-size: 13px; | ||
line-height: 18px; | ||
} | ||
|
||
pre { | ||
background-color: #eee; | ||
padding: 10px; | ||
font-size: 11px; | ||
} | ||
|
||
a { color: #000; } | ||
a:visited { color: #666; } | ||
a:hover { color: #fff; background-color:#000; } | ||
|
||
.fieldWithErrors { | ||
padding: 2px; | ||
background-color: red; | ||
display: table; | ||
} | ||
|
||
#errorExplanation { | ||
width: 400px; | ||
border: 2px solid red; | ||
padding: 7px; | ||
padding-bottom: 12px; | ||
margin-bottom: 20px; | ||
background-color: #f0f0f0; | ||
} | ||
|
||
#errorExplanation h2 { | ||
text-align: left; | ||
font-weight: bold; | ||
padding: 5px 5px 5px 15px; | ||
font-size: 12px; | ||
margin: -7px; | ||
background-color: #c00; | ||
color: #fff; | ||
} | ||
|
||
#errorExplanation p { | ||
color: #333; | ||
margin-bottom: 0; | ||
padding: 5px; | ||
} | ||
|
||
#errorExplanation ul li { | ||
font-size: 12px; | ||
list-style: square; | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require 'spec_helper' | ||
|
||
describe FeedsController do | ||
|
||
#Delete this example and add some real ones | ||
it "should use FeedsController" do | ||
controller.should be_an_instance_of(FeedsController) | ||
end | ||
|
||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html | ||
|
||
one: | ||
url: MyString | ||
|
||
two: | ||
url: MyString |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'spec_helper' | ||
|
||
describe FeedsHelper do | ||
|
||
#Delete this example and add some real ones or delete this file | ||
it "should be included in the object returned by #helper" do | ||
included_modules = (class << helper; self; end).send :included_modules | ||
included_modules.should include(FeedsHelper) | ||
end | ||
|
||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require 'spec_helper' | ||
|
||
describe Blog do | ||
before(:each) do | ||
@valid_attributes = { | ||
:url => "value for url" | ||
} | ||
end | ||
|
||
it "should create a new instance given valid attributes" do | ||
Blog.create!(@valid_attributes) | ||
end | ||
end |
Oops, something went wrong.