Permalink
Browse files

merge with http://github.com/awagener/refinerycms-blog

  • Loading branch information...
2 parents 62415fb + efd43f0 commit 60923743e7b4776c06ba079dff6a1b9e632f86e2 @unixcharles unixcharles committed Jun 11, 2010
View
8 app/controllers/admin/blogs_controller.rb
@@ -1,8 +1,16 @@
class Admin::BlogsController < Admin::BaseController
+
before_filter :get_count, :only => 'index'
+ before_filter :group_blogs_by_date, :only => 'index'
+
crudify :blog, :title_attribute => :title, :order => "publishing_date DESC"
def get_count
@unread_comments_count = Comment.unread.count
end
+
+ def group_blogs_by_date
+ @grouped_blogs = Blog.grouped_by_date
+ end
+
end
View
20 app/models/blog.rb
@@ -1,5 +1,7 @@
class Blog < ActiveRecord::Base
+
acts_as_taggable_on :categories, :tags, :authors
+
has_many :comments
named_scope :published, lambda {{:conditions => ["publishing_date < '#{Time.now.to_formatted_s(:db)}' and draft != ?", true],
@@ -9,15 +11,29 @@ class Blog < ActiveRecord::Base
acts_as_indexed :fields => [:title, :permalink, :excerpt, :body],
:index_file => [Rails.root.to_s, "tmp", "index"]
- validates_presence_of :title, :permalink, :excerpt, :body
- validates_uniqueness_of :title, :permalink
+ validates_presence_of :excerpt, :body
+ validates_uniqueness_of :title, :permalink, :case_sensitive => true
validates_format_of :permalink, :with => /^(([-_]|[a-z]|\d){1,100})$/, :message => " is invalid, only lowercase alphanumeric character and _-"
validates_length_of :permalink, :within => 4..99
+ validates_length_of :title, :within => 2..95
+
+ def before_validation
+ self.permalink = title.parameterize if permalink.blank?
+ end
def published?
# A blog post should be published? if:
# the publishing date is before now and it is not a draft blog post.
publishing_date <= Time.now && !draft
end
+
+ def num_comments
+ comments.size
+ end
+
+ def self.grouped_by_date
+ all.group_by { |blog| blog.publishing_date.to_date }.sort {|a,b| b[0] <=> a[0]}
+ end
+
end
View
1 app/models/comment.rb
@@ -9,7 +9,6 @@ class Comment < ActiveRecord::Base
validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i,
:message => 'must be valid'
- validates_presence_of :name, :email, :body, :title
validates_length_of :name, :email, :title, :within => 3..80
validates_length_of :body, :within => 3..1000
View
2 app/views/admin/blog_settings/_blog_setting.html.erb
@@ -9,7 +9,7 @@
:title => 'Edit this blog setting' if blog_setting.value.nil? %>
</span>
<strong><%=h blog_setting.name %></strong>
- is set to <strong>"<%=h blog_setting.value.nil? ? blog_setting.entry : blog_setting.value %>"</strong>
+ <%= "is set to <strong>#{h blog_setting.entry}</strong>" if blog_setting.entry %>
<%= link_to '?', edit_admin_blog_setting_path(blog_setting), :title => blog_setting.description %>
<span class="preview">&nbsp;</span>
</span>
View
8 app/views/admin/blog_settings/index.html.erb
@@ -1,10 +1,4 @@
-<div id='actions'>
- <ul>
- <li>
- <%= link_to "Manage Blog", admin_blogs_url, :class => "back_icon" %>
- </li>
- </ul>
-</div>
+<%= render :partial => '/admin/blogs/side_bar' %>
<div id='records'>
<% if @blog_settings.present? and @blog_settings.any? %>
<%= will_paginate @blog_settings, :previous_label => '&laquo;', :next_label => '&raquo;' %>
View
3 app/views/admin/blogs/_blog.html.erb
@@ -10,6 +10,7 @@
:class => "cancel confirm-delete",
:title => 'Remove this blog post forever' %>
</span>
- <%=h truncate blog.title, :length => 60 %> <span class="preview">&nbsp;</span>
+ <%=h truncate blog.title, :length => 60 %>
+ <span class="preview"><%= pluralize blog.num_comments, 'comment' %></span>
</span>
</li>
View
108 app/views/admin/blogs/_form.html.erb
@@ -3,7 +3,7 @@
<div class='field'>
<%= f.label :title -%>
- <%= f.text_field :title, :class => 'larger' -%>
+ <%= f.text_field :title, :class => 'larger', :style => 'width: 944px' -%>
</div>
<div class='field'>
@@ -16,56 +16,80 @@
<%= f.text_area :body, :rows => 20, :cols => 140, :class => 'wymeditor' -%>
</div>
- <div class='field'>
- <%= f.label :permalink -%>
- <b>http://<%=h request.domain %>/blog/<%= f.text_field :permalink -%>/</b>
- <p>
- Only lowcase alphanumeric characters, underscore and dash.
- (Ex.: webdesign-more_css_tips)
- </p>
- </div>
+ <p>
+ <%= link_to "&raquo; Hide/Show Advanced Options", "#",
+ :id => 'toggle_advanced_options',
+ :rel => 'Click to access meta tag settings and menu options' %>
+ </p>
- <div class='field'>
- <%= f.label :draft -%>
- <%= f.check_box :draft -%>
- </div>
+ <div id='more_options' style="display:none;">
+ <div class='field'>
+ <%= f.label :publishing_date, "Date published" -%>
+ <%= f.datetime_select :publishing_date -%>
+ </div>
+
+ <div class='field'>
+ <label>Allow comments</label>
+ <%= f.check_box :allow_comment -%>
+ <%= f.label :allow_comment, "Allow readers to comment on this post", :class => "stripped" %>
+ </div>
- <div class='field'>
- <%= f.label :allow_comment -%>
- <%= f.check_box :allow_comment -%>
- </div>
+ <div class='field'>
+ <%= f.label :permalink -%>
+ <b>http://<%=h request.domain %>/blog/<%= f.text_field :permalink -%>/</b><br/>
+ <small>
+ Allowed characters are: lowercase letters, numbers, underscores and dashes.
+ </small>
+ </div>
- <div class='field'>
- <%= f.label :category_list %>
- <%= f.text_field :category_list %>
- <p>
- separate with coma.
- (Ex.: Programming, Web Design)
- </p>
- </div>
+ <div class='field'>
+ <%= f.label :category_list, "Categories" %>
+ <%= f.text_field :category_list %><br/>
+ <small>
+ Separate with commas, e.g. "Programming, Web Design"
+ </small>
+ </div>
- <div class='field'>
- <%= f.label :tag_list %>
- <%= f.text_field :tag_list %>
- <p>
- separate with coma.
- (Ex.: RefineryCMS, Rails, Models, Validation)
- </p>
- </div>
+ <div class='field'>
+ <%= f.label :tag_list, "Tags" %>
+ <%= f.text_field :tag_list %><br/>
+ <small>
+ Separate with commas, e.g. "RefineryCMS, Rails, Models, Validation"
+ </small>
+ </div>
- <div class='field'>
- <%= f.label :author_list %>
- <%= f.text_field :author_list %>
- <p>
- separate with coma.
- (Ex.: Bob Dylan, Jimi Hendrix, John Lennon)
- </p>
+ <div class='field'>
+ <%= f.label :author_list, "Authors" %>
+ <%= f.text_field :author_list %><br/>
+ <small>
+ Separate with commas, e.g. "Bob Dylan, Jimi Hendrix, John Lennon"
+ </small>
+ </div>
</div>
<div class='field'>
- <%= f.label :publishing_date -%>
- <%= f.datetime_select :publishing_date -%>
+ <label>Draft</label>
+ <%= f.check_box :draft -%>
+ <%= f.label :draft, "Save as Draft", :class => "stripped" %>
</div>
<%= render :partial => "/shared/admin/form_actions", :locals => {:f => f, :continue_editing => false} %>
<% end -%>
+
+<% content_for :head do %>
+ <script type='text/javascript'>
+ $(document).ready(function(){
+ $('#toggle_advanced_options').click(function(e){
+ e.preventDefault();
+ $('#more_options').animate({
+ opacity: 'toggle'
+ , height: 'toggle'
+ }, 250);
+
+ $('html,body').animate({
+ scrollTop: $('#toggle_advanced_options').parent().offset().top
+ }, 250);
+ });
+ });
+ </script>
+<% end %>
View
16 app/views/admin/blogs/_side_bar.html.erb
@@ -0,0 +1,16 @@
+<div id='actions'>
+ <ul>
+ <li>
+ <%= render :partial => "/shared/admin/search", :locals => {:url => admin_blogs_url} %>
+ </li>
+ <li>
+ <%= link_to "Create new post", new_admin_blog_url, :class => "add_icon" %>
+ </li>
+ <li>
+ <%= link_to "Moderate comments (#{Comment.unread.count} unread)", admin_comments_url, :class => "user_comment_icon" %>
+ </li>
+ <li>
+ <%= link_to "Edit settings", admin_blog_settings_url, :class => "edit_icon" %>
+ </li>
+ </ul>
+</div>
View
54 app/views/admin/blogs/index.html.erb
@@ -1,49 +1,25 @@
-<div id='actions'>
- <ul>
- <li>
- <%= render :partial => "/shared/admin/search", :locals => {:url => admin_blogs_url} %>
- </li>
- <li>
- <%= link_to "Create New Blog", new_admin_blog_url, :class => "add_icon" %>
- </li>
- <li>
- <%= link_to "Manage comments", admin_comments_url, :class => "user_comment_icon" %>
- </li>
- <li>
- <%= link_to "Edit blog settings", admin_blog_settings_url, :class => "edit_icon" %>
- </li>
-
- </ul>
-</div>
+<%= render :partial => 'side_bar' %>
<div id='records'>
<% if searching? %>
<h2>Search Results for "<%= params[:search] %>"</h2>
- <% if @blogs.present? and @blogs.any? %>
+ <% if @blogs.any? %>
<%= render :partial => "blog", :collection => @blogs %>
<% else %>
<p>Sorry, no results found.</p>
<% end %>
+ <% elsif @grouped_blogs.any? %>
+ <% @grouped_blogs.each do |date, posts| %>
+ <h3><%= date.strftime("%A, #{date.day} %B %Y") %></h3>
+ <ul>
+ <%= render :partial => 'blog', :collection => posts %>
+ </ul>
+ <% end %>
<% else %>
- <% if @blogs.present? and @blogs.any? %>
- <% if @unread_comments_count > 0 %>
- <p>
- <strong>
- You have <%= @unread_comments_count %> unread comment<%= 's' unless @unread_comments_count == 1%>
- </strong>
- </p>
- <% end %>
- <%= will_paginate @blogs, :previous_label => '&laquo;', :next_label => '&raquo;' %>
- <ul>
- <%= render :partial => 'blog', :collection => @blogs %>
- </ul>
- <%= will_paginate @blogs, :previous_label => '&laquo;', :next_label => '&raquo;' %>
- <% else %>
- <p>
- <strong>
- There are no blogs yet.
- Click "Create New Blog" to add your first blog.
- </strong>
- </p>
- <% end %>
+ <p>
+ <strong>
+ There are no posts yet.
+ Click "Create New Post" to add your first post to your blog.
+ </strong>
+ </p>
<% end %>
</div>
View
11 app/views/admin/comments/index.html.erb
@@ -1,13 +1,4 @@
-<div id='actions'>
- <ul>
- <li>
- <%= render :partial => "/shared/admin/search", :locals => {:url => admin_comments_url} %>
- </li>
- <li>
- <%= link_to "Manage Blog", admin_blogs_url, :class => "back_icon" %>
- </li>
- </ul>
-</div>
+<%= render :partial => '/admin/blogs/side_bar' %>
<div id='records'>
<% if searching? %>
<h2>Search Results for "<%= params[:search] %>"</h2>
View
3 app/views/admin/comments/show.html.erb
@@ -8,9 +8,8 @@
<ul>
<li>
<%= link_to "Mark this comment as #{@comment.is_approved? ? 'refused' : 'approved'}",
- toggle_status_admin
{:action => "toggle_status", :id => @comment.id},
- :class => @comment.is_approved? ? 'failure_icon' : 'success_icon' %>
+ :class => (@comment.is_approved? ? 'failure_icon' : 'success_icon') %>
</li>
<li>
<%= link_to "Back to all Comments", {:action => 'index'}, :class => "back_icon" %>
View
3 app/views/blogs/_blog.html.erb
@@ -1,3 +0,0 @@
-<li>
- <%= link_to blog.title, blog_post_url(blog.permalink) %>
-</li>
View
11 app/views/blogs/_blog_post.html.erb
@@ -0,0 +1,11 @@
+<h2><%= link_to blog_post.title, blog_post_url(blog_post.permalink) %></h2>
+<p class="post_date">
+ <%= blog_post.publishing_date.to_date.to_s(:long) %>
+ <%= " by #{blog_post.author_list.to_sentence}" unless blog_post.authors.blank? %>
+</p>
+<p>
+ <%= blog_post.excerpt %>
+</p>
+<p>
+ <%= link_to 'Read more', blog_post_url(blog_post.permalink) -%> (<%= pluralize blog_post.num_comments, 'comment' %>)
+</p>
View
1 app/views/blogs/_comments.html.erb
@@ -5,7 +5,6 @@
<h4><%=h comment.title %></h4>
<p><%=h comment.body %></p>
<p>comment from <%=h comment.name %>, <%= time_ago_in_words comment.created_at %> ago</p>
- <hr/>
<% end %>
</div>
<% end %>
View
17 app/views/blogs/_form.html.erb
@@ -1,11 +1,5 @@
-<% form_for @comment, :url =>comment_url(@blog.permalink) do |f| %>
+<% form_for @comment, :url => comment_url(@blog.permalink) do |f| %>
<div class='comments'>
- <% if BlogSetting.enable_captcha %>
- <h3>Are you human?</h3>
- <div class='field'>
- <%= Raptcha.input :kw => {:background => 'black'} %>
- </div>
- <% end %>
<h3>Post your comment:</h3>
<div class='field'>
<%= f.label :name -%>
@@ -27,8 +21,15 @@
<%= f.text_area :body, :rows => 8 -%>
</div>
+ <% if BlogSetting.enable_captcha %>
+ <h3>Are you human?</h3>
+ <div class='field'>
+ <%= Raptcha.input :kw => {:background => 'black'} %>
+ </div>
+ <% end %>
+
<div class='actions'>
- <%= f.submit 'send comment' %>
+ <%= f.submit 'add comment' %>
</div>
</div>
<% end -%>
View
8 app/views/blogs/_side_body.html.erb
@@ -1,4 +1,4 @@
-<% if @categories.present? and @categories.any? %>
+<% unless @categories.blank? %>
<h2>Categories</h2>
<ul id="categories">
<% @categories.each do |category| %>
@@ -9,7 +9,7 @@
</ul>
<% end %>
-<% if @tags.present? and @tags.any? %>
+<% unless @tags.blank? %>
<h2>Tags</h2>
<ul id="tags">
<% @tags.each do |tag| %>
@@ -20,7 +20,7 @@
</ul>
<% end %>
-<% if @authors.present? and @authors.any? %>
+<% unless @authors.blank? %>
<h2>Authors</h2>
<ul id="tags">
<% @authors.each do |author| %>
@@ -31,7 +31,7 @@
</ul>
<% end %>
-<% if @recent_blogs.present? and @recent_blogs.any? %>
+<% unless @recent_blogs.blank? %>
<h2>Recent posts</h2>
<ul id="blogs">
<% @recent_blogs.each do |blog| %>
View
19 app/views/blogs/index.html.erb
@@ -1,22 +1,11 @@
-<% content_for :head_after_javascript_libraries do %>
+<% content_for :head do %>
<%= auto_discovery_link_tag(:rss, blog_url(:format => 'rss'), {:title => "#{RefinerySetting.find_or_set(:site_name, "Company Name")} Blog"}) %>
<% end %>
<% content_for :body_content_left do %>
- <% @blogs.each do |blog| %>
- <div class="blog">
- <h2><%= blog.title %></h2>
- <p>
- <small><%= blog.publishing_date.to_date.to_s(:long) %></small>
- </p>
- <p>
- <%= blog.excerpt %>
- </p>
- <p>
- <%= link_to 'Read more', blog_post_url(blog.permalink) -%>
- </p>
- </div>
- <% end %>
+ <div class="blog_posts">
+ <%= render :partial => 'blog_post', :collection => @blogs %>
+ </div>
<% end %>
<% content_for :body_content_right do %>
View
44 app/views/blogs/show.html.erb
@@ -7,58 +7,46 @@
<% end %>
<% content_for :body_content_left do %>
-<div id='body_content_left' class='clearfix'>
- <%= @message if @message %>
- <%= error_messages_for :comment, :header_message => "Whoops there was a small problem",
- :message => "The following problems need to be corrected:" %>
<div class="body">
<%= @blog.body %>
</div>
-<% if @authors %>
- <% if @blog.author_list.present? and @blog.author_list.any? %>
+
+ <% if @authors and @blog.author_list.present? and @blog.author_list.any? %>
<div class="authors">
<p>By
- <% @blog.author_list.each do |author|%>
- <%= link_to author, blog_author_url(author) -%><%= author == @blog.author_list.last ? '.' : ', ' %>
- <% end %>
+ <%= @blog.author_list.collect{ |author| link_to author, blog_author_url(author) }.join(', ') %>
</p>
</div>
<% end %>
-<% end %>
- <hr/>
-<% if @categories %>
- <% if @blog.category_list.present? and @blog.category_list.any? %>
+
+ <% if @categories and @blog.category_list.present? and @blog.category_list.any? %>
<div class="categories">
- <p>Filled under:
- <% @blog.category_list.each do |category|%>
- <%= link_to category, blog_category_url(category) -%><%= category == @blog.category_list.last ? '.' : ', ' %>
- <% end %>
+ <p>Filed under:
+ <%= @blog.category_list.collect{ |category| link_to category, blog_category_url(category) }.join(', ') %>
</p>
</div>
<% end %>
-<% end %>
-<% if @tags %>
- <% if @blog.tag_list.present? and @blog.tag_list.any? %>
+
+ <% if @tags and @blog.tag_list.present? and @blog.tag_list.any? %>
<div class="categories">
<p>Tags:
- <% @blog.tag_list.each do |tag| -%>
- <%= link_to tag, blog_tag_url(tag) -%><%= tag == @blog.tag_list.last ? '.' : ', ' -%>
- <% end -%>
+ <%= @blog.tag_list.collect{ |tag| link_to tag, blog_tag_url(tag) }.join(', ') %>
</p>
</div>
<% end %>
-<% end %>
<%= 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:" %>
+
<%= render :partial => 'form' %>
-</div>
<% end %>
<% content_for :body_content_right do %>
-<div>
<h2>Publishing Date</h2>
- Posted on <%= @blog.publishing_date %>
-</div>
+ <p>Posted on <%= @blog.publishing_date.to_s(:long_ordinal) %></p>
<%= render :partial => 'see_also' %>
<%= render :partial => 'side_body' %>
View
2 config/routes.rb
@@ -12,7 +12,7 @@
map.raptcha '/raptcha', :controller => 'blogs', :action => 'captcha'
- map.namespace(:admin, :path_prefix => 'refinery') do |admin|
+ map.namespace(:admin, :path_prefix => (defined?(REFINERY_GEM_VERSION) ? "admin" : "refinery") ) do |admin|
admin.resources :blogs, :as => 'blog'
admin.resources :comments, :member => {:toggle_status => :get, :unread => :get}
admin.connect 'blog_settings/toggle_setting/:id', :controller => "blog_settings", :action => "toggle_setting"

0 comments on commit 6092374

Please sign in to comment.