diff options
-rw-r--r-- | app/controllers/blog/posts_controller.rb | 34 | ||||
-rw-r--r-- | app/models/blog_comment.rb | 12 | ||||
-rw-r--r-- | app/models/blog_post.rb | 31 | ||||
-rw-r--r-- | app/views/admin/blog/categories/_form.html.erb | 14 | ||||
-rw-r--r-- | app/views/admin/blog/posts/_form.html.erb | 14 | ||||
-rw-r--r-- | app/views/blog/posts/show.html.erb | 20 | ||||
-rw-r--r-- | config/routes.rb | 90 | ||||
-rw-r--r-- | readme.md | 12 |
8 files changed, 67 insertions, 160 deletions
diff --git a/app/controllers/blog/posts_controller.rb b/app/controllers/blog/posts_controller.rb index 5de6984..f489039 100644 --- a/app/controllers/blog/posts_controller.rb +++ b/app/controllers/blog/posts_controller.rb @@ -3,29 +3,21 @@ class Blog::PostsController < BlogController before_filter :find_all_blog_posts, :except => [:archive] before_filter :find_blog_post, :only => [:show, :comment, :update_nav] - respond_to :html, :js, :rss if Rails.version >= '3.0.0' + respond_to :html, :js, :rss def index - if Rails.version < '3.0.0' - # TODO: respond_to block - else - respond_with (@blog_posts) do |format| - format.html - format.rss - end + respond_with (@blog_posts) do |format| + format.html + format.rss end end def show @blog_comment = BlogComment.new - if Rails.version < '3.0.0' - # TODO: respond_to block - else - respond_with (@blog_post) do |format| - format.html { present(@page) } - format.js { render :partial => 'post', :layout => false } - end + respond_with (@blog_post) do |format| + format.html { present(@page) } + format.js { render :partial => 'post', :layout => false } end end @@ -33,11 +25,7 @@ class Blog::PostsController < BlogController if (@blog_comment = @blog_post.comments.create(params[:blog_comment])).valid? if BlogComment::Moderation.enabled? or @blog_comment.ham? begin - if Rails.version < '3.0.0' - Blog::CommentMailer.deliver_notification(@blog_comment, request) - else - Blog::CommentMailer.notification(@blog_comment, request).deliver - end + Blog::CommentMailer.notification(@blog_comment, request).deliver rescue logger.warn "There was an error delivering a blog comment notification.\n#{$!}\n" end @@ -63,11 +51,7 @@ class Blog::PostsController < BlogController :page => params[:page], :per_page => RefinerySetting.find_or_set(:blog_posts_per_page, 10) }) - if Rails.version < '3.0.0' - # TODO: respond_to block - else - respond_with (@blog_posts) - end + respond_with (@blog_posts) end protected diff --git a/app/models/blog_comment.rb b/app/models/blog_comment.rb index 63f9731..f608a1a 100644 --- a/app/models/blog_comment.rb +++ b/app/models/blog_comment.rb @@ -14,15 +14,9 @@ class BlogComment < ActiveRecord::Base validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i - if Rails.version < '3.0.0' - named_scope :unmoderated, :conditions => {:state => nil} - named_scope :approved, :conditions => {:state => 'approved'} - named_scope :rejected, :conditions => {:state => 'rejected'} - else - scope :unmoderated, :conditions => {:state => nil} - scope :approved, :conditions => {:state => 'approved'} - scope :rejected, :conditions => {:state => 'rejected'} - end + scope :unmoderated, :conditions => {:state => nil} + scope :approved, :conditions => {:state => 'approved'} + scope :rejected, :conditions => {:state => 'rejected'} def approve! self.update_attribute(:state, 'approved') diff --git a/app/models/blog_post.rb b/app/models/blog_post.rb index b965e5d..8937e09 100644 --- a/app/models/blog_post.rb +++ b/app/models/blog_post.rb @@ -10,33 +10,16 @@ class BlogPost < ActiveRecord::Base has_friendly_id :title, :use_slug => true - if Rails.version < '3.0.0' - named_scope :by_archive, lambda { |archive_date| {:conditions => ['published_at between ? and ?', archive_date.beginning_of_month, archive_date.end_of_month], :order => "published_at DESC"} } - else - scope :by_archive, lambda { |archive_date| - where(['published_at between ? and ?', archive_date.beginning_of_month, archive_date.end_of_month]).order("published_at DESC") - } - end + scope :by_archive, lambda { |archive_date| + where(['published_at between ? and ?', archive_date.beginning_of_month, archive_date.end_of_month]).order("published_at DESC") + } - if Rails.version < '3.0.0' - named_scope :all_previous, :conditions => ['published_at <= ?', Time.now.beginning_of_month], :order => "published_at DESC" - else - scope :all_previous, where(['published_at <= ?', Time.now.beginning_of_month]).order("published_at DESC") - end + scope :all_previous, where(['published_at <= ?', Time.now.beginning_of_month]).order("published_at DESC") - if Rails.version < '3.0.0' - named_scope :live, lambda { {:conditions => ["published_at < ? and draft = ?", Time.now, false], :order => "published_at DESC"} } - else - scope :live, lambda { where( "published_at < ? and draft = ?", Time.now, false).order("published_at DESC") } - end + scope :live, lambda { where( "published_at < ? and draft = ?", Time.now, false).order("published_at DESC") } - if Rails.version < '3.0.0' - named_scope :previous, lambda { |i| { :conditions => ["published_at < ?", i.published_at], :order => "published_at DESC", :limit => 1 } } - named_scope :next, lambda { |i| { :condtions => ["published_at > ?", i.published_at], :order => "published_at ASC", :limit => 1 } } - else - scope :previous, lambda { |i| where(["published_at < ?", i.published_at]).order("published_at DESC").limit(1) } - scope :next, lambda { |i| where(["published_at > ?", i.published_at]).order("published_at ASC").limit(1) } - end + scope :previous, lambda { |i| where(["published_at < ?", i.published_at]).order("published_at DESC").limit(1) } + scope :next, lambda { |i| where(["published_at > ?", i.published_at]).order("published_at ASC").limit(1) } def next self.class.next(self).first diff --git a/app/views/admin/blog/categories/_form.html.erb b/app/views/admin/blog/categories/_form.html.erb index 28227ae..4f1809a 100644 --- a/app/views/admin/blog/categories/_form.html.erb +++ b/app/views/admin/blog/categories/_form.html.erb @@ -1,13 +1,9 @@ <% form_for [:admin, @blog_category] do |f| -%> - <% if Rails.version < '3.0.0'%> - <%= f.error_messages %> - <% else %> - <%= render :partial => "/shared/admin/error_messages", - :locals => { - :object => f.object, - :include_object_name => true - } %> - <% end %> + <%= render :partial => "/shared/admin/error_messages", + :locals => { + :object => f.object, + :include_object_name => true + } %> <div class='field'> <%= f.label :title -%> diff --git a/app/views/admin/blog/posts/_form.html.erb b/app/views/admin/blog/posts/_form.html.erb index 5779e4c..29585ea 100644 --- a/app/views/admin/blog/posts/_form.html.erb +++ b/app/views/admin/blog/posts/_form.html.erb @@ -1,13 +1,9 @@ <% form_for [:admin, @blog_post] do |f| -%> - <% if Rails.version < '3.0.0'%> - <%= f.error_messages %> - <% else %> - <%= render :partial => "/shared/admin/error_messages", - :locals => { - :object => f.object, - :include_object_name => true - } %> - <% end %> + <%= render :partial => "/shared/admin/error_messages", + :locals => { + :object => f.object, + :include_object_name => true + } %> <div class='field'> <%= f.label :title -%> diff --git a/app/views/blog/posts/show.html.erb b/app/views/blog/posts/show.html.erb index 72916f3..b6cff8c 100644 --- a/app/views/blog/posts/show.html.erb +++ b/app/views/blog/posts/show.html.erb @@ -23,26 +23,18 @@ <h2><%= t('.comments.add') %></h2> <% form_for [:blog_post, @blog_comment] do |f| %> - <% if Rails.version < '3.0.0'%> - <%= f.error_messages %> - <% else %> - <%= render :partial => "/shared/admin/error_messages", - :locals => { - :object => f.object, - :include_object_name => true - } %> - <% end %> + <%= render :partial => "/shared/admin/error_messages", + :locals => { + :object => f.object, + :include_object_name => true + } %> <div class='field'> <%= f.label :name %> <%= f.text_field :name %> </div> <div class='field'> <%= f.label :email %> - <% if Rails.version > '3.0.0' %> - <%= f.email_field :email %> - <% else %> - <%= f.text_field :email %> - <% end %> + <%= f.email_field :email %> </div> <div class='field message_field'> <%= f.label :message %> diff --git a/config/routes.rb b/config/routes.rb index 2cb4723..20fa1b1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,73 +1,37 @@ -if Rails.version < '3.0.0' - ActionController::Routing::Routes.draw do |map| - map.namespace(:blog) do |blog| - blog.rss_feed 'feed.rss', :controller => 'posts', :action => 'index', :format => 'rss' - blog.root :controller => "posts", :action => 'index' - blog.post ':id', :controller => "posts", :action => 'show' - blog.category 'categories/:id', :controller => "categories", :action => 'show' - blog.post_blog_comments ':id/comments', :controller => 'posts', :action => 'comment' - - ## what is the rails2 syntax for this? sorry ;__; - # get 'archive/:year/:month', :to => 'posts#archive', :as => 'archive_blog_posts' - end - - map.namespace(:admin, :path_prefix => 'refinery') do |admin| - admin.namespace :blog do |blog| - blog.resources :posts - - blog.resources :categories - - blog.resources :comments, :collection => { - :approved => :get, - :rejected => :get - }, :member => { - :approved => :get, - :rejected => :get - } - - blog.resources :settings, :collection => { - :notification_recipients => [:get, :post], - :moderation => :get - } - end - end +Refinery::Application.routes.draw do + scope(:path => 'blog', :module => 'blog') do + root :to => 'posts#index', :as => 'blog_root' + match 'feed.rss', :to => 'posts#index.rss', :as => 'blog_rss_feed' + match ':id', :to => 'posts#show', :as => 'blog_post' + match 'categories/:id', :to => 'categories#show', :as => 'blog_category' + match ':id/comments', :to => 'posts#comment', :as => 'blog_post_blog_comments' + get 'archive/:year/:month', :to => 'posts#archive', :as => 'archive_blog_posts' end -else - Refinery::Application.routes.draw do - scope(:path => 'blog', :module => 'blog') do - root :to => 'posts#index', :as => 'blog_root' - match 'feed.rss', :to => 'posts#index.rss', :as => 'blog_rss_feed' - match ':id', :to => 'posts#show', :as => 'blog_post' - match 'categories/:id', :to => 'categories#show', :as => 'blog_category' - match ':id/comments', :to => 'posts#comment', :as => 'blog_post_blog_comments' - get 'archive/:year/:month', :to => 'posts#archive', :as => 'archive_blog_posts' - end - scope(:path => 'refinery', :as => 'admin', :module => 'admin') do - scope(:path => 'blog', :as => 'blog', :module => 'blog') do - root :to => 'posts#index' - resources :posts + scope(:path => 'refinery', :as => 'admin', :module => 'admin') do + scope(:path => 'blog', :as => 'blog', :module => 'blog') do + root :to => 'posts#index' + resources :posts - resources :categories + resources :categories - resources :comments do - collection do - get :approved - get :rejected - end - member do - get :approved - get :rejected - end + resources :comments do + collection do + get :approved + get :rejected end + member do + get :approved + get :rejected + end + end - resources :settings do - collection do - get :notification_recipients - post :notification_recipients + resources :settings do + collection do + get :notification_recipients + post :notification_recipients - get :moderation - end + get :moderation end end end @@ -1,13 +1,15 @@ -# About +# Refinery CMS Blog Simple blog engine for [Refinery CMS](http://refinerycms.com). It supports posts, categories and comments. +Refinery CMS Blog supports Rails 2.x using the [Rails 2.x stable branch](http://github.com/resolve/refinerycms-blog/tree/rails2-stable). + Options: * Comment moderation * [ShareThis.com](http://sharethis.com) support on posts. Set your key in Refinery's settings area to enable this. -# Install +## Install Open up your ``Gemfile`` and add at the bottom this line @@ -15,11 +17,7 @@ Open up your ``Gemfile`` and add at the bottom this line Now run ``bundle install`` -Next to install the blog plugin run (for Rails 2): - - ruby script/generate refinerycms_blog - -Or, for Rails 3: +Next to install the blog plugin run: rails generate refinerycms_blog |