aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorPhilip Arndt <parndt@gmail.com>2011-07-01 09:14:46 +1200
committerPhilip Arndt <parndt@gmail.com>2011-07-01 09:14:46 +1200
commit7028ef3dddd8559c8e5519431d3529c0c99872cc (patch)
tree6b8aa08e5f8713b85fc1bbf4a2460c001e516822 /app
parent47a71b309f4fb364449167ddc6ed978b6969e047 (diff)
downloadrefinerycms-blog-7028ef3dddd8559c8e5519431d3529c0c99872cc.tar.gz
refinerycms-blog-7028ef3dddd8559c8e5519431d3529c0c99872cc.tar.bz2
refinerycms-blog-7028ef3dddd8559c8e5519431d3529c0c99872cc.zip
Making use of modules and putting classes under modules.
Diffstat (limited to 'app')
-rw-r--r--app/controllers/admin/blog/categories_controller.rb12
-rw-r--r--app/controllers/admin/blog/comments_controller.rb64
-rw-r--r--app/controllers/admin/blog/posts_controller.rb144
-rw-r--r--app/controllers/admin/blog/settings_controller.rb68
-rw-r--r--app/controllers/blog/categories_controller.rb20
-rw-r--r--app/controllers/blog/posts_controller.rb152
-rw-r--r--app/mailers/blog/comment_mailer.rb20
7 files changed, 251 insertions, 229 deletions
diff --git a/app/controllers/admin/blog/categories_controller.rb b/app/controllers/admin/blog/categories_controller.rb
index fe15a0b..6933c44 100644
--- a/app/controllers/admin/blog/categories_controller.rb
+++ b/app/controllers/admin/blog/categories_controller.rb
@@ -1,7 +1,11 @@
-class Admin::Blog::CategoriesController < Admin::BaseController
+module Admin
+ module Blog
+ class CategoriesController < Admin::BaseController
- crudify :blog_category,
- :title_attribute => :title,
- :order => 'title ASC'
+ crudify :blog_category,
+ :title_attribute => :title,
+ :order => 'title ASC'
+ end
+ end
end
diff --git a/app/controllers/admin/blog/comments_controller.rb b/app/controllers/admin/blog/comments_controller.rb
index f07abed..1868206 100644
--- a/app/controllers/admin/blog/comments_controller.rb
+++ b/app/controllers/admin/blog/comments_controller.rb
@@ -1,36 +1,40 @@
-class Admin::Blog::CommentsController < Admin::BaseController
+module Admin
+ module Blog
+ class CommentsController < Admin::BaseController
- crudify :blog_comment,
- :title_attribute => :name,
- :order => 'published_at DESC'
+ crudify :blog_comment,
+ :title_attribute => :name,
+ :order => 'published_at DESC'
- def index
- @blog_comments = BlogComment.unmoderated
- render :action => 'index'
- end
+ def index
+ @blog_comments = BlogComment.unmoderated
+ render :action => 'index'
+ end
- def approved
- unless params[:id].present?
- @blog_comments = BlogComment.approved
- render :action => 'index'
- else
- @blog_comment = BlogComment.find(params[:id])
- @blog_comment.approve!
- flash[:notice] = t('approved', :scope => 'admin.blog.comments', :author => @blog_comment.name)
- redirect_to :action => params[:return_to] || 'index'
- end
- end
+ def approved
+ unless params[:id].present?
+ @blog_comments = BlogComment.approved
+ render :action => 'index'
+ else
+ @blog_comment = BlogComment.find(params[:id])
+ @blog_comment.approve!
+ flash[:notice] = t('approved', :scope => 'admin.blog.comments', :author => @blog_comment.name)
+ redirect_to :action => params[:return_to] || 'index'
+ end
+ end
+
+ def rejected
+ unless params[:id].present?
+ @blog_comments = BlogComment.rejected
+ render :action => 'index'
+ else
+ @blog_comment = BlogComment.find(params[:id])
+ @blog_comment.reject!
+ flash[:notice] = t('rejected', :scope => 'admin.blog.comments', :author => @blog_comment.name)
+ redirect_to :action => params[:return_to] || 'index'
+ end
+ end
- def rejected
- unless params[:id].present?
- @blog_comments = BlogComment.rejected
- render :action => 'index'
- else
- @blog_comment = BlogComment.find(params[:id])
- @blog_comment.reject!
- flash[:notice] = t('rejected', :scope => 'admin.blog.comments', :author => @blog_comment.name)
- redirect_to :action => params[:return_to] || 'index'
end
end
-
-end
+end \ No newline at end of file
diff --git a/app/controllers/admin/blog/posts_controller.rb b/app/controllers/admin/blog/posts_controller.rb
index e180741..dbf13b2 100644
--- a/app/controllers/admin/blog/posts_controller.rb
+++ b/app/controllers/admin/blog/posts_controller.rb
@@ -1,86 +1,90 @@
-class Admin::Blog::PostsController < Admin::BaseController
+module Admin
+ module Blog
+ class PostsController < Admin::BaseController
- crudify :blog_post,
- :title_attribute => :title,
- :order => 'published_at DESC'
+ crudify :blog_post,
+ :title_attribute => :title,
+ :order => 'published_at DESC'
- def uncategorized
- @blog_posts = BlogPost.uncategorized.paginate({
- :page => params[:page],
- :per_page => BlogPost.per_page
- })
- end
+ def uncategorized
+ @blog_posts = BlogPost.uncategorized.paginate({
+ :page => params[:page],
+ :per_page => BlogPost.per_page
+ })
+ end
- def tags
- op = case ActiveRecord::Base.connection.adapter_name.downcase
- when 'postgresql'
- '~*'
- else
- 'LIKE'
- end
- wildcard = case ActiveRecord::Base.connection.adapter_name.downcase
- when 'postgresql'
- '.*'
- else
- '%'
- end
- @tags = BlogPost.tag_counts_on(:tags).where(
- ["tags.name #{op} ?", "#{wildcard}#{params[:term].to_s.downcase}#{wildcard}"]
- ).map { |tag| {:id => tag.id, :value => tag.name}}
- render :json => @tags.flatten
- end
+ def tags
+ op = case ActiveRecord::Base.connection.adapter_name.downcase
+ when 'postgresql'
+ '~*'
+ else
+ 'LIKE'
+ end
+ wildcard = case ActiveRecord::Base.connection.adapter_name.downcase
+ when 'postgresql'
+ '.*'
+ else
+ '%'
+ end
+ @tags = BlogPost.tag_counts_on(:tags).where(
+ ["tags.name #{op} ?", "#{wildcard}#{params[:term].to_s.downcase}#{wildcard}"]
+ ).map { |tag| {:id => tag.id, :value => tag.name}}
+ render :json => @tags.flatten
+ end
- def create
- # if the position field exists, set this object as last object, given the conditions of this class.
- if BlogPost.column_names.include?("position")
- params[:blog_post].merge!({
- :position => ((BlogPost.maximum(:position, :conditions => "")||-1) + 1)
- })
- end
+ def create
+ # if the position field exists, set this object as last object, given the conditions of this class.
+ if BlogPost.column_names.include?("position")
+ params[:blog_post].merge!({
+ :position => ((BlogPost.maximum(:position, :conditions => "")||-1) + 1)
+ })
+ end
- if BlogPost.column_names.include?("user_id")
- params[:blog_post].merge!({
- :user_id => current_user.id
- })
- end
+ if BlogPost.column_names.include?("user_id")
+ params[:blog_post].merge!({
+ :user_id => current_user.id
+ })
+ end
- if (@blog_post = BlogPost.create(params[:blog_post])).valid?
- (request.xhr? ? flash.now : flash).notice = t(
- 'refinery.crudify.created',
- :what => "'#{@blog_post.title}'"
- )
+ if (@blog_post = BlogPost.create(params[:blog_post])).valid?
+ (request.xhr? ? flash.now : flash).notice = t(
+ 'refinery.crudify.created',
+ :what => "'#{@blog_post.title}'"
+ )
- unless from_dialog?
- unless params[:continue_editing] =~ /true|on|1/
- redirect_back_or_default(admin_blog_posts_url)
+ unless from_dialog?
+ unless params[:continue_editing] =~ /true|on|1/
+ redirect_back_or_default(admin_blog_posts_url)
+ else
+ unless request.xhr?
+ redirect_to :back
+ else
+ render :partial => "/shared/message"
+ end
+ end
+ else
+ render :text => "<script>parent.window.location = '#{admin_blog_posts_url}';</script>"
+ end
else
unless request.xhr?
- redirect_to :back
+ render :action => 'new'
else
- render :partial => "/shared/message"
+ render :partial => "/shared/admin/error_messages",
+ :locals => {
+ :object => @blog_post,
+ :include_object_name => true
+ }
end
end
- else
- render :text => "<script>parent.window.location = '#{admin_blog_posts_url}';</script>"
- end
- else
- unless request.xhr?
- render :action => 'new'
- else
- render :partial => "/shared/admin/error_messages",
- :locals => {
- :object => @blog_post,
- :include_object_name => true
- }
end
- end
- end
- before_filter :find_all_categories,
- :only => [:new, :edit, :create, :update]
+ before_filter :find_all_categories,
+ :only => [:new, :edit, :create, :update]
-protected
- def find_all_categories
- @blog_categories = BlogCategory.find(:all)
+ protected
+ def find_all_categories
+ @blog_categories = BlogCategory.find(:all)
+ end
+ end
end
-end
+end \ No newline at end of file
diff --git a/app/controllers/admin/blog/settings_controller.rb b/app/controllers/admin/blog/settings_controller.rb
index eb1eef9..a9b053e 100644
--- a/app/controllers/admin/blog/settings_controller.rb
+++ b/app/controllers/admin/blog/settings_controller.rb
@@ -1,39 +1,43 @@
-class Admin::Blog::SettingsController < Admin::BaseController
+module Admin
+ module Blog
+ class SettingsController < Admin::BaseController
- def notification_recipients
- @recipients = BlogComment::Notification.recipients
+ def notification_recipients
+ @recipients = BlogComment::Notification.recipients
- if request.post?
- BlogComment::Notification.recipients = params[:recipients]
- flash[:notice] = t('updated', :scope => 'admin.blog.settings.notification_recipients'
- :recipients => BlogComment::Notification.recipients)
- unless request.xhr? or from_dialog?
- redirect_back_or_default(admin_blog_posts_path)
- else
- render :text => "<script type='text/javascript'>parent.window.location = '#{admin_blog_posts_path}';</script>",
- :layout => false
+ if request.post?
+ BlogComment::Notification.recipients = params[:recipients]
+ flash[:notice] = t('updated', :scope => 'admin.blog.settings.notification_recipients'
+ :recipients => BlogComment::Notification.recipients)
+ unless request.xhr? or from_dialog?
+ redirect_back_or_default(admin_blog_posts_path)
+ else
+ render :text => "<script type='text/javascript'>parent.window.location = '#{admin_blog_posts_path}';</script>",
+ :layout => false
+ end
+ end
end
- end
- end
- def moderation
- enabled = BlogComment::Moderation.toggle!
- unless request.xhr?
- redirect_back_or_default(admin_blog_posts_path)
- else
- render :json => {:enabled => enabled},
- :layout => false
- end
- end
+ def moderation
+ enabled = BlogComment::Moderation.toggle!
+ unless request.xhr?
+ redirect_back_or_default(admin_blog_posts_path)
+ else
+ render :json => {:enabled => enabled},
+ :layout => false
+ end
+ end
+
+ def comments
+ enabled = BlogComment.toggle!
+ unless request.xhr?
+ redirect_back_or_default(admin_blog_posts_path)
+ else
+ render :json => {:enabled => enabled},
+ :layout => false
+ end
+ end
- def comments
- enabled = BlogComment.toggle!
- unless request.xhr?
- redirect_back_or_default(admin_blog_posts_path)
- else
- render :json => {:enabled => enabled},
- :layout => false
end
end
-
-end
+end \ No newline at end of file
diff --git a/app/controllers/blog/categories_controller.rb b/app/controllers/blog/categories_controller.rb
index 35a87c3..efda778 100644
--- a/app/controllers/blog/categories_controller.rb
+++ b/app/controllers/blog/categories_controller.rb
@@ -1,11 +1,13 @@
-class Blog::CategoriesController < BlogController
+module Blog
+ class CategoriesController < BlogController
- def show
- @category = BlogCategory.find(params[:id])
- @blog_posts = @category.posts.live.includes(:comments, :categories).paginate({
- :page => params[:page],
- :per_page => RefinerySetting.find_or_set(:blog_posts_per_page, 10)
- })
- end
+ def show
+ @category = BlogCategory.find(params[:id])
+ @blog_posts = @category.posts.live.includes(:comments, :categories).paginate({
+ :page => params[:page],
+ :per_page => RefinerySetting.find_or_set(:blog_posts_per_page, 10)
+ })
+ end
-end
+ end
+end \ No newline at end of file
diff --git a/app/controllers/blog/posts_controller.rb b/app/controllers/blog/posts_controller.rb
index fd1cd1b..9dc595c 100644
--- a/app/controllers/blog/posts_controller.rb
+++ b/app/controllers/blog/posts_controller.rb
@@ -1,101 +1,103 @@
-class Blog::PostsController < BlogController
+module Blog
+ class PostsController < BlogController
- before_filter :find_all_blog_posts, :except => [:archive]
- before_filter :find_blog_post, :only => [:show, :comment, :update_nav]
- before_filter :find_tags
+ before_filter :find_all_blog_posts, :except => [:archive]
+ before_filter :find_blog_post, :only => [:show, :comment, :update_nav]
+ before_filter :find_tags
- respond_to :html, :js, :rss
+ respond_to :html, :js, :rss
- def index
- respond_with (@blog_posts) do |format|
- format.html
- format.rss
+ def index
+ respond_with (@blog_posts) do |format|
+ format.html
+ format.rss
+ end
end
- end
- def show
- @blog_comment = BlogComment.new
+ def show
+ @blog_comment = BlogComment.new
- respond_with (@blog_post) do |format|
- format.html { present(@blog_post) }
- format.js { render :partial => 'post', :layout => false }
+ respond_with (@blog_post) do |format|
+ format.html { present(@blog_post) }
+ format.js { render :partial => 'post', :layout => false }
+ end
end
- end
- def comment
- if (@blog_comment = @blog_post.comments.create(params[:blog_comment])).valid?
- if BlogComment::Moderation.enabled? or @blog_comment.ham?
- begin
- Blog::CommentMailer.notification(@blog_comment, request).deliver
- rescue
- logger.warn "There was an error delivering a blog comment notification.\n#{$!}\n"
+ def comment
+ if (@blog_comment = @blog_post.comments.create(params[:blog_comment])).valid?
+ if BlogComment::Moderation.enabled? or @blog_comment.ham?
+ begin
+ Blog::CommentMailer.notification(@blog_comment, request).deliver
+ rescue
+ logger.warn "There was an error delivering a blog comment notification.\n#{$!}\n"
+ end
end
+
+ if BlogComment::Moderation.enabled?
+ flash[:notice] = t('thank_you_moderated', :scope => 'blog.posts.comments')
+ redirect_to blog_post_url(params[:id])
+ else
+ flash[:notice] = t('thank_you', :scope => 'blog.posts.comments')
+ redirect_to blog_post_url(params[:id],
+ :anchor => "comment-#{@blog_comment.to_param}")
+ end
+ else
+ render :action => 'show'
end
+ end
- if BlogComment::Moderation.enabled?
- flash[:notice] = t('thank_you_moderated', :scope => 'blog.posts.comments')
- redirect_to blog_post_url(params[:id])
+ def archive
+ if params[:month].present?
+ date = "#{params[:month]}/#{params[:year]}"
+ @archive_date = Time.parse(date)
+ @date_title = @archive_date.strftime('%B %Y')
+ @blog_posts = BlogPost.live.by_archive(@archive_date).paginate({
+ :page => params[:page],
+ :per_page => RefinerySetting.find_or_set(:blog_posts_per_page, 10)
+ })
else
- flash[:notice] = t('thank_you', :scope => 'blog.posts.comments')
- redirect_to blog_post_url(params[:id],
- :anchor => "comment-#{@blog_comment.to_param}")
+ date = "01/#{params[:year]}"
+ @archive_date = Time.parse(date)
+ @date_title = @archive_date.strftime('%Y')
+ @blog_posts = BlogPost.live.by_year(@archive_date).paginate({
+ :page => params[:page],
+ :per_page => RefinerySetting.find_or_set(:blog_posts_per_page, 10)
+ })
end
- else
- render :action => 'show'
+ respond_with (@blog_posts)
end
- end
- def archive
- if params[:month].present?
- date = "#{params[:month]}/#{params[:year]}"
- @archive_date = Time.parse(date)
- @date_title = @archive_date.strftime('%B %Y')
- @blog_posts = BlogPost.live.by_archive(@archive_date).paginate({
- :page => params[:page],
- :per_page => RefinerySetting.find_or_set(:blog_posts_per_page, 10)
- })
- else
- date = "01/#{params[:year]}"
- @archive_date = Time.parse(date)
- @date_title = @archive_date.strftime('%Y')
- @blog_posts = BlogPost.live.by_year(@archive_date).paginate({
+ def tagged
+ @tag = ActsAsTaggableOn::Tag.find(params[:tag_id])
+ @tag_name = @tag.name
+ @blog_posts = BlogPost.tagged_with(@tag_name).paginate({
:page => params[:page],
:per_page => RefinerySetting.find_or_set(:blog_posts_per_page, 10)
})
end
- respond_with (@blog_posts)
- end
- def tagged
- @tag = ActsAsTaggableOn::Tag.find(params[:tag_id])
- @tag_name = @tag.name
- @blog_posts = BlogPost.tagged_with(@tag_name).paginate({
- :page => params[:page],
- :per_page => RefinerySetting.find_or_set(:blog_posts_per_page, 10)
- })
- end
-
-protected
+ protected
- def find_blog_post
- unless (@blog_post = BlogPost.find(params[:id])).try(:live?)
- if refinery_user? and current_user.authorized_plugins.include?("refinerycms_blog")
- @blog_post = BlogPost.find(params[:id])
- else
- error_404
+ def find_blog_post
+ unless (@blog_post = BlogPost.find(params[:id])).try(:live?)
+ if refinery_user? and current_user.authorized_plugins.include?("refinerycms_blog")
+ @blog_post = BlogPost.find(params[:id])
+ else
+ error_404
+ end
end
end
- end
- def find_all_blog_posts
- @blog_posts = BlogPost.live.includes(:comments, :categories).paginate({
- :page => params[:page],
- :per_page => RefinerySetting.find_or_set(:blog_posts_per_page, 10)
- })
- end
+ def find_all_blog_posts
+ @blog_posts = BlogPost.live.includes(:comments, :categories).paginate({
+ :page => params[:page],
+ :per_page => RefinerySetting.find_or_set(:blog_posts_per_page, 10)
+ })
+ end
- def find_tags
- @tags = BlogPost.tag_counts_on(:tags)
- end
+ def find_tags
+ @tags = BlogPost.tag_counts_on(:tags)
+ end
-end
+ end
+end \ No newline at end of file
diff --git a/app/mailers/blog/comment_mailer.rb b/app/mailers/blog/comment_mailer.rb
index 3e4c76d..3710ea1 100644
--- a/app/mailers/blog/comment_mailer.rb
+++ b/app/mailers/blog/comment_mailer.rb
@@ -1,11 +1,13 @@
-class Blog::CommentMailer < ActionMailer::Base
+module Blog
+ class CommentMailer < ActionMailer::Base
- def notification(comment, request)
- subject BlogComment::Notification.subject
- recipients BlogComment::Notification.recipients
- from "\"#{RefinerySetting[:site_name]}\" <no-reply@#{request.domain(RefinerySetting.find_or_set(:tld_length, 1))}>"
- sent_on Time.now
- @comment = comment
- end
+ def notification(comment, request)
+ subject BlogComment::Notification.subject
+ recipients BlogComment::Notification.recipients
+ from "\"#{RefinerySetting[:site_name]}\" <no-reply@#{request.domain(RefinerySetting.find_or_set(:tld_length, 1))}>"
+ sent_on Time.now
+ @comment = comment
+ end
-end
+ end
+end \ No newline at end of file