Permalink
Browse files

Initial work to move to Rails resources

  • Loading branch information...
1 parent 98ebc4a commit 6976d99c0c48b918621dbcea066ebccb3e800530 @johnl committed Jun 28, 2009
@@ -18,101 +18,17 @@
class NewsArticlesController < ApplicationController
layout 'newsniffer'
- def list
- @title = "Revisionista latest news article list"
+ def index
+ @title = "Latest news articles"
@articles = NewsArticle.paginate :include => 'versions', :page => params[:page] || 1,
- :order => "news_articles.created_at desc"
- render :action => 'list_articles'
+ :order => "news_articles.id desc"
+ # TODO: rss
end
-
- def list_revisions
- @title = "Revisionista latest revision list"
- @discovery_links = [ [url_for(:action => "list_rss"), "Latest news revisions"] ]
- @versions = NewsArticleVersion.paginate :per_page => 16, :page => params[:page] || 1,
- :include => 'news_article', :order => "news_article_versions.created_at desc",
- :conditions => 'news_article_versions.version > 0'
- end
-
- def list_recommended
- @title = "Revisionista recommended revisions"
- @discovery_links = [ [url_for(:action => "list_recommended_rss"), "Latest recommended news revisions"] ]
- @versions = NewsArticleVersion.paginate(:per_page => 16, :page => params[:page] || 1,
- :include => 'news_article',
- :order => "news_article_versions.votes desc, news_article_versions.created_at desc",
- :conditions => 'news_article_versions.version > 0 and news_article_versions.votes > 0')
- render :action => 'list_revisions'
- end
-
- def list_recommended_rss
- @versions = NewsArticleVersion.find_by_sql("SELECT news_article_versions.created_at, news_article_versions.title, votes, news_article_versions.id, version, news_article_id, news_articles.id, news_articles.source
- FROM news_article_versions, votes, news_articles
- WHERE votes.class = 'NewsArticleVersion' AND votes.relation_id = news_article_versions.id
- AND news_article_versions.news_article_id = news_articles.id ORDER BY votes.id desc LIMIT 20")
- render :layout => false
- end
-
- def list_rss
- headers["Content-Type"] = "application/xml"
- @versions = NewsArticleVersion.find(:all, :order => 'news_article_versions.created_at desc',
- :limit => 20,
- :conditions => 'version > 0',
- :include => 'news_article')
- render :layout => false
- end
-
- def search
- @title = "Revision Search - Revisionista"
- @search = cookies[:na_search] = params[:search] || cookies[:na_search]
- @versions = NewsArticleVersion.paginate(:limit => 16, :page => params[:page],
- :include => :news_article)
- render :action => :search
- end
-
-
+
def show
@article = NewsArticle.find(params[:id])
@versions = @article.versions.find(:all, :order => 'version asc', :select => "id, votes, version, title, created_at")
- end
-
- def show_version
- @article = NewsArticle.find(params[:id])
- @versions = @article.versions.find(:all, :order => 'version asc', :select => "id, votes, version, title")
- @version = @article.versions.find(params[:version])
- end
-
- def diff_rss
- @article = NewsArticle.find(params[:id])
- @versions = @article.versions.find(:all, :order => 'version desc', :select => "id, created_at, version, title")
- render :layout => false
- end
-
- def diff
- @article = NewsArticle.find(params[:id])
- @discovery_links = [ [url_for(:action => "diff_rss", :id => @article.id), "Latest revisions of this news article"] ]
- @versions = @article.versions.find(:all, :order => 'version asc', :select => "id, votes, version, title")
- @va = @article.versions.find_by_version!(params[:version_a])
- @vb = @article.versions.find_by_version!(params[:version_b])
-
- @next = @versions.fetch(@va.version + 1, nil)
- @prev = @versions.fetch(@vb.version - 1, nil) if @vb.version > 0
-
- @diff = HTMLDiff::diff(@vb.text.split(/\n|<p>/), @va.text.split(/\n|<p>/))
- rescue ActiveRecord::RecordNotFound => e
- flash[:error] = e.message
- redirect_to :action => :list
+ # TODO: rss
end
- def vote
- @version = NewsArticleVersion.find(params[:id])
- if is_admin?
- # An admin vote is with 5, and gets unlimited votes
- 5.times { @voted = Vote.vote @version }
- else
- @voted = Vote.vote @version, cookies['_session_id']
- end
- unless request.xhr?
- flash[:notice] = 'Thank you for your recommendation'
- redirect_to :controller => 'news_articles', :action => 'list' #FIXME
- end
- end
end
@@ -0,0 +1,57 @@
+class VersionsController < ApplicationController
+
+ layout 'newsniffer'
+
+ def index
+ @title = "Versions"
+ @discovery_links = [ [url_for(:format => :xml), "Latest versions"] ]
+ @versions = NewsArticleVersion.paginate :per_page => 16, :page => params[:page] || 1,
+ :include => 'news_article', :order => "news_article_versions.id desc"
+ # TODO: xml template
+ end
+
+ def search
+ @title = "Search"
+ @search = cookies[:na_search] = params[:search] || cookies[:na_search]
+ @versions = NewsArticleVersion.paginate(:limit => 16, :page => params[:page],
+ :include => :news_article)
+ render :action => :search
+ end
+
+ def show
+ @article = NewsArticle.find(params[:article_id])
+ @versions = @article.versions.find(:all, :order => 'version asc')
+ @version = @article.versions.find(params[:id])
+ end
+
+ def diff
+ @article = NewsArticle.find(params[:id])
+ @discovery_links = [ [url_for(:action => "diff_rss", :id => @article.id), "Latest revisions of this news article"] ]
+ @versions = @article.versions.find(:all, :order => 'version asc', :select => "id, votes, version, title")
+ @va = @article.versions.find_by_version!(params[:version_a])
+ @vb = @article.versions.find_by_version!(params[:version_b])
+
+ @next = @versions.fetch(@va.version + 1, nil)
+ @prev = @versions.fetch(@vb.version - 1, nil) if @vb.version > 0
+
+ @diff = HTMLDiff::diff(@vb.text.split(/\n|<p>/), @va.text.split(/\n|<p>/))
+ rescue ActiveRecord::RecordNotFound => e
+ flash[:error] = e.message
+ redirect_to :action => :list
+ end
+
+ def vote
+ @version = NewsArticleVersion.find(params[:id])
+ if is_admin?
+ # An admin vote is with 5, and gets unlimited votes
+ 5.times { @voted = Vote.vote @version }
+ else
+ @voted = Vote.vote @version, cookies['_session_id']
+ end
+ unless request.xhr?
+ flash[:notice] = 'Thank you for your recommendation'
+ redirect_to :controller => 'news_articles', :action => 'list' #FIXME
+ end
+ end
+
+end
@@ -0,0 +1,2 @@
+module VersionsHelper
+end
@@ -21,10 +21,9 @@
:class => (controller.controller_name == 'pages' and controller.action_name == 'summary') ? "selected" : "" %></li>
<li><%= link_to 'About', { :controller => 'pages',
:action => :about }, :class => (controller.controller_name == 'pages' and controller.action_name != "summary") ? "selected" : "" %></li>
- <li><%= link_to 'News Articles',
- { :controller => 'news_articles', :action => 'list_revisions', :page => nil, },
+ <li><%= link_to 'News Articles', articles_url,
:title => 'Corporate news article revisions',
- :class => controller.controller_name == "news_articles" ? "selected" : ""%></li>
+ :class => controller.controller_name =~ /news_articles|versions/ ? "selected" : ""%></li>
<li><a href="/blog/">Blog</a></li>
</ul>
</div>
@@ -36,7 +35,7 @@
<%= render :partial => "partials/sidebar_pages" if
controller.controller_name == 'pages' %>
<%= render :partial => "partials/sidebar_revisionista" if
- controller.controller_name == "news_articles" -%>
+ controller.controller_name =~ /news_articles|versions/ -%>
<li>&nbsp;</li>
</ul>
</div>
@@ -9,7 +9,7 @@
<% @versions.each do |version| %>
<tr>
<td>
- <%= link_to version.version, :action => :show_version, :id => @article.id, :version => version.id %>
+ <%= link_to version.version, article_version_url(@article, version) %>
<td>
<%= version.created_at.to_s(:long) %>
</td>
@@ -1,14 +1,8 @@
<li id="menu">
<h2>Revisionista</h2>
<ul>
- <li><%= link_to 'Latest Articles',
- :controller => 'news_articles', :action => 'list', :page => nil %></li>
- <li><%= link_to 'Latest Revisions',
- :controller => 'news_articles', :action => 'list_revisions', :page => nil %></li>
- <li><%= link_to 'Recommended Revisions',
- :controller => 'news_articles', :action => 'list_recommended', :page => nil %></li>
- <li><%= link_to 'Revisions RSS Feed',
- :controller => 'news_articles', :action => 'list_rss' %></li>
+ <li><%= link_to 'Latest Articles', articles_url %></li>
+ <li><%= link_to 'Latest Revisions', versions_url %></li>
<li><%= link_to 'Search',
:controller => 'news_articles', :action => 'search' %></li>
</ul>
View
@@ -1,65 +1,20 @@
ActionController::Routing::Routes.draw do |map|
- # The priority is based upon order of creation: first created -> highest priority.
-
- # Sample of regular route:
- # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
- # Keep in mind you can assign values other than :controller and :action
-
- # Sample of named route:
- # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
- # This route can be invoked with purchase_url(:id => product.id)
- #
map.connect 'admin', :controller => 'admin', :action => 'login'
- map.connect 'bbc/threads/show/:id', :controller => 'bbchysthreads', :action => 'show'
- map.connect 'bbc/threads/:action/page/:page', :controller => 'bbchysthreads'
-
- map.connect 'bbc/threads/:action/:id/:comment_id',
- :controller => 'bbchysthreads'
-
- map.connect 'bbc/threads/:action/:id', :controller => 'bbchysthreads'
-
- map.connect 'bbc/comments/:action/page/:page',
- :controller => 'bbchyscomments'
-
- map.connect 'bbc/comments/feed',
- :controller => 'bbchyscomments', :action => 'list_rss'
-
- map.connect 'bbc/comments/:action/:id', :controller => 'bbchyscomments'
-
- map.connect 'articles/list/page/:page', :controller => 'news_articles', :action => 'list'
- map.connect 'articles/list', :controller => 'news_articles', :action => 'list'
-
- map.connect 'articles/list_by_revision/page/:page', :controller => 'news_articles', :action => 'list_revisions'
- map.connect 'articles/list_by_revision', :controller => 'news_articles', :action => 'list_revisions'
-
- map.connect 'articles/recommended/list/page/:page', :controller => 'news_articles', :action => 'list_recommended'
- map.connect 'articles/recommended/list', :controller => 'news_articles', :action => 'list_recommended'
-
- map.connect 'articles/rss', :controller => 'news_articles', :action => 'list_rss'
- map.connect 'articles/recommended/rss', :controller => 'news_articles', :action => 'list_recommended_rss'
-
- map.connect 'articles/search', :controller => 'news_articles', :action => 'search'
map.connect 'articles/:id/diff/:version_b/:version_a',
:controller => 'news_articles', :action => 'diff'
map.connect 'articles/:id/version/:version',
:controller => 'news_articles', :action => 'show_version'
-
- map.connect 'articles/:id/rss', :controller => 'news_articles', :action => 'diff_rss'
- map.connect 'articles/:id', :controller => 'news_articles', :action => 'show'
- #map.connect ':controller/:action/:id/:comment_id'
-
- # You can have the root of your site routed by hooking up ''
- # -- just remember to delete public/index.html.
+ map.resources :versions
+
+ map.resources :articles, :controller => :news_articles do |article|
+ article.resources :versions
+ end
+
map.connect '', :controller => "pages", :action => 'summary'
- # Allow downloading Web Service WSDL as a file with an extension
- # instead of a file named 'wsdl'
- map.connect ':controller/service.wsdl', :action => 'wsdl'
-
- # Install the default route as the lowest priority.
map.connect ':controller/:action/:id'
end
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class VersionsControllerTest < ActionController::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class VersionsHelperTest < ActionView::TestCase
+end

0 comments on commit 6976d99

Please sign in to comment.