Permalink
Browse files

Fix up some of the routes, prepping a better navigation.

  • Loading branch information...
1 parent 121ea1a commit 2735effe503d61fd6cc397eac7040bb1a7480647 @seancribbs seancribbs committed Aug 17, 2009
@@ -4,7 +4,7 @@ def index
@comments = load_comments
respond_to do |format|
format.html
- format.csv { render :text => @comments.to_csv }
+ format.csv { send_data @comments.to_csv, :filename => "#{File.basename(request.request_uri)}", :type => 'text/csv' }
end
end
@@ -0,0 +1,7 @@
+module Admin::CommentsHelper
+ def link_or_span_unless_current(text, url, options={})
+ link_to_unless_current(text,url, options) do
+ content_tag(:span, text)
+ end
+ end
+end
@@ -1,25 +1,22 @@
+<% include_stylesheet 'admin/comments' %>
<h1>
- <% if @page.nil? %>
- <%= "#{params[:status].titleize if params[:status]} Comments |
- #{link_to('Download CSV', {:format => 'csv', :status => params[:status]})}" %>
- <% else %>
- <%= "#{@page.comments_count} #{pluralize(@page.comments_count, "Comment")} on
- #{link_to(@page.title, page_edit_url(@page.id))}|
- #{link_to('Download CSV', {:format => 'csv', :status => params[:status], :page_id => @page.id})}
- " %>
- <% end %>
+ <% if @page -%>
+ <%= @page.comments.count %> <%= pluralize(@page.comments.count, 'Comment') %> on <%= link_to @page.title, edit_admin_page_path(@page) %>
+ <% else -%>
+ <%= params[:status].titleize if params[:status] %> Comments
+ <% end -%>
</h1>
-<p class="comment-nav">
- View:
- <%= content_tag :span, link_to_unless_current("All Comments", :status => "all", :page_id => params[:page_id]) %>
- <%= content_tag :span, link_to_unless_current("Approved Comments", :status => "approved", :page_id => params[:page_id]) %>
- <%= content_tag :span, link_to_unless_current("Unapproved Comments", :status => "unapproved", :page_id => params[:page_id]) %>
-</p>
+<ul id="comment-nav">
+ <li class="all"><%= link_or_span_unless_current("All Comments", :status => 'all', :page_id => params[:page_id]) %></li>
+ <li class="approved"><%= link_or_span_unless_current("Approved Comments", :status => "approved", :page_id => params[:page_id]) %></li>
+ <li class="unapproved"><%= link_or_span_unless_current("Unapproved Comments", :status => "unapproved", :page_id => params[:page_id]) %></li>
+ <li class="csv"><%= link_to "Download CSV", :format => :csv %></li>
+</ul>
<table id="comments" class="index" border="0" cellspacing="0" cellpadding="0">
<tbody>
- <%= render :partial => "comment", :collection => (@comments) %>
+ <%= render :partial => "comment", :collection => @comments %>
</tbody>
</table>
@@ -35,10 +32,4 @@
<small class="notice">Comments are protected from spam by a simple challenge/response field. For more robust spam filtering, try <a href="http://mollom.com">Mollom</a> or <a href="http://akismet.com/">Akismet</a>.</small>
<% elsif current_user.developer? || current_user.admin? %>
<small class="note">You have 3 built-in options for spam protection although currently comments are not automatically protected. Install <a href="http://mollom.com">Mollom</a> or <a href="http://akismet.com/">Akismet</a> to protect against comment spam through an external service, or use the &lt;r:comments:spam_answer_tag /&gt;. Instructions may be found in the README.</small>
-<% end %>
-
-<script type="text/javascript">
-// <![CDATA[
- new RuledTable('comments');
-// ]]>
-</script>
+<% end %>
View
@@ -5,7 +5,8 @@ class CommentsExtension < Radiant::Extension
define_routes do |map|
map.namespace :admin do |admin|
- admin.connect 'comments/:status', :controller => 'comments', :status => /all|approved|unapproved/, :conditions => { :method => :get }
+ admin.connect 'comments/:status', :controller => 'comments', :status => 'unapproved', :conditions => { :method => :get }, :requirements => { :status => /all|unapproved|approved/ }
+ admin.connect 'comments/:status.:format', :controller => 'comments', :status => /all|approved|unapproved/, :conditions => { :method => :get }
admin.resources :comments, :member => { :remove => :get, :approve => :put, :unapprove => :put }, :collection => {:destroy_unapproved => :delete}
admin.page_enable_comments '/pages/:page_id/comments/enable', :controller => 'comments', :action => 'enable', :conditions => {:method => :put}
end
@@ -37,7 +38,7 @@ def activate
admin.page.index.add :node, "index_view_comments"
end
- admin.tabs.add "Comments", "/admin/comments/unapproved", :visibility => [:all]
+ admin.tabs.add "Comments", "/admin/comments", :visibility => [:all]
require "fastercsv"
ActiveRecord::Base.class_eval do
@@ -7,13 +7,23 @@
end
describe "routing" do
+ it "should route to unapproved comments by default" do
+ params_from(:get, "/admin/comments").should == { :controller => "admin/comments", :action => "index", :status => 'unapproved' }
+ end
+
%w(all approved unapproved).each do |status|
it "should route to the index action for #{status} comments" do
params_from(:get, "/admin/comments/#{status}").should == { :controller => "admin/comments", :action => "index", :status => status }
end
it "should route to the index action for #{status} comments on the page" do
params_from(:get, "/admin/pages/1/comments/#{status}").should == { :controller => "admin/comments", :action => "index", :page_id => "1", :status => status }
end
+ it "should route to the index action for #{status} comments with the csv format" do
+ params_from(:get, "/admin/comments/#{status}.csv").should == { :controller => "admin/comments", :action => "index", :status => status, :format => 'csv' }
+ end
+ it "should route to the index action for #{status} comments on the page with the csv format" do
+ params_from(:get, "/admin/pages/1/comments/#{status}.csv").should == { :controller => "admin/comments", :action => "index", :status => status, :page_id => "1", :format => 'csv' }
+ end
end
it "should route to the destroy_unapproved action" do

0 comments on commit 2735eff

Please sign in to comment.