Permalink
Browse files

Tidied display of comment form and comment numbers when commenting di…

…sabled for a post; moved towards including partials to determine whether tags/categories/authors are displayed rather than using the setting
  • Loading branch information...
1 parent 5efd494 commit 8fb7e1cb0181f42ffccc3d72cbf41537b0fd4cdc @awagener awagener committed with unixcharles Jun 15, 2010
@@ -3,7 +3,6 @@ class BlogsController < ApplicationController
before_filter :find_blog, :only => [:comment, :show, :authorize]
before_filter :find_page, :except => [:captcha, :authorize]
before_filter :load_blogs, :except => [:captcha, :authorize, :tag, :category, :author, :show]
- before_filter :load_tags, :except => [:captcha, :authorize]
def index
present(@page)
@@ -90,10 +89,6 @@ def authorize
protected
def load_blogs
@blogs = Blog.published
-
- if BlogSetting.enable_recent_blogs
- @recent_blogs = Blog.published(:limit => 5)
- end
end
def find_blog
@@ -109,23 +104,9 @@ def find_blog
if BlogSetting.enable_related_authors
@related_authors_blogs = @blog.find_related_authors.reject {|blog| !blog.published? && !@blog }
end
-
- # in show action, the recent blog exclude the currently displayed blog
- if BlogSetting.enable_recent_blogs
- @recent_blogs = Blog.find(:all,
- :limit => 5,
- :conditions => ["id != ? and publishing_date < ? and draft != ?", @blog.id, Time.now, true],
- :order => "publishing_date DESC")
- end
end
end
- def load_tags
- @tags = Blog.published.tag_counts if BlogSetting.enable_tags
- @categories = Blog.published.category_counts if BlogSetting.enable_categories
- @authors = Blog.published.author_counts if BlogSetting.enable_authors
- end
-
def find_page
@page = Page.find_by_link_url("/blog")
end
View
@@ -18,6 +18,8 @@ class Blog < ActiveRecord::Base
validates_length_of :permalink, :within => 4..99
validates_length_of :title, :within => 2..95
+ NUM_RECENT_POSTS = 5
+
def before_validation
self.permalink = title.parameterize if permalink.blank?
end
@@ -28,12 +30,34 @@ def published?
publishing_date <= Time.now && !draft
end
- def num_comments
- comments.size
+ def approved_comment_count
+ comments.approved.size
end
def self.grouped_by_date
all.group_by { |blog| blog.publishing_date.to_date }.sort {|a,b| b[0] <=> a[0]}
end
+ def self.tags
+ Blog.published.tag_counts.collect(&:name)
+ end
+
+ def self.categories
+ Blog.published.category_counts.collect(&:name)
+ end
+
+ def self.authors
+ Blog.published.author_counts.collect(&:name)
+ end
+
+ def self.recent_posts
+ Blog.published.first(NUM_RECENT_POSTS)
+ end
+
+ def recent_posts
+ recent_posts = Blog.published(:limit => (NUM_RECENT_POSTS+1))
+ recent_posts.delete(self)
+ recent_posts.first(NUM_RECENT_POSTS)
+ end
+
end
@@ -11,6 +11,6 @@
:title => 'Remove this blog post forever' %>
</span>
<%=h truncate blog.title, :length => 60 %>
- <span class="preview"><%= pluralize blog.num_comments, 'comment' %></span>
+ <span class="preview"><%= pluralize blog.approved_comment_count, 'comment' %></span>
</span>
</li>
@@ -7,5 +7,6 @@
<%= blog_post.excerpt %>
</p>
<p>
- <%= link_to 'Read more', blog_post_url(blog_post.permalink) -%> (<%= pluralize blog_post.num_comments, 'comment' %>)
+ <%= link_to 'Read more', blog_post_url(blog_post.permalink) -%>
+ <%= "(#{pluralize blog_post.approved_comment_count, 'comment'})" if blog_post.allow_comment %>
</p>
@@ -1,43 +1,4 @@
-<% unless @categories.blank? %>
- <h2>Categories</h2>
- <ul id="categories">
- <% @categories.each do |category| %>
- <li>
- <%= link_to category.name, blog_category_url(category.name) -%>
- </li>
- <% end %>
- </ul>
-<% end %>
-
-<% unless @tags.blank? %>
- <h2>Tags</h2>
- <ul id="tags">
- <% @tags.each do |tag| %>
- <li>
- <%= link_to tag.name, blog_tag_url(tag.name) -%>
- </li>
- <% end %>
- </ul>
-<% end %>
-
-<% unless @authors.blank? %>
- <h2>Authors</h2>
- <ul id="tags">
- <% @authors.each do |author| %>
- <li>
- <%= link_to author.name, blog_author_url(author.name) -%>
- </li>
- <% end %>
- </ul>
-<% end %>
-
-<% unless @recent_blogs.blank? %>
- <h2>Recent posts</h2>
- <ul id="blogs">
- <% @recent_blogs.each do |blog| %>
- <li>
- <%= link_to blog.title, blog_post_url(blog.permalink) %>
- </li>
- <% end %>
- </ul>
-<% end %>
+<%= render :partial => '/blogs/side_body/categories' %>
+<%= render :partial => '/blogs/side_body/tags' %>
+<%= render :partial => '/blogs/side_body/authors' %>
+<%= render :partial => '/blogs/side_body/recent_posts' %>
@@ -0,0 +1,7 @@
+<% if @blog.author_list.present? and @blog.author_list.any? %>
+ <div class="authors">
+ <p>By
+ <%= @blog.author_list.collect{ |author| link_to author, blog_author_url(author) }.join(', ') %>
+ </p>
+ </div>
+<% end %>
@@ -0,0 +1,7 @@
+<% if @blog.category_list.present? and @blog.category_list.any? %>
+ <div class="categories">
+ <p>Filed under:
+ <%= @blog.category_list.collect{ |category| link_to category, blog_category_url(category) }.join(', ') %>
+ </p>
+ </div>
+<% end %>
@@ -0,0 +1,7 @@
+<% if @blog.tag_list.present? and @blog.tag_list.any? %>
+ <div class="categories">
+ <p>Tags:
+ <%= @blog.tag_list.collect{ |tag| link_to tag, blog_tag_url(tag) }.join(', ') %>
+ </p>
+ </div>
+<% end %>
@@ -11,37 +11,19 @@
<%= @blog.body %>
</div>
- <% if @authors and @blog.author_list.present? and @blog.author_list.any? %>
- <div class="authors">
- <p>By
- <%= @blog.author_list.collect{ |author| link_to author, blog_author_url(author) }.join(', ') %>
- </p>
- </div>
- <% end %>
-
- <% if @categories and @blog.category_list.present? and @blog.category_list.any? %>
- <div class="categories">
- <p>Filed under:
- <%= @blog.category_list.collect{ |category| link_to category, blog_category_url(category) }.join(', ') %>
- </p>
- </div>
- <% end %>
-
- <% if @tags and @blog.tag_list.present? and @blog.tag_list.any? %>
- <div class="categories">
- <p>Tags:
- <%= @blog.tag_list.collect{ |tag| link_to tag, blog_tag_url(tag) }.join(', ') %>
- </p>
- </div>
- <% end %>
+ <%= render :partial => '/blogs/post/authors' %>
+ <%= render :partial => '/blogs/post/categories' %>
+ <%= render :partial => '/blogs/post/tags' %>
<%= render :partial => 'comments' %>
- <%= @message if @message %>
- <%= error_messages_for :comment, :header_message => "Whoops there was a small problem",
- :message => "The following problems need to be corrected:" %>
+ <% if @blog.allow_comment %>
+ <%= @message if @message %>
+ <%= error_messages_for :comment, :header_message => "Whoops there was a small problem",
+ :message => "The following problems need to be corrected:" %>
- <%= render :partial => 'form' %>
+ <%= render :partial => 'form' %>
+ <% end %>
<% end %>
<% content_for :body_content_right do %>
@@ -0,0 +1,10 @@
+<% unless (authors = Blog.authors).blank? %>
+ <h2>Authors</h2>
+ <ul id="tags">
+ <% authors.each do |author| %>
+ <li>
+ <%= link_to author, blog_author_url(author) -%>
+ </li>
+ <% end %>
+ </ul>
+<% end %>
@@ -0,0 +1,10 @@
+<% unless (categories = Blog.categories).blank? %>
+ <h2>Categories</h2>
+ <ul id="categories">
+ <% categories.each do |category| %>
+ <li>
+ <%= link_to category, blog_category_url(category) -%>
+ </li>
+ <% end %>
+ </ul>
+<% end %>
@@ -0,0 +1,10 @@
+<% unless (recent_posts = (@blog || Blog).recent_posts).blank? %>
+ <h2>Recent posts</h2>
+ <ul id="blogs">
+ <% recent_posts.each do |blog| %>
+ <li>
+ <%= link_to blog.title, blog_post_url(blog.permalink) %>
+ </li>
+ <% end %>
+ </ul>
+<% end %>
@@ -0,0 +1,10 @@
+<% unless (tags = Blog.tags).blank? %>
+ <h2>Tags</h2>
+ <ul id="tags">
+ <% tags.each do |tag| %>
+ <li>
+ <%= link_to tag, blog_tag_url(tag) -%>
+ </li>
+ <% end %>
+ </ul>
+<% end %>

0 comments on commit 8fb7e1c

Please sign in to comment.