Rails 3.1 - wip.
This commit is contained in:
parent
e5db679226
commit
3fa8937b95
51 changed files with 1064 additions and 1036 deletions
|
@ -1,11 +0,0 @@
|
|||
module Admin
|
||||
module Blog
|
||||
class CategoriesController < Admin::BaseController
|
||||
|
||||
crudify :blog_category,
|
||||
:title_attribute => :title,
|
||||
:order => 'title ASC'
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,40 +0,0 @@
|
|||
module Admin
|
||||
module Blog
|
||||
class CommentsController < Admin::BaseController
|
||||
|
||||
crudify :blog_comment,
|
||||
:title_attribute => :name,
|
||||
:order => 'published_at DESC'
|
||||
|
||||
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 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
|
||||
end
|
|
@ -1,97 +0,0 @@
|
|||
module Admin
|
||||
module Blog
|
||||
class PostsController < Admin::BaseController
|
||||
|
||||
|
||||
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 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
|
||||
|
||||
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}'"
|
||||
)
|
||||
|
||||
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?
|
||||
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 :check_category_ids, :only => :update
|
||||
|
||||
protected
|
||||
def find_all_categories
|
||||
@blog_categories = BlogCategory.find(:all)
|
||||
end
|
||||
|
||||
def check_category_ids
|
||||
params[:blog_post][:category_ids] ||= []
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,53 +0,0 @@
|
|||
module Admin
|
||||
module Blog
|
||||
class SettingsController < Admin::BaseController
|
||||
|
||||
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
|
||||
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 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 teasers
|
||||
enabled = BlogPost.teaser_enabled_toggle!
|
||||
unless request.xhr?
|
||||
redirect_back_or_default(admin_blog_posts_path)
|
||||
else
|
||||
render :json => {:enabled => enabled},
|
||||
:layout => false
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,13 +0,0 @@
|
|||
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
|
||||
|
||||
end
|
||||
end
|
|
@ -1,105 +0,0 @@
|
|||
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
|
||||
|
||||
respond_to :html, :js, :rss
|
||||
|
||||
def index
|
||||
# Rss feeders are greedy. Let's give them every blog post instead of paginating.
|
||||
(@blog_posts = BlogPost.live.includes(:comments, :categories).all) if request.format.rss?
|
||||
respond_with (@blog_posts) do |format|
|
||||
format.html
|
||||
format.rss
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@blog_comment = BlogComment.new
|
||||
|
||||
respond_with (@blog_post) do |format|
|
||||
format.html { present(@blog_post) }
|
||||
format.js { render :partial => 'post', :layout => false }
|
||||
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"
|
||||
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
|
||||
|
||||
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({
|
||||
: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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
end
|
||||
end
|
|
@ -1,16 +0,0 @@
|
|||
class BlogController < ApplicationController
|
||||
|
||||
helper :blog_posts
|
||||
before_filter :find_page, :find_all_blog_categories
|
||||
|
||||
protected
|
||||
|
||||
def find_page
|
||||
@page = Page.find_by_link_url("/blog")
|
||||
end
|
||||
|
||||
def find_all_blog_categories
|
||||
@blog_categories = BlogCategory.all
|
||||
end
|
||||
|
||||
end
|
13
app/controllers/refinery/admin/blog/categories_controller.rb
Normal file
13
app/controllers/refinery/admin/blog/categories_controller.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
module Refinery
|
||||
module Admin
|
||||
module Blog
|
||||
class CategoriesController < ::Admin::BaseController
|
||||
|
||||
crudify :'refinery/blog_category',
|
||||
:title_attribute => :title,
|
||||
:order => 'title ASC'
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
42
app/controllers/refinery/admin/blog/comments_controller.rb
Normal file
42
app/controllers/refinery/admin/blog/comments_controller.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
module Refinery
|
||||
module Admin
|
||||
module Blog
|
||||
class CommentsController < ::Admin::BaseController
|
||||
|
||||
crudify :'refinery/blog_comment',
|
||||
:title_attribute => :name,
|
||||
:order => 'published_at DESC'
|
||||
|
||||
def index
|
||||
@blog_comments = Refinery::BlogComment.unmoderated
|
||||
render :action => 'index'
|
||||
end
|
||||
|
||||
def approved
|
||||
unless params[:id].present?
|
||||
@blog_comments = Refinery::BlogComment.approved
|
||||
render :action => 'index'
|
||||
else
|
||||
@blog_comment = Refinery::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 = Refinery::BlogComment.rejected
|
||||
render :action => 'index'
|
||||
else
|
||||
@blog_comment = Refinery::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
|
||||
end
|
||||
end
|
99
app/controllers/refinery/admin/blog/posts_controller.rb
Normal file
99
app/controllers/refinery/admin/blog/posts_controller.rb
Normal file
|
@ -0,0 +1,99 @@
|
|||
module Refinery
|
||||
module Admin
|
||||
module Blog
|
||||
class PostsController < ::Admin::BaseController
|
||||
|
||||
|
||||
crudify :'refinery/blog_post',
|
||||
:title_attribute => :title,
|
||||
:order => 'published_at DESC'
|
||||
|
||||
def uncategorized
|
||||
@blog_posts = Refinery::BlogPost.uncategorized.paginate({
|
||||
:page => params[:page],
|
||||
:per_page => Refinery::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 = Refinery::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 Refinery::BlogPost.column_names.include?("position")
|
||||
params[:blog_post].merge!({
|
||||
:position => ((Refinery::BlogPost.maximum(:position, :conditions => "")||-1) + 1)
|
||||
})
|
||||
end
|
||||
|
||||
if Refinery::BlogPost.column_names.include?("user_id")
|
||||
params[:blog_post].merge!({
|
||||
:user_id => current_user.id
|
||||
})
|
||||
end
|
||||
|
||||
if (@blog_post = Refinery::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)
|
||||
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?
|
||||
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 :check_category_ids, :only => :update
|
||||
|
||||
protected
|
||||
def find_all_categories
|
||||
@blog_categories = Refinery::BlogCategory.find(:all)
|
||||
end
|
||||
|
||||
def check_category_ids
|
||||
params[:blog_post][:category_ids] ||= []
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
55
app/controllers/refinery/admin/blog/settings_controller.rb
Normal file
55
app/controllers/refinery/admin/blog/settings_controller.rb
Normal file
|
@ -0,0 +1,55 @@
|
|||
module Refinery
|
||||
module Admin
|
||||
module Blog
|
||||
class SettingsController < ::Admin::BaseController
|
||||
|
||||
def notification_recipients
|
||||
@recipients = Refinery::BlogComment::Notification.recipients
|
||||
|
||||
if request.post?
|
||||
Refinery::BlogComment::Notification.recipients = params[:recipients]
|
||||
flash[:notice] = t('updated', :scope => 'admin.blog.settings.notification_recipients',
|
||||
:recipients => Refinery::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
|
||||
|
||||
def moderation
|
||||
enabled = Refinery::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 = Refinery::BlogComment.toggle!
|
||||
unless request.xhr?
|
||||
redirect_back_or_default(admin_blog_posts_path)
|
||||
else
|
||||
render :json => {:enabled => enabled},
|
||||
:layout => false
|
||||
end
|
||||
end
|
||||
|
||||
def teasers
|
||||
enabled = Refinery::BlogPost.teaser_enabled_toggle!
|
||||
unless request.xhr?
|
||||
redirect_back_or_default(admin_blog_posts_path)
|
||||
else
|
||||
render :json => {:enabled => enabled},
|
||||
:layout => false
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
15
app/controllers/refinery/blog/categories_controller.rb
Normal file
15
app/controllers/refinery/blog/categories_controller.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
module Refinery
|
||||
module Blog
|
||||
class CategoriesController < BlogController
|
||||
|
||||
def show
|
||||
@category = Refinery::BlogCategory.find(params[:id])
|
||||
@blog_posts = @category.posts.live.includes(:comments, :categories).paginate({
|
||||
:page => params[:page],
|
||||
:per_page => Refinery::Setting.find_or_set(:blog_posts_per_page, 10)
|
||||
})
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
107
app/controllers/refinery/blog/posts_controller.rb
Normal file
107
app/controllers/refinery/blog/posts_controller.rb
Normal file
|
@ -0,0 +1,107 @@
|
|||
module Refinery
|
||||
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
|
||||
|
||||
respond_to :html, :js, :rss
|
||||
|
||||
def index
|
||||
# Rss feeders are greedy. Let's give them every blog post instead of paginating.
|
||||
(@blog_posts = Refinery::BlogPost.live.includes(:comments, :categories).all) if request.format.rss?
|
||||
respond_with (@blog_posts) do |format|
|
||||
format.html
|
||||
format.rss
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@blog_comment = Refinery::BlogComment.new
|
||||
|
||||
respond_with (@blog_post) do |format|
|
||||
format.html { present(@blog_post) }
|
||||
format.js { render :partial => 'post', :layout => false }
|
||||
end
|
||||
end
|
||||
|
||||
def comment
|
||||
if (@blog_comment = @blog_post.comments.create(params[:blog_comment])).valid?
|
||||
if Refinery::BlogComment::Moderation.enabled? or @blog_comment.ham?
|
||||
begin
|
||||
Refinery::Blog::CommentMailer.notification(@blog_comment, request).deliver
|
||||
rescue
|
||||
logger.warn "There was an error delivering a blog comment notification.\n#{$!}\n"
|
||||
end
|
||||
end
|
||||
|
||||
if Refinery::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
|
||||
|
||||
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 => Refinery::Setting.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 = Refinery::live.by_year(@archive_date).paginate({
|
||||
:page => params[:page],
|
||||
:per_page => Refinery::Setting.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 = Refinery::BlogPost.tagged_with(@tag_name).paginate({
|
||||
:page => params[:page],
|
||||
:per_page => Refinery::Setting.find_or_set(:blog_posts_per_page, 10)
|
||||
})
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def find_blog_post
|
||||
unless (@blog_post = Refinery::BlogPost.find(params[:id])).try(:live?)
|
||||
if refinery_user? and current_user.authorized_plugins.include?("refinerycms_blog")
|
||||
@blog_post = Refinery::BlogPost.find(params[:id])
|
||||
else
|
||||
error_404
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def find_all_blog_posts
|
||||
@blog_posts = Refinery::BlogPost.live.includes(:comments, :categories).paginate({
|
||||
:page => params[:page],
|
||||
:per_page => Refinery::Setting.find_or_set(:blog_posts_per_page, 10)
|
||||
})
|
||||
end
|
||||
|
||||
def find_tags
|
||||
@tags = Refinery::BlogPost.tag_counts_on(:tags)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
18
app/controllers/refinery/blog_controller.rb
Normal file
18
app/controllers/refinery/blog_controller.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
module Refinery
|
||||
class BlogController < ::ApplicationController
|
||||
|
||||
helper :blog_posts
|
||||
before_filter :find_page, :find_all_blog_categories
|
||||
|
||||
protected
|
||||
|
||||
def find_page
|
||||
@page = Refinery::Page.find_by_link_url("/blog")
|
||||
end
|
||||
|
||||
def find_all_blog_categories
|
||||
@blog_categories = Refinery::BlogCategory.all
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -1,13 +0,0 @@
|
|||
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
|
||||
|
||||
end
|
||||
end
|
15
app/mailers/refinery/blog/comment_mailer.rb
Normal file
15
app/mailers/refinery/blog/comment_mailer.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
module Refinery
|
||||
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
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1 +0,0 @@
|
|||
require File.expand_path('../../../mailers/blog/comment_mailer', __FILE__)
|
|
@ -1,19 +0,0 @@
|
|||
class BlogCategory < ActiveRecord::Base
|
||||
|
||||
has_many :categorizations, :dependent => :destroy
|
||||
has_many :posts, :through => :categorizations, :source => :blog_post
|
||||
|
||||
acts_as_indexed :fields => [:title]
|
||||
|
||||
validates :title, :presence => true, :uniqueness => true
|
||||
|
||||
has_friendly_id :title, :use_slug => true,
|
||||
:default_locale => (::Refinery::I18n.default_frontend_locale rescue :en),
|
||||
:approximate_ascii => RefinerySetting.find_or_set(:approximate_ascii, false, :scoping => 'blog'),
|
||||
:strip_non_ascii => RefinerySetting.find_or_set(:strip_non_ascii, false, :scoping => 'blog')
|
||||
|
||||
def post_count
|
||||
posts.select(&:live?).count
|
||||
end
|
||||
|
||||
end
|
|
@ -1,131 +0,0 @@
|
|||
class BlogComment < ActiveRecord::Base
|
||||
|
||||
attr_accessible :name, :email, :message
|
||||
|
||||
filters_spam :author_field => :name,
|
||||
:email_field => :email,
|
||||
:message_field => :body
|
||||
|
||||
belongs_to :post, :class_name => 'BlogPost', :foreign_key => 'blog_post_id'
|
||||
|
||||
acts_as_indexed :fields => [:name, :email, :message]
|
||||
|
||||
alias_attribute :message, :body
|
||||
|
||||
validates :name, :message, :presence => true
|
||||
validates :email, :format => { :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i }
|
||||
|
||||
scope :unmoderated, :conditions => {:state => nil}
|
||||
scope :approved, :conditions => {:state => 'approved'}
|
||||
scope :rejected, :conditions => {:state => 'rejected'}
|
||||
|
||||
def avatar_url(options = {})
|
||||
options = {:size => 60}
|
||||
require 'digest/md5'
|
||||
size = ("?s=#{options[:size]}" if options[:size])
|
||||
"http://gravatar.com/avatar/#{Digest::MD5.hexdigest(self.email.to_s.strip.downcase)}#{size}.jpg"
|
||||
end
|
||||
|
||||
def approve!
|
||||
self.update_attribute(:state, 'approved')
|
||||
end
|
||||
|
||||
def reject!
|
||||
self.update_attribute(:state, 'rejected')
|
||||
end
|
||||
|
||||
def rejected?
|
||||
self.state == 'rejected'
|
||||
end
|
||||
|
||||
def approved?
|
||||
self.state == 'approved'
|
||||
end
|
||||
|
||||
def unmoderated?
|
||||
self.state.nil?
|
||||
end
|
||||
|
||||
def self.toggle!
|
||||
currently = RefinerySetting.find_or_set(:comments_allowed, true, {
|
||||
:scoping => 'blog'
|
||||
})
|
||||
RefinerySetting.set(:comments_allowed, {:value => !currently, :scoping => 'blog'})
|
||||
end
|
||||
|
||||
before_create do |comment|
|
||||
unless BlogComment::Moderation.enabled?
|
||||
comment.state = comment.ham? ? 'approved' : 'rejected'
|
||||
end
|
||||
end
|
||||
|
||||
module Moderation
|
||||
class << self
|
||||
def enabled?
|
||||
RefinerySetting.find_or_set(:comment_moderation, true, {
|
||||
:scoping => 'blog',
|
||||
:restricted => false
|
||||
})
|
||||
end
|
||||
|
||||
def toggle!
|
||||
new_value = {
|
||||
:value => !BlogComment::Moderation.enabled?,
|
||||
:scoping => 'blog',
|
||||
:restricted => false
|
||||
}
|
||||
if RefinerySetting.respond_to?(:set)
|
||||
RefinerySetting.set(:comment_moderation, new_value)
|
||||
else
|
||||
RefinerySetting[:comment_moderation] = new_value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module Notification
|
||||
class << self
|
||||
def recipients
|
||||
RefinerySetting.find_or_set(:comment_notification_recipients, (Role[:refinery].users.first.email rescue ''),
|
||||
{
|
||||
:scoping => 'blog',
|
||||
:restricted => false
|
||||
})
|
||||
end
|
||||
|
||||
def recipients=(emails)
|
||||
new_value = {
|
||||
:value => emails,
|
||||
:scoping => 'blog',
|
||||
:restricted => false
|
||||
}
|
||||
if RefinerySetting.respond_to?(:set)
|
||||
RefinerySetting.set(:comment_notification_recipients, new_value)
|
||||
else
|
||||
RefinerySetting[:comment_notification_recipients] = new_value
|
||||
end
|
||||
end
|
||||
|
||||
def subject
|
||||
RefinerySetting.find_or_set(:comment_notification_subject, "New inquiry from your website", {
|
||||
:scoping => 'blog',
|
||||
:restricted => false
|
||||
})
|
||||
end
|
||||
|
||||
def subject=(subject_line)
|
||||
new_value = {
|
||||
:value => subject_line,
|
||||
:scoping => 'blog',
|
||||
:restricted => false
|
||||
}
|
||||
if RefinerySetting.respond_to?(:set)
|
||||
RefinerySetting.set(:comment_notification_subject, new_value)
|
||||
else
|
||||
RefinerySetting[:comment_notification_subject] = new_value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,114 +0,0 @@
|
|||
require 'acts-as-taggable-on'
|
||||
require 'seo_meta'
|
||||
|
||||
class BlogPost < ActiveRecord::Base
|
||||
|
||||
is_seo_meta if self.table_exists?
|
||||
|
||||
default_scope :order => 'published_at DESC'
|
||||
#.first & .last will be reversed -- consider a with_exclusive_scope on these?
|
||||
|
||||
belongs_to :author, :class_name => 'User', :foreign_key => :user_id, :readonly => true
|
||||
|
||||
has_many :comments, :class_name => 'BlogComment', :dependent => :destroy
|
||||
acts_as_taggable
|
||||
|
||||
has_many :categorizations, :dependent => :destroy
|
||||
has_many :categories, :through => :categorizations, :source => :blog_category
|
||||
|
||||
acts_as_indexed :fields => [:title, :body]
|
||||
|
||||
validates :title, :presence => true, :uniqueness => true
|
||||
validates :body, :presence => true
|
||||
|
||||
has_friendly_id :friendly_id_source, :use_slug => true,
|
||||
:default_locale => (::Refinery::I18n.default_frontend_locale rescue :en),
|
||||
:approximate_ascii => RefinerySetting.find_or_set(:approximate_ascii, false, :scoping => 'blog'),
|
||||
:strip_non_ascii => RefinerySetting.find_or_set(:strip_non_ascii, false, :scoping => 'blog')
|
||||
|
||||
scope :by_archive, lambda { |archive_date|
|
||||
where(['published_at between ? and ?', archive_date.beginning_of_month, archive_date.end_of_month])
|
||||
}
|
||||
|
||||
scope :by_year, lambda { |archive_year|
|
||||
where(['published_at between ? and ?', archive_year.beginning_of_year, archive_year.end_of_year])
|
||||
}
|
||||
|
||||
scope :all_previous, lambda { where(['published_at <= ?', Time.now.beginning_of_month]) }
|
||||
|
||||
scope :live, lambda { where( "published_at <= ? and draft = ?", Time.now, false) }
|
||||
|
||||
scope :previous, lambda { |i| where(["published_at < ? and draft = ?", i.published_at, false]).limit(1) }
|
||||
# next is now in << self
|
||||
|
||||
def next
|
||||
BlogPost.next(self).first
|
||||
end
|
||||
|
||||
def prev
|
||||
BlogPost.previous(self).first
|
||||
end
|
||||
|
||||
def live?
|
||||
!draft and published_at <= Time.now
|
||||
end
|
||||
|
||||
def category_ids=(ids)
|
||||
self.categories = ids.reject{|id| id.blank?}.collect {|c_id|
|
||||
BlogCategory.find(c_id.to_i) rescue nil
|
||||
}.compact
|
||||
end
|
||||
|
||||
def friendly_id_source
|
||||
custom_url.present? ? custom_url : title
|
||||
end
|
||||
|
||||
class << self
|
||||
def next current_record
|
||||
self.send(:with_exclusive_scope) do
|
||||
where(["published_at > ? and draft = ?", current_record.published_at, false]).order("published_at ASC")
|
||||
end
|
||||
end
|
||||
|
||||
def comments_allowed?
|
||||
RefinerySetting.find_or_set(:comments_allowed, true, {
|
||||
:scoping => 'blog'
|
||||
})
|
||||
end
|
||||
|
||||
def teasers_enabled?
|
||||
RefinerySetting.find_or_set(:teasers_enabled, true, {
|
||||
:scoping => 'blog'
|
||||
})
|
||||
end
|
||||
|
||||
def teaser_enabled_toggle!
|
||||
currently = RefinerySetting.find_or_set(:teasers_enabled, true, {
|
||||
:scoping => 'blog'
|
||||
})
|
||||
RefinerySetting.set(:teasers_enabled, {:value => !currently, :scoping => 'blog'})
|
||||
end
|
||||
|
||||
def uncategorized
|
||||
BlogPost.live.reject { |p| p.categories.any? }
|
||||
end
|
||||
end
|
||||
|
||||
module ShareThis
|
||||
DEFAULT_KEY = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
||||
|
||||
class << self
|
||||
def key
|
||||
RefinerySetting.find_or_set(:share_this_key, BlogPost::ShareThis::DEFAULT_KEY, {
|
||||
:scoping => 'blog'
|
||||
})
|
||||
end
|
||||
|
||||
def enabled?
|
||||
key = BlogPost::ShareThis.key
|
||||
key.present? and key != BlogPost::ShareThis::DEFAULT_KEY
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,7 +0,0 @@
|
|||
class Categorization < ActiveRecord::Base
|
||||
|
||||
set_table_name 'blog_categories_blog_posts'
|
||||
belongs_to :blog_post
|
||||
belongs_to :blog_category
|
||||
|
||||
end
|
1
app/models/refinery/blog/comment_mailer.rb
Normal file
1
app/models/refinery/blog/comment_mailer.rb
Normal file
|
@ -0,0 +1 @@
|
|||
require File.expand_path('../../../../mailers/refinery/blog/comment_mailer', __FILE__)
|
21
app/models/refinery/blog_category.rb
Normal file
21
app/models/refinery/blog_category.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
module Refinery
|
||||
class BlogCategory < ActiveRecord::Base
|
||||
|
||||
has_many :categorizations, :dependent => :destroy
|
||||
has_many :posts, :through => :categorizations, :source => :blog_post
|
||||
|
||||
acts_as_indexed :fields => [:title]
|
||||
|
||||
validates :title, :presence => true, :uniqueness => true
|
||||
|
||||
has_friendly_id :title, :use_slug => true,
|
||||
:default_locale => (::Refinery::I18n.default_frontend_locale rescue :en),
|
||||
:approximate_ascii => Refinery::Setting.find_or_set(:approximate_ascii, false, :scoping => 'blog'),
|
||||
:strip_non_ascii => Refinery::Setting.find_or_set(:strip_non_ascii, false, :scoping => 'blog')
|
||||
|
||||
def post_count
|
||||
posts.select(&:live?).count
|
||||
end
|
||||
|
||||
end
|
||||
end
|
133
app/models/refinery/blog_comment.rb
Normal file
133
app/models/refinery/blog_comment.rb
Normal file
|
@ -0,0 +1,133 @@
|
|||
module Refinery
|
||||
class BlogComment < ActiveRecord::Base
|
||||
|
||||
attr_accessible :name, :email, :message
|
||||
|
||||
filters_spam :author_field => :name,
|
||||
:email_field => :email,
|
||||
:message_field => :body
|
||||
|
||||
belongs_to :post, :class_name => 'Refinery::BlogPost', :foreign_key => 'blog_post_id'
|
||||
|
||||
acts_as_indexed :fields => [:name, :email, :message]
|
||||
|
||||
alias_attribute :message, :body
|
||||
|
||||
validates :name, :message, :presence => true
|
||||
validates :email, :format => { :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i }
|
||||
|
||||
scope :unmoderated, :conditions => {:state => nil}
|
||||
scope :approved, :conditions => {:state => 'approved'}
|
||||
scope :rejected, :conditions => {:state => 'rejected'}
|
||||
|
||||
def avatar_url(options = {})
|
||||
options = {:size => 60}
|
||||
require 'digest/md5'
|
||||
size = ("?s=#{options[:size]}" if options[:size])
|
||||
"http://gravatar.com/avatar/#{Digest::MD5.hexdigest(self.email.to_s.strip.downcase)}#{size}.jpg"
|
||||
end
|
||||
|
||||
def approve!
|
||||
self.update_attribute(:state, 'approved')
|
||||
end
|
||||
|
||||
def reject!
|
||||
self.update_attribute(:state, 'rejected')
|
||||
end
|
||||
|
||||
def rejected?
|
||||
self.state == 'rejected'
|
||||
end
|
||||
|
||||
def approved?
|
||||
self.state == 'approved'
|
||||
end
|
||||
|
||||
def unmoderated?
|
||||
self.state.nil?
|
||||
end
|
||||
|
||||
def self.toggle!
|
||||
currently = Refinery::Setting.find_or_set(:comments_allowed, true, {
|
||||
:scoping => 'blog'
|
||||
})
|
||||
Refinery::Setting.set(:comments_allowed, {:value => !currently, :scoping => 'blog'})
|
||||
end
|
||||
|
||||
before_create do |comment|
|
||||
unless BlogComment::Moderation.enabled?
|
||||
comment.state = comment.ham? ? 'approved' : 'rejected'
|
||||
end
|
||||
end
|
||||
|
||||
module Moderation
|
||||
class << self
|
||||
def enabled?
|
||||
Refinery::Setting.find_or_set(:comment_moderation, true, {
|
||||
:scoping => 'blog',
|
||||
:restricted => false
|
||||
})
|
||||
end
|
||||
|
||||
def toggle!
|
||||
new_value = {
|
||||
:value => !BlogComment::Moderation.enabled?,
|
||||
:scoping => 'blog',
|
||||
:restricted => false
|
||||
}
|
||||
if Refinery::Setting.respond_to?(:set)
|
||||
Refinery::Setting.set(:comment_moderation, new_value)
|
||||
else
|
||||
Refinery::Setting[:comment_moderation] = new_value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module Notification
|
||||
class << self
|
||||
def recipients
|
||||
Refinery::Setting.find_or_set(:comment_notification_recipients, (Refinery::Role[:refinery].users.first.email rescue ''),
|
||||
{
|
||||
:scoping => 'blog',
|
||||
:restricted => false
|
||||
})
|
||||
end
|
||||
|
||||
def recipients=(emails)
|
||||
new_value = {
|
||||
:value => emails,
|
||||
:scoping => 'blog',
|
||||
:restricted => false
|
||||
}
|
||||
if Refinery::Setting.respond_to?(:set)
|
||||
Refinery::Setting.set(:comment_notification_recipients, new_value)
|
||||
else
|
||||
Refinery::Setting[:comment_notification_recipients] = new_value
|
||||
end
|
||||
end
|
||||
|
||||
def subject
|
||||
Refinery::Setting.find_or_set(:comment_notification_subject, "New inquiry from your website", {
|
||||
:scoping => 'blog',
|
||||
:restricted => false
|
||||
})
|
||||
end
|
||||
|
||||
def subject=(subject_line)
|
||||
new_value = {
|
||||
:value => subject_line,
|
||||
:scoping => 'blog',
|
||||
:restricted => false
|
||||
}
|
||||
if Refinery::Setting.respond_to?(:set)
|
||||
Refinery::Setting.set(:comment_notification_subject, new_value)
|
||||
else
|
||||
Refinery::Setting[:comment_notification_subject] = new_value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
116
app/models/refinery/blog_post.rb
Normal file
116
app/models/refinery/blog_post.rb
Normal file
|
@ -0,0 +1,116 @@
|
|||
require 'acts-as-taggable-on'
|
||||
require 'seo_meta'
|
||||
|
||||
module Refinery
|
||||
class BlogPost < ActiveRecord::Base
|
||||
|
||||
is_seo_meta if self.table_exists?
|
||||
|
||||
default_scope :order => 'published_at DESC'
|
||||
#.first & .last will be reversed -- consider a with_exclusive_scope on these?
|
||||
|
||||
belongs_to :author, :class_name => 'Refinery::User', :foreign_key => :user_id, :readonly => true
|
||||
|
||||
has_many :comments, :class_name => 'Refinery::BlogComment', :dependent => :destroy
|
||||
acts_as_taggable
|
||||
|
||||
has_many :categorizations, :dependent => :destroy
|
||||
has_many :categories, :through => :categorizations, :source => :blog_category
|
||||
|
||||
acts_as_indexed :fields => [:title, :body]
|
||||
|
||||
validates :title, :presence => true, :uniqueness => true
|
||||
validates :body, :presence => true
|
||||
|
||||
has_friendly_id :friendly_id_source, :use_slug => true,
|
||||
:default_locale => (::Refinery::I18n.default_frontend_locale rescue :en),
|
||||
:approximate_ascii => Refinery::Setting.find_or_set(:approximate_ascii, false, :scoping => 'blog'),
|
||||
:strip_non_ascii => Refinery::Setting.find_or_set(:strip_non_ascii, false, :scoping => 'blog')
|
||||
|
||||
scope :by_archive, lambda { |archive_date|
|
||||
where(['published_at between ? and ?', archive_date.beginning_of_month, archive_date.end_of_month])
|
||||
}
|
||||
|
||||
scope :by_year, lambda { |archive_year|
|
||||
where(['published_at between ? and ?', archive_year.beginning_of_year, archive_year.end_of_year])
|
||||
}
|
||||
|
||||
scope :all_previous, lambda { where(['published_at <= ?', Time.now.beginning_of_month]) }
|
||||
|
||||
scope :live, lambda { where( "published_at <= ? and draft = ?", Time.now, false) }
|
||||
|
||||
scope :previous, lambda { |i| where(["published_at < ? and draft = ?", i.published_at, false]).limit(1) }
|
||||
# next is now in << self
|
||||
|
||||
def next
|
||||
BlogPost.next(self).first
|
||||
end
|
||||
|
||||
def prev
|
||||
BlogPost.previous(self).first
|
||||
end
|
||||
|
||||
def live?
|
||||
!draft and published_at <= Time.now
|
||||
end
|
||||
|
||||
def category_ids=(ids)
|
||||
self.categories = ids.reject{|id| id.blank?}.collect {|c_id|
|
||||
Refinery::BlogCategory.find(c_id.to_i) rescue nil
|
||||
}.compact
|
||||
end
|
||||
|
||||
def friendly_id_source
|
||||
custom_url.present? ? custom_url : title
|
||||
end
|
||||
|
||||
class << self
|
||||
def next current_record
|
||||
self.send(:with_exclusive_scope) do
|
||||
where(["published_at > ? and draft = ?", current_record.published_at, false]).order("published_at ASC")
|
||||
end
|
||||
end
|
||||
|
||||
def comments_allowed?
|
||||
Refinery::Setting.find_or_set(:comments_allowed, true, {
|
||||
:scoping => 'blog'
|
||||
})
|
||||
end
|
||||
|
||||
def teasers_enabled?
|
||||
Refinery::Setting.find_or_set(:teasers_enabled, true, {
|
||||
:scoping => 'blog'
|
||||
})
|
||||
end
|
||||
|
||||
def teaser_enabled_toggle!
|
||||
currently = Refinery::Setting.find_or_set(:teasers_enabled, true, {
|
||||
:scoping => 'blog'
|
||||
})
|
||||
Refinery::Setting.set(:teasers_enabled, {:value => !currently, :scoping => 'blog'})
|
||||
end
|
||||
|
||||
def uncategorized
|
||||
BlogPost.live.reject { |p| p.categories.any? }
|
||||
end
|
||||
end
|
||||
|
||||
module ShareThis
|
||||
DEFAULT_KEY = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
||||
|
||||
class << self
|
||||
def key
|
||||
Refinery::Setting.find_or_set(:share_this_key, BlogPost::ShareThis::DEFAULT_KEY, {
|
||||
:scoping => 'blog'
|
||||
})
|
||||
end
|
||||
|
||||
def enabled?
|
||||
key = BlogPost::ShareThis.key
|
||||
key.present? and key != BlogPost::ShareThis::DEFAULT_KEY
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
9
app/models/refinery/categorization.rb
Normal file
9
app/models/refinery/categorization.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
module Refinery
|
||||
class Categorization < ActiveRecord::Base
|
||||
|
||||
set_table_name 'refinery_blog_categories_blog_posts'
|
||||
belongs_to :blog_post
|
||||
belongs_to :blog_category
|
||||
|
||||
end
|
||||
end
|
|
@ -1,45 +1,47 @@
|
|||
::Refinery::Application.routes.draw do
|
||||
scope(:path => 'blog', :module => 'blog') do
|
||||
root :to => 'posts#index', :as => 'blog_root'
|
||||
match 'feed.rss', :to => 'posts#index', :as => 'blog_rss_feed', :defaults => {:format => "rss"}
|
||||
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'
|
||||
get 'tagged/:tag_id(/:tag_name)' => 'posts#tagged', :as => 'tagged_posts'
|
||||
end
|
||||
scope(:module => 'refinery') do
|
||||
scope(:path => 'blog', :module => 'blog') do
|
||||
root :to => 'posts#index', :as => 'blog_root'
|
||||
match 'feed.rss', :to => 'posts#index', :as => 'blog_rss_feed', :defaults => {:format => "rss"}
|
||||
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'
|
||||
get 'tagged/:tag_id(/:tag_name)' => 'posts#tagged', :as => 'tagged_posts'
|
||||
end
|
||||
|
||||
scope(:path => 'refinery', :as => 'admin', :module => 'admin') do
|
||||
scope(:path => 'blog', :as => 'blog', :module => 'blog') do
|
||||
root :to => 'posts#index'
|
||||
resources :posts do
|
||||
collection do
|
||||
get :uncategorized
|
||||
get :tags
|
||||
scope(:path => 'refinery', :as => 'refinery_admin', :module => 'admin') do
|
||||
scope(:path => 'blog', :as => 'blog', :module => 'blog') do
|
||||
root :to => 'posts#index'
|
||||
resources :posts do
|
||||
collection do
|
||||
get :uncategorized
|
||||
get :tags
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
resources :categories
|
||||
resources :categories
|
||||
|
||||
resources :comments do
|
||||
collection do
|
||||
get :approved
|
||||
get :rejected
|
||||
resources :comments do
|
||||
collection do
|
||||
get :approved
|
||||
get :rejected
|
||||
end
|
||||
member do
|
||||
get :approved
|
||||
get :rejected
|
||||
end
|
||||
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
|
||||
get :comments
|
||||
get :teasers
|
||||
get :moderation
|
||||
get :comments
|
||||
get :teasers
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class CreateBlogStructure < ActiveRecord::Migration
|
||||
|
||||
def self.up
|
||||
create_table :blog_posts, :id => true do |t|
|
||||
def up
|
||||
create_table Refinery::BlogPost.table_name, :id => true do |t|
|
||||
t.string :title
|
||||
t.text :body
|
||||
t.boolean :draft
|
||||
|
@ -9,9 +9,9 @@ class CreateBlogStructure < ActiveRecord::Migration
|
|||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :blog_posts, :id
|
||||
add_index Refinery::BlogPost.table_name, :id
|
||||
|
||||
create_table :blog_comments, :id => true do |t|
|
||||
create_table Refinery::BlogComment.table_name, :id => true do |t|
|
||||
t.integer :blog_post_id
|
||||
t.boolean :spam
|
||||
t.string :name
|
||||
|
@ -21,34 +21,34 @@ class CreateBlogStructure < ActiveRecord::Migration
|
|||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :blog_comments, :id
|
||||
add_index Refinery::BlogComment.table_name, :id
|
||||
|
||||
create_table :blog_categories, :id => true do |t|
|
||||
create_table Refinery::BlogCategory.table_name, :id => true do |t|
|
||||
t.string :title
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :blog_categories, :id
|
||||
add_index Refinery::BlogCategory.table_name, :id
|
||||
|
||||
create_table :blog_categories_blog_posts, :id => true do |t|
|
||||
create_table Refinery::Categorization.table_name, :id => true do |t|
|
||||
t.integer :blog_category_id
|
||||
t.integer :blog_post_id
|
||||
end
|
||||
|
||||
add_index :blog_categories_blog_posts, [:blog_category_id, :blog_post_id], :name => 'index_blog_categories_blog_posts_on_bc_and_bp'
|
||||
add_index Refinery::Categorization.table_name, [:blog_category_id, :blog_post_id], :name => 'index_blog_categories_blog_posts_on_bc_and_bp'
|
||||
|
||||
load(Rails.root.join('db', 'seeds', 'refinerycms_blog.rb').to_s)
|
||||
end
|
||||
|
||||
def self.down
|
||||
UserPlugin.destroy_all({:name => "refinerycms_blog"})
|
||||
def down
|
||||
Refinery::UserPlugin.destroy_all({:name => "refinerycms_blog"})
|
||||
|
||||
Page.delete_all({:link_url => "/blog"})
|
||||
Refinery::Page.delete_all({:link_url => "/blog"})
|
||||
|
||||
drop_table :blog_posts
|
||||
drop_table :blog_comments
|
||||
drop_table :blog_categories
|
||||
drop_table :blog_categories_blog_posts
|
||||
drop_table Refinery::BlogPost.table_name
|
||||
drop_table Refinery::BlogComment.table_name
|
||||
drop_table Refinery::Category.table_name
|
||||
drop_table Refinery::Categorization.table_name
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
class AddUserIdToBlogPosts < ActiveRecord::Migration
|
||||
|
||||
def self.up
|
||||
add_column :blog_posts, :user_id, :integer
|
||||
|
||||
def change
|
||||
add_column Refinery::BlogPost.table_name, :user_id, :integer
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :blog_posts, :user_id
|
||||
end
|
||||
|
||||
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
class ActsAsTaggableOnMigration < ActiveRecord::Migration
|
||||
def self.up
|
||||
def up
|
||||
create_table :tags do |t|
|
||||
t.string :name
|
||||
end
|
||||
|
@ -21,7 +21,7 @@ class ActsAsTaggableOnMigration < ActiveRecord::Migration
|
|||
add_index :taggings, [:taggable_id, :taggable_type, :context]
|
||||
end
|
||||
|
||||
def self.down
|
||||
def down
|
||||
drop_table :taggings
|
||||
drop_table :tags
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class CreateSeoMetaForBlog < ActiveRecord::Migration
|
||||
|
||||
def self.up
|
||||
def up
|
||||
unless ::SeoMetum.table_exists?
|
||||
create_table ::SeoMetum.table_name do |t|
|
||||
t.integer :seo_meta_id
|
||||
|
@ -18,7 +18,7 @@ class CreateSeoMetaForBlog < ActiveRecord::Migration
|
|||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
def down
|
||||
# can't drop the table because someone else might be using it.
|
||||
end
|
||||
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
class AddCachedSlugs < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column :blog_categories, :cached_slug, :string
|
||||
add_column :blog_posts, :cached_slug, :string
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :blog_categories, :cached_slug
|
||||
remove_column :blog_posts, :cached_slug
|
||||
def change
|
||||
add_column Refinery::BlogCategory.table_name, :cached_slug, :string
|
||||
add_column Refinery::BlogPost.table_name, :cached_slug, :string
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
class AddCustomUrlFieldToBlogPosts < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column :blog_posts, :custom_url, :string
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :blog_posts, :custom_url
|
||||
def change
|
||||
add_column Refinery::BlogPost.table_name, :custom_url, :string
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
class AddCustomTeaserFieldToBlogPosts < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column :blog_posts, :custom_teaser, :text
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :blog_posts, :custom_teaser
|
||||
def change
|
||||
add_column Refinery::BlogPost.table_name, :custom_teaser, :text
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
class AddPrimaryKeyToCategorizations < ActiveRecord::Migration
|
||||
def self.up
|
||||
unless ::Categorization.column_names.include?("id")
|
||||
add_column :blog_categories_blog_posts, :id, :primary_key
|
||||
def up
|
||||
unless Refinery::Categorization.column_names.include?("id")
|
||||
add_column Refinery::Categorization.table_name, :id, :primary_key
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :blog_categories_blog_posts, :id
|
||||
def down
|
||||
if Refinery::Categorization.column_names.include?("id")
|
||||
remove_column Refinery::Categorization.table_name, :id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
::User.find(:all).each do |user|
|
||||
Refinery::User.find(:all).each do |user|
|
||||
if user.plugins.where(:name => 'refinerycms_blog').blank?
|
||||
user.plugins.create(:name => "refinerycms_blog",
|
||||
:position => (user.plugins.maximum(:position) || -1) +1)
|
||||
end
|
||||
end if defined?(::User)
|
||||
end if defined?(Refinery::User)
|
||||
|
||||
if defined?(::Page)
|
||||
page = ::Page.create(
|
||||
if defined?(Refinery::Page)
|
||||
page = Refinery::Page.create(
|
||||
:title => "Blog",
|
||||
:link_url => "/blog",
|
||||
:deletable => false,
|
||||
:position => ((Page.maximum(:position, :conditions => {:parent_id => nil}) || -1)+1),
|
||||
:position => ((Refinery::Page.maximum(:position, :conditions => {:parent_id => nil}) || -1)+1),
|
||||
:menu_match => "^/blogs?(\/|\/.+?|)$"
|
||||
)
|
||||
|
||||
::Page.default_parts.each do |default_page_part|
|
||||
Refinery::Page.default_parts.each do |default_page_part|
|
||||
page.parts.create(:title => default_page_part, :body => nil)
|
||||
end
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
require 'factory_girl'
|
||||
|
||||
Factory.define(:blog_category) do |f|
|
||||
Factory.define :blog_category, :class => 'refinery/blog_category' do |f|
|
||||
f.sequence(:title) { |n| "Shopping #{n}" }
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'factory_girl'
|
||||
|
||||
Factory.define(:blog_comment) do |f|
|
||||
Factory.define :blog_comment, :class => 'refinery/blog_comment' do |f|
|
||||
f.name "Joe Commenter"
|
||||
f.sequence(:email) { |n| "person#{n}@example.com" }
|
||||
f.body "Which one is the best for picking up new shoes?"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'factory_girl'
|
||||
|
||||
Factory.define(:blog_post, :class => BlogPost) do |f|
|
||||
Factory.define :blog_post, :class => 'refinery/blog_post' do |f|
|
||||
f.sequence(:title) { |n| "Top #{n} Shopping Centers in Chicago" }
|
||||
f.body "These are the top ten shopping centers in Chicago. You're going to read a long blog post about them. Come to peace with it."
|
||||
f.draft false
|
||||
|
|
|
@ -17,7 +17,7 @@ Gem::Specification.new do |s|
|
|||
s.require_paths = %w(lib)
|
||||
|
||||
# Runtime dependencies
|
||||
s.add_dependency 'refinerycms-core', '~> 1.0.3'
|
||||
s.add_dependency 'refinerycms-core', '~> 1.1.0'
|
||||
s.add_dependency 'filters_spam', '~> 0.2'
|
||||
s.add_dependency 'acts-as-taggable-on'
|
||||
s.add_dependency 'seo_meta', '~> 1.1.0'
|
||||
|
|
10
lib/generators/blog_generator.rb
Normal file
10
lib/generators/blog_generator.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
require 'refinery/generators'
|
||||
|
||||
module ::Refinery
|
||||
class BlogGenerator < ::Refinery::Generators::EngineInstaller
|
||||
|
||||
source_root File.expand_path('../../../', __FILE__)
|
||||
engine_name "refinerycms-blog"
|
||||
|
||||
end
|
||||
end
|
|
@ -1,8 +0,0 @@
|
|||
require 'refinery/generators'
|
||||
|
||||
class RefinerycmsBlogGenerator < ::Refinery::Generators::EngineInstaller
|
||||
|
||||
source_root File.expand_path('../../../', __FILE__)
|
||||
engine_name "refinerycms-blog"
|
||||
|
||||
end
|
|
@ -1,9 +1,9 @@
|
|||
module Refinery
|
||||
module Blog
|
||||
class Version
|
||||
@major = 1
|
||||
@minor = 6
|
||||
@tiny = 2
|
||||
@major = 2
|
||||
@minor = 0
|
||||
@tiny = 0
|
||||
|
||||
class << self
|
||||
attr_reader :major, :minor, :tiny
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
require 'filters_spam'
|
||||
require File.expand_path('../generators/blog_generator', __FILE__)
|
||||
|
||||
module Refinery
|
||||
module Blog
|
||||
|
@ -25,14 +26,14 @@ module Refinery
|
|||
require File.expand_path('../refinery/blog/tabs', __FILE__)
|
||||
end
|
||||
|
||||
config.after_initialize do
|
||||
initializer "init plugin", :after => :set_routes_reloader do |app|
|
||||
Refinery::Plugin.register do |plugin|
|
||||
plugin.pathname = root
|
||||
plugin.name = "refinerycms_blog"
|
||||
plugin.url = {:controller => '/admin/blog/posts', :action => 'index'}
|
||||
plugin.menu_match = /^\/?(admin|refinery)\/blog\/?(posts|comments|categories)?/
|
||||
plugin.url = app.routes.url_helpers.refinery_admin_blog_posts_path
|
||||
plugin.menu_match = /^\/refinery\/blog\/?(posts|comments|categories)?/
|
||||
plugin.activity = {
|
||||
:class => BlogPost
|
||||
:class => Refinery::BlogPost
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
Gem::Specification.new do |s|
|
||||
s.name = %q{refinerycms-blog}
|
||||
s.version = %q{1.6.2}
|
||||
s.version = %q{2.0.0}
|
||||
s.description = %q{A really straightforward open source Ruby on Rails blog engine designed for integration with RefineryCMS.}
|
||||
s.date = %q{2011-06-29}
|
||||
s.date = %q{2011-07-27}
|
||||
s.summary = %q{Ruby on Rails blogging engine for RefineryCMS.}
|
||||
s.email = %q{info@refinerycms.com}
|
||||
s.homepage = %q{http://refinerycms.com/blog}
|
||||
|
@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|||
s.require_paths = %w(lib)
|
||||
|
||||
# Runtime dependencies
|
||||
s.add_dependency 'refinerycms-core', '~> 1.0.3'
|
||||
s.add_dependency 'refinerycms-core', '~> 1.1.0'
|
||||
s.add_dependency 'filters_spam', '~> 0.2'
|
||||
s.add_dependency 'acts-as-taggable-on'
|
||||
s.add_dependency 'seo_meta', '~> 1.1.0'
|
||||
|
@ -21,28 +21,31 @@ Gem::Specification.new do |s|
|
|||
s.files = %w(
|
||||
app
|
||||
app/controllers
|
||||
app/controllers/admin
|
||||
app/controllers/admin/blog
|
||||
app/controllers/admin/blog/categories_controller.rb
|
||||
app/controllers/admin/blog/comments_controller.rb
|
||||
app/controllers/admin/blog/posts_controller.rb
|
||||
app/controllers/admin/blog/settings_controller.rb
|
||||
app/controllers/blog
|
||||
app/controllers/blog/categories_controller.rb
|
||||
app/controllers/blog/posts_controller.rb
|
||||
app/controllers/blog_controller.rb
|
||||
app/controllers/refinery
|
||||
app/controllers/refinery/admin
|
||||
app/controllers/refinery/admin/blog
|
||||
app/controllers/refinery/admin/blog/categories_controller.rb
|
||||
app/controllers/refinery/admin/blog/comments_controller.rb
|
||||
app/controllers/refinery/admin/blog/posts_controller.rb
|
||||
app/controllers/refinery/admin/blog/settings_controller.rb
|
||||
app/controllers/refinery/blog
|
||||
app/controllers/refinery/blog/categories_controller.rb
|
||||
app/controllers/refinery/blog/posts_controller.rb
|
||||
app/controllers/refinery/blog_controller.rb
|
||||
app/helpers
|
||||
app/helpers/blog_posts_helper.rb
|
||||
app/mailers
|
||||
app/mailers/blog
|
||||
app/mailers/blog/comment_mailer.rb
|
||||
app/mailers/refinery
|
||||
app/mailers/refinery/blog
|
||||
app/mailers/refinery/blog/comment_mailer.rb
|
||||
app/models
|
||||
app/models/blog
|
||||
app/models/blog/comment_mailer.rb
|
||||
app/models/blog_category.rb
|
||||
app/models/blog_comment.rb
|
||||
app/models/blog_post.rb
|
||||
app/models/categorization.rb
|
||||
app/models/refinery
|
||||
app/models/refinery/blog
|
||||
app/models/refinery/blog/comment_mailer.rb
|
||||
app/models/refinery/blog_category.rb
|
||||
app/models/refinery/blog_comment.rb
|
||||
app/models/refinery/blog_post.rb
|
||||
app/models/refinery/categorization.rb
|
||||
app/views
|
||||
app/views/admin
|
||||
app/views/admin/blog
|
||||
|
@ -99,12 +102,14 @@ Gem::Specification.new do |s|
|
|||
changelog.md
|
||||
config
|
||||
config/locales
|
||||
config/locales/bg.yml
|
||||
config/locales/cs.yml
|
||||
config/locales/de.yml
|
||||
config/locales/en.yml
|
||||
config/locales/es.yml
|
||||
config/locales/fr.yml
|
||||
config/locales/it.yml
|
||||
config/locales/jp.yml
|
||||
config/locales/nb.yml
|
||||
config/locales/nl.yml
|
||||
config/locales/pl.yml
|
||||
|
@ -122,6 +127,7 @@ Gem::Specification.new do |s|
|
|||
db/migrate/5_add_cached_slugs.rb
|
||||
db/migrate/6_add_custom_url_field_to_blog_posts.rb
|
||||
db/migrate/7_add_custom_teaser_field_to_blog_posts.rb
|
||||
db/migrate/8_add_primary_key_to_categorizations.rb
|
||||
db/seeds
|
||||
db/seeds/refinerycms_blog.rb
|
||||
features
|
||||
|
@ -141,7 +147,7 @@ Gem::Specification.new do |s|
|
|||
lib
|
||||
lib/gemspec.rb
|
||||
lib/generators
|
||||
lib/generators/refinerycms_blog_generator.rb
|
||||
lib/generators/blog_generator.rb
|
||||
lib/refinery
|
||||
lib/refinery/blog
|
||||
lib/refinery/blog/tabs.rb
|
||||
|
@ -194,9 +200,11 @@ Gem::Specification.new do |s|
|
|||
refinerycms-blog.gemspec
|
||||
spec
|
||||
spec/models
|
||||
spec/models/blog_category_spec.rb
|
||||
spec/models/blog_comment_spec.rb
|
||||
spec/models/blog_post_spec.rb
|
||||
spec/models/refinery
|
||||
spec/models/refinery/blog_category_spec.rb
|
||||
spec/models/refinery/blog_comment_spec.rb
|
||||
spec/models/refinery/blog_post_spec.rb
|
||||
todo.md
|
||||
)
|
||||
|
||||
end
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
require 'spec_helper'
|
||||
Dir[File.expand_path('../../../features/support/factories/*.rb', __FILE__)].each{|factory| require factory}
|
||||
|
||||
describe BlogCategory do
|
||||
before(:each) do
|
||||
@blog_category = Factory.create(:blog_category)
|
||||
end
|
||||
|
||||
describe "validations" do
|
||||
it "requires title" do
|
||||
Factory.build(:blog_category, :title => "").should_not be_valid
|
||||
end
|
||||
|
||||
it "won't allow duplicate titles" do
|
||||
Factory.build(:blog_category, :title => @blog_category.title).should_not be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe "blog posts association" do
|
||||
it "has a posts attribute" do
|
||||
@blog_category.should respond_to(:posts)
|
||||
end
|
||||
|
||||
it "returns posts by published_at date in descending order" do
|
||||
first_post = @blog_category.posts.create!({ :title => "Breaking News: Joe Sak is hot stuff you guys!!", :body => "True story.", :published_at => Time.now.yesterday })
|
||||
latest_post = @blog_category.posts.create!({ :title => "parndt is p. okay", :body => "For a Kiwi.", :published_at => Time.now })
|
||||
|
||||
@blog_category.posts.first.should == latest_post
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#post_count" do
|
||||
it "returns post count in category" do
|
||||
2.times do
|
||||
@blog_category.posts << Factory.create(:blog_post)
|
||||
end
|
||||
@blog_category.post_count.should == 2
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,21 +0,0 @@
|
|||
require 'spec_helper'
|
||||
Dir[File.expand_path('../../../features/support/factories/*.rb', __FILE__)].each{|factory| require factory}
|
||||
|
||||
describe BlogComment do
|
||||
|
||||
context "wiring up" do
|
||||
|
||||
before(:each) do
|
||||
@comment = Factory.create(:blog_comment)
|
||||
end
|
||||
|
||||
it "saves" do
|
||||
@comment.should_not be_nil
|
||||
end
|
||||
|
||||
it "has a blog post" do
|
||||
@comment.post.should_not be_nil
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -1,217 +0,0 @@
|
|||
require 'spec_helper'
|
||||
Dir[File.expand_path('../../../features/support/factories/*.rb', __FILE__)].each{|factory| require factory}
|
||||
|
||||
describe BlogPost do
|
||||
let(:blog_post ) { Factory.create(:blog_post) }
|
||||
|
||||
describe "validations" do
|
||||
it "requires title" do
|
||||
Factory.build(:blog_post, :title => "").should_not be_valid
|
||||
end
|
||||
|
||||
it "won't allow duplicate titles" do
|
||||
Factory.build(:blog_post, :title => blog_post.title).should_not be_valid
|
||||
end
|
||||
|
||||
it "requires body" do
|
||||
Factory.build(:blog_post, :body => nil).should_not be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe "comments association" do
|
||||
|
||||
it "have a comments attribute" do
|
||||
blog_post.should respond_to(:comments)
|
||||
end
|
||||
|
||||
it "destroys associated comments" do
|
||||
Factory.create(:blog_comment, :blog_post_id => blog_post.id)
|
||||
blog_post.destroy
|
||||
BlogComment.find_by_blog_post_id(blog_post.id).should == nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "categories association" do
|
||||
it "have categories attribute" do
|
||||
blog_post.should respond_to(:categories)
|
||||
end
|
||||
end
|
||||
|
||||
describe "tags" do
|
||||
it "acts as taggable" do
|
||||
blog_post.should respond_to(:tag_list)
|
||||
|
||||
#the factory has default tags, including 'chicago'
|
||||
blog_post.tag_list.should include("chicago")
|
||||
end
|
||||
end
|
||||
|
||||
describe "authors" do
|
||||
it "are authored" do
|
||||
BlogPost.instance_methods.map(&:to_sym).should include(:author)
|
||||
end
|
||||
end
|
||||
|
||||
describe "by_archive scope" do
|
||||
before do
|
||||
@blog_post1 = Factory.create(:blog_post, :published_at => Date.new(2011, 3, 11))
|
||||
@blog_post2 = Factory.create(:blog_post, :published_at => Date.new(2011, 3, 12))
|
||||
|
||||
#2 months before
|
||||
Factory.create(:blog_post, :published_at => Date.new(2011, 1, 10))
|
||||
end
|
||||
|
||||
it "returns all posts from specified month" do
|
||||
#check for this month
|
||||
date = "03/2011"
|
||||
BlogPost.by_archive(Time.parse(date)).count.should be == 2
|
||||
BlogPost.by_archive(Time.parse(date)).should == [@blog_post2, @blog_post1]
|
||||
end
|
||||
end
|
||||
|
||||
describe "all_previous scope" do
|
||||
before do
|
||||
@blog_post1 = Factory.create(:blog_post, :published_at => Time.now - 2.months)
|
||||
@blog_post2 = Factory.create(:blog_post, :published_at => Time.now - 1.month)
|
||||
Factory.create(:blog_post, :published_at => Time.now)
|
||||
end
|
||||
|
||||
it "returns all posts from previous months" do
|
||||
BlogPost.all_previous.count.should be == 2
|
||||
BlogPost.all_previous.should == [@blog_post2, @blog_post1]
|
||||
end
|
||||
end
|
||||
|
||||
describe "live scope" do
|
||||
before do
|
||||
@blog_post1 = Factory.create(:blog_post, :published_at => Time.now.advance(:minutes => -2))
|
||||
@blog_post2 = Factory.create(:blog_post, :published_at => Time.now.advance(:minutes => -1))
|
||||
Factory.create(:blog_post, :draft => true)
|
||||
Factory.create(:blog_post, :published_at => Time.now + 1.minute)
|
||||
end
|
||||
|
||||
it "returns all posts which aren't in draft and pub date isn't in future" do
|
||||
BlogPost.live.count.should be == 2
|
||||
BlogPost.live.should == [@blog_post2, @blog_post1]
|
||||
end
|
||||
end
|
||||
|
||||
describe "uncategorized scope" do
|
||||
before do
|
||||
@uncategorized_blog_post = Factory.create(:blog_post)
|
||||
@categorized_blog_post = Factory.create(:blog_post)
|
||||
|
||||
@categorized_blog_post.categories << Factory.create(:blog_category)
|
||||
end
|
||||
|
||||
it "returns uncategorized posts if they exist" do
|
||||
BlogPost.uncategorized.should include @uncategorized_blog_post
|
||||
BlogPost.uncategorized.should_not include @categorized_blog_post
|
||||
end
|
||||
end
|
||||
|
||||
describe "#live?" do
|
||||
it "returns true if post is not in draft and it's published" do
|
||||
Factory.create(:blog_post).live?.should be_true
|
||||
end
|
||||
|
||||
it "returns false if post is in draft" do
|
||||
Factory.create(:blog_post, :draft => true).live?.should be_false
|
||||
end
|
||||
|
||||
it "returns false if post pub date is in future" do
|
||||
Factory.create(:blog_post, :published_at => Time.now.advance(:minutes => 1)).live?.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe "#next" do
|
||||
before do
|
||||
Factory.create(:blog_post, :published_at => Time.now.advance(:minutes => -1))
|
||||
@blog_post = Factory.create(:blog_post)
|
||||
end
|
||||
|
||||
it "returns next article when called on current article" do
|
||||
BlogPost.last.next.should == @blog_post
|
||||
end
|
||||
end
|
||||
|
||||
describe "#prev" do
|
||||
before do
|
||||
Factory.create(:blog_post)
|
||||
@blog_post = Factory.create(:blog_post, :published_at => Time.now.advance(:minutes => -1))
|
||||
end
|
||||
|
||||
it "returns previous article when called on current article" do
|
||||
BlogPost.first.prev.should == @blog_post
|
||||
end
|
||||
end
|
||||
|
||||
describe "#category_ids=" do
|
||||
before do
|
||||
@cat1 = Factory.create(:blog_category, :id => 1)
|
||||
@cat2 = Factory.create(:blog_category, :id => 2)
|
||||
@cat3 = Factory.create(:blog_category, :id => 3)
|
||||
blog_post.category_ids = [1,2,"","",3]
|
||||
end
|
||||
|
||||
it "rejects blank category ids" do
|
||||
blog_post.categories.count.should == 3
|
||||
end
|
||||
|
||||
it "returns array of categories based on given ids" do
|
||||
blog_post.categories.should == [@cat1, @cat2, @cat3]
|
||||
end
|
||||
end
|
||||
|
||||
describe ".comments_allowed?" do
|
||||
context "with RefinerySetting comments_allowed set to true" do
|
||||
before do
|
||||
RefinerySetting.set(:comments_allowed, { :scoping => 'blog', :value => true })
|
||||
end
|
||||
|
||||
it "should be true" do
|
||||
BlogPost.comments_allowed?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "with RefinerySetting comments_allowed set to false" do
|
||||
before do
|
||||
RefinerySetting.set(:comments_allowed, { :scoping => 'blog', :value => false })
|
||||
end
|
||||
|
||||
it "should be false" do
|
||||
BlogPost.comments_allowed?.should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "custom teasers" do
|
||||
it "should allow a custom teaser" do
|
||||
Factory.create(:blog_post, :custom_teaser => 'This is some custom content').should be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe ".teasers_enabled?" do
|
||||
context "with RefinerySetting teasers_enabled set to true" do
|
||||
before do
|
||||
RefinerySetting.set(:teasers_enabled, { :scoping => 'blog', :value => true })
|
||||
end
|
||||
|
||||
it "should be true" do
|
||||
BlogPost.teasers_enabled?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "with RefinerySetting teasers_enabled set to false" do
|
||||
before do
|
||||
RefinerySetting.set(:teasers_enabled, { :scoping => 'blog', :value => false })
|
||||
end
|
||||
|
||||
it "should be false" do
|
||||
BlogPost.teasers_enabled?.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
43
spec/models/refinery/blog_category_spec.rb
Normal file
43
spec/models/refinery/blog_category_spec.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
require 'spec_helper'
|
||||
Dir[File.expand_path('../../../features/support/factories/*.rb', __FILE__)].each{|factory| require factory}
|
||||
|
||||
module Refinery
|
||||
describe BlogCategory do
|
||||
before(:each) do
|
||||
@blog_category = Factory.create(:blog_category)
|
||||
end
|
||||
|
||||
describe "validations" do
|
||||
it "requires title" do
|
||||
Factory.build(:blog_category, :title => "").should_not be_valid
|
||||
end
|
||||
|
||||
it "won't allow duplicate titles" do
|
||||
Factory.build(:blog_category, :title => @blog_category.title).should_not be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe "blog posts association" do
|
||||
it "has a posts attribute" do
|
||||
@blog_category.should respond_to(:posts)
|
||||
end
|
||||
|
||||
it "returns posts by published_at date in descending order" do
|
||||
first_post = @blog_category.posts.create!({ :title => "Breaking News: Joe Sak is hot stuff you guys!!", :body => "True story.", :published_at => Time.now.yesterday })
|
||||
latest_post = @blog_category.posts.create!({ :title => "parndt is p. okay", :body => "For a Kiwi.", :published_at => Time.now })
|
||||
|
||||
@blog_category.posts.first.should == latest_post
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#post_count" do
|
||||
it "returns post count in category" do
|
||||
2.times do
|
||||
@blog_category.posts << Factory.create(:blog_post)
|
||||
end
|
||||
@blog_category.post_count.should == 2
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
23
spec/models/refinery/blog_comment_spec.rb
Normal file
23
spec/models/refinery/blog_comment_spec.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
require 'spec_helper'
|
||||
Dir[File.expand_path('../../../features/support/factories/*.rb', __FILE__)].each{|factory| require factory}
|
||||
|
||||
module Refinery
|
||||
describe BlogComment do
|
||||
|
||||
context "wiring up" do
|
||||
|
||||
before(:each) do
|
||||
@comment = Factory.create(:blog_comment)
|
||||
end
|
||||
|
||||
it "saves" do
|
||||
@comment.should_not be_nil
|
||||
end
|
||||
|
||||
it "has a blog post" do
|
||||
@comment.post.should_not be_nil
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
219
spec/models/refinery/blog_post_spec.rb
Normal file
219
spec/models/refinery/blog_post_spec.rb
Normal file
|
@ -0,0 +1,219 @@
|
|||
require 'spec_helper'
|
||||
Dir[File.expand_path('../../../features/support/factories/*.rb', __FILE__)].each{|factory| require factory}
|
||||
|
||||
module Refinery
|
||||
describe BlogPost do
|
||||
let(:blog_post ) { Factory.create(:blog_post) }
|
||||
|
||||
describe "validations" do
|
||||
it "requires title" do
|
||||
Factory.build(:blog_post, :title => "").should_not be_valid
|
||||
end
|
||||
|
||||
it "won't allow duplicate titles" do
|
||||
Factory.build(:blog_post, :title => blog_post.title).should_not be_valid
|
||||
end
|
||||
|
||||
it "requires body" do
|
||||
Factory.build(:blog_post, :body => nil).should_not be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe "comments association" do
|
||||
|
||||
it "have a comments attribute" do
|
||||
blog_post.should respond_to(:comments)
|
||||
end
|
||||
|
||||
it "destroys associated comments" do
|
||||
Factory.create(:blog_comment, :blog_post_id => blog_post.id)
|
||||
blog_post.destroy
|
||||
BlogComment.find_by_blog_post_id(blog_post.id).should == nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "categories association" do
|
||||
it "have categories attribute" do
|
||||
blog_post.should respond_to(:categories)
|
||||
end
|
||||
end
|
||||
|
||||
describe "tags" do
|
||||
it "acts as taggable" do
|
||||
blog_post.should respond_to(:tag_list)
|
||||
|
||||
#the factory has default tags, including 'chicago'
|
||||
blog_post.tag_list.should include("chicago")
|
||||
end
|
||||
end
|
||||
|
||||
describe "authors" do
|
||||
it "are authored" do
|
||||
BlogPost.instance_methods.map(&:to_sym).should include(:author)
|
||||
end
|
||||
end
|
||||
|
||||
describe "by_archive scope" do
|
||||
before do
|
||||
@blog_post1 = Factory.create(:blog_post, :published_at => Date.new(2011, 3, 11))
|
||||
@blog_post2 = Factory.create(:blog_post, :published_at => Date.new(2011, 3, 12))
|
||||
|
||||
#2 months before
|
||||
Factory.create(:blog_post, :published_at => Date.new(2011, 1, 10))
|
||||
end
|
||||
|
||||
it "returns all posts from specified month" do
|
||||
#check for this month
|
||||
date = "03/2011"
|
||||
BlogPost.by_archive(Time.parse(date)).count.should be == 2
|
||||
BlogPost.by_archive(Time.parse(date)).should == [@blog_post2, @blog_post1]
|
||||
end
|
||||
end
|
||||
|
||||
describe "all_previous scope" do
|
||||
before do
|
||||
@blog_post1 = Factory.create(:blog_post, :published_at => Time.now - 2.months)
|
||||
@blog_post2 = Factory.create(:blog_post, :published_at => Time.now - 1.month)
|
||||
Factory.create(:blog_post, :published_at => Time.now)
|
||||
end
|
||||
|
||||
it "returns all posts from previous months" do
|
||||
BlogPost.all_previous.count.should be == 2
|
||||
BlogPost.all_previous.should == [@blog_post2, @blog_post1]
|
||||
end
|
||||
end
|
||||
|
||||
describe "live scope" do
|
||||
before do
|
||||
@blog_post1 = Factory.create(:blog_post, :published_at => Time.now.advance(:minutes => -2))
|
||||
@blog_post2 = Factory.create(:blog_post, :published_at => Time.now.advance(:minutes => -1))
|
||||
Factory.create(:blog_post, :draft => true)
|
||||
Factory.create(:blog_post, :published_at => Time.now + 1.minute)
|
||||
end
|
||||
|
||||
it "returns all posts which aren't in draft and pub date isn't in future" do
|
||||
BlogPost.live.count.should be == 2
|
||||
BlogPost.live.should == [@blog_post2, @blog_post1]
|
||||
end
|
||||
end
|
||||
|
||||
describe "uncategorized scope" do
|
||||
before do
|
||||
@uncategorized_blog_post = Factory.create(:blog_post)
|
||||
@categorized_blog_post = Factory.create(:blog_post)
|
||||
|
||||
@categorized_blog_post.categories << Factory.create(:blog_category)
|
||||
end
|
||||
|
||||
it "returns uncategorized posts if they exist" do
|
||||
BlogPost.uncategorized.should include @uncategorized_blog_post
|
||||
BlogPost.uncategorized.should_not include @categorized_blog_post
|
||||
end
|
||||
end
|
||||
|
||||
describe "#live?" do
|
||||
it "returns true if post is not in draft and it's published" do
|
||||
Factory.create(:blog_post).live?.should be_true
|
||||
end
|
||||
|
||||
it "returns false if post is in draft" do
|
||||
Factory.create(:blog_post, :draft => true).live?.should be_false
|
||||
end
|
||||
|
||||
it "returns false if post pub date is in future" do
|
||||
Factory.create(:blog_post, :published_at => Time.now.advance(:minutes => 1)).live?.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe "#next" do
|
||||
before do
|
||||
Factory.create(:blog_post, :published_at => Time.now.advance(:minutes => -1))
|
||||
@blog_post = Factory.create(:blog_post)
|
||||
end
|
||||
|
||||
it "returns next article when called on current article" do
|
||||
BlogPost.last.next.should == @blog_post
|
||||
end
|
||||
end
|
||||
|
||||
describe "#prev" do
|
||||
before do
|
||||
Factory.create(:blog_post)
|
||||
@blog_post = Factory.create(:blog_post, :published_at => Time.now.advance(:minutes => -1))
|
||||
end
|
||||
|
||||
it "returns previous article when called on current article" do
|
||||
BlogPost.first.prev.should == @blog_post
|
||||
end
|
||||
end
|
||||
|
||||
describe "#category_ids=" do
|
||||
before do
|
||||
@cat1 = Factory.create(:blog_category, :id => 1)
|
||||
@cat2 = Factory.create(:blog_category, :id => 2)
|
||||
@cat3 = Factory.create(:blog_category, :id => 3)
|
||||
blog_post.category_ids = [1,2,"","",3]
|
||||
end
|
||||
|
||||
it "rejects blank category ids" do
|
||||
blog_post.categories.count.should == 3
|
||||
end
|
||||
|
||||
it "returns array of categories based on given ids" do
|
||||
blog_post.categories.should == [@cat1, @cat2, @cat3]
|
||||
end
|
||||
end
|
||||
|
||||
describe ".comments_allowed?" do
|
||||
context "with Refinery::Setting comments_allowed set to true" do
|
||||
before do
|
||||
Refinery::Setting.set(:comments_allowed, { :scoping => 'blog', :value => true })
|
||||
end
|
||||
|
||||
it "should be true" do
|
||||
BlogPost.comments_allowed?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "with Refinery::Setting comments_allowed set to false" do
|
||||
before do
|
||||
Refinery::Setting.set(:comments_allowed, { :scoping => 'blog', :value => false })
|
||||
end
|
||||
|
||||
it "should be false" do
|
||||
BlogPost.comments_allowed?.should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "custom teasers" do
|
||||
it "should allow a custom teaser" do
|
||||
Factory.create(:blog_post, :custom_teaser => 'This is some custom content').should be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe ".teasers_enabled?" do
|
||||
context "with Refinery::Setting teasers_enabled set to true" do
|
||||
before do
|
||||
Refinery::Setting.set(:teasers_enabled, { :scoping => 'blog', :value => true })
|
||||
end
|
||||
|
||||
it "should be true" do
|
||||
BlogPost.teasers_enabled?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "with Refinery::Setting teasers_enabled set to false" do
|
||||
before do
|
||||
Refinery::Setting.set(:teasers_enabled, { :scoping => 'blog', :value => false })
|
||||
end
|
||||
|
||||
it "should be false" do
|
||||
BlogPost.teasers_enabled?.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue