Hello rails3 support.
This commit is contained in:
parent
c4222bfdf5
commit
a2f655b55e
20 changed files with 288 additions and 51 deletions
|
@ -16,7 +16,7 @@ class Admin::Blog::SettingsController < Admin::BaseController
|
|||
end
|
||||
|
||||
def moderation
|
||||
enabled = BlogComment::Moderation.toggle
|
||||
enabled = BlogComment::Moderation.toggle!
|
||||
unless request.xhr?
|
||||
redirect_back_or_default(admin_blog_posts_path)
|
||||
else
|
||||
|
|
|
@ -21,10 +21,10 @@ class BlogPostsController < ApplicationController
|
|||
def comment
|
||||
if (@blog_comment = @blog_post.comments.create(params[:blog_comment])).valid?
|
||||
if BlogComment::Moderation.enabled?
|
||||
flash[:notice] = t('.comments.thank_you_moderated')
|
||||
redirect_back_or_default blog_post_url(params[:id])
|
||||
flash[:notice] = t('blog_posts.show.comments.thank_you_moderated')
|
||||
redirect_to blog_post_url(params[:id])
|
||||
else
|
||||
flash[:notice] = t('.comments.thank_you')
|
||||
flash[:notice] = t('blog_posts.show.comments.thank_you')
|
||||
redirect_to blog_post_url(params[:id],
|
||||
:anchor => "comment-#{@blog_comment.to_param}")
|
||||
end
|
||||
|
|
|
@ -14,9 +14,15 @@ class BlogComment < ActiveRecord::Base
|
|||
validates_format_of :email,
|
||||
:with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
|
||||
|
||||
named_scope :unmoderated, :conditions => {:state => nil}
|
||||
named_scope :approved, :conditions => {:state => 'approved'}
|
||||
named_scope :rejected, :conditions => {:state => 'rejected'}
|
||||
if Rails.version < '3.0.0'
|
||||
named_scope :unmoderated, :conditions => {:state => nil}
|
||||
named_scope :approved, :conditions => {:state => 'approved'}
|
||||
named_scope :rejected, :conditions => {:state => 'rejected'}
|
||||
else
|
||||
scope :unmoderated, :conditions => {:state => nil}
|
||||
scope :approved, :conditions => {:state => 'approved'}
|
||||
scope :rejected, :conditions => {:state => 'rejected'}
|
||||
end
|
||||
|
||||
def approve!
|
||||
self.update_attribute(:state, 'approved')
|
||||
|
@ -48,14 +54,18 @@ class BlogComment < ActiveRecord::Base
|
|||
class << self
|
||||
def enabled?
|
||||
RefinerySetting.find_or_set(:comment_moderation, true, {
|
||||
:scoping => :blog
|
||||
:scoping => :blog,
|
||||
:restricted => false,
|
||||
:callback_proc_as_string => nil
|
||||
})
|
||||
end
|
||||
|
||||
def toggle
|
||||
def toggle!
|
||||
RefinerySetting[:comment_moderation] = {
|
||||
:value => !self.enabled?,
|
||||
:scoping => :blog
|
||||
:scoping => :blog,
|
||||
:restricted => false,
|
||||
:callback_proc_as_string => nil
|
||||
}
|
||||
end
|
||||
end
|
||||
|
@ -64,17 +74,21 @@ class BlogComment < ActiveRecord::Base
|
|||
module Notification
|
||||
class << self
|
||||
def recipients
|
||||
RefinerySetting.find_or_set(
|
||||
:comment_notification_recipients,
|
||||
(Role[:refinery].users.first.email rescue ''),
|
||||
{:scoping => :blog}
|
||||
)
|
||||
RefinerySetting.find_or_set(:comment_notification_recipients,
|
||||
(Role[:refinery].users.first.email rescue ''),
|
||||
{
|
||||
:scoping => :blog,
|
||||
:restricted => false,
|
||||
:callback_proc_as_string => nil
|
||||
})
|
||||
end
|
||||
|
||||
def recipients=(emails)
|
||||
RefinerySetting[:comment_notification_recipients] = {
|
||||
:value => emails,
|
||||
:scoping => :blog
|
||||
:scoping => :blog,
|
||||
:restricted => false,
|
||||
:callback_proc_as_string => nil
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,7 +12,11 @@ class BlogPost < ActiveRecord::Base
|
|||
|
||||
default_scope :order => "created_at DESC"
|
||||
|
||||
named_scope :live, :conditions => {:draft => false}
|
||||
if Rails.version < '3.0.0'
|
||||
named_scope :live, :conditions => {:draft => false}
|
||||
else
|
||||
scope :live, :conditions => {:draft => false}
|
||||
end
|
||||
|
||||
def category_ids=(ids)
|
||||
self.categories = ids.reject{|id| id.blank?}.collect {|c_id|
|
||||
|
|
|
@ -4,11 +4,13 @@
|
|||
<span class="preview"> </span>
|
||||
</span>
|
||||
<span class='actions'>
|
||||
<%= link_to refinery_icon_tag("application_edit.png"),
|
||||
<%= link_to refinery_icon_tag("application_edit.png"),
|
||||
edit_admin_blog_category_path(category, :dialog => true, :height => 325),
|
||||
:title => t('.edit') %>
|
||||
<%= link_to refinery_icon_tag("delete.png"), admin_blog_category_path(category),
|
||||
:class => "cancel confirm-delete",
|
||||
:title => t('.delete') %>
|
||||
:title => t('.delete'),
|
||||
:'data-method' => 'delete',
|
||||
:'data-confirm' => t('shared.admin.delete.message', :title => category.title) %>
|
||||
</span>
|
||||
</li>
|
||||
|
|
|
@ -1,6 +1,14 @@
|
|||
<% form_for [:admin, @blog_category] do |f| -%>
|
||||
<%= f.error_messages %>
|
||||
|
||||
<% if Rails.version < '3.0.0'%>
|
||||
<%= f.error_messages %>
|
||||
<% else %>
|
||||
<%= render :partial => "/shared/admin/error_messages",
|
||||
:locals => {
|
||||
:object => f.object,
|
||||
:include_object_name => true
|
||||
} %>
|
||||
<% end %>
|
||||
|
||||
<div class='field'>
|
||||
<%= f.label :title -%>
|
||||
<%= f.text_field :title, :class => 'larger widest' -%>
|
||||
|
|
|
@ -11,10 +11,10 @@
|
|||
<%= link_to refinery_icon_tag('zoom.png'), admin_blog_comment_path(comment),
|
||||
:title => t('.read') %>
|
||||
<%= link_to refinery_icon_tag("cross.png"),
|
||||
rejected_admin_blog_comment_path(comment, :return_to => request.path.split('/').last),
|
||||
rejected_admin_blog_comment_path(comment, :return_to => request.path.split('/').last.gsub(/^comments$/, 'index')),
|
||||
:title => t('.reject') unless comment.rejected? %>
|
||||
<%= link_to refinery_icon_tag("tick.png"),
|
||||
approved_admin_blog_comment_path(comment, :return_to => request.path.split('/').last),
|
||||
approved_admin_blog_comment_path(comment, :return_to => request.path.split('/').last.gsub(/^comments$/, 'index')),
|
||||
:title => t('.approve') unless comment.approved? %>
|
||||
</span>
|
||||
</li>
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
<% form_for [:admin, @blog_post] do |f| -%>
|
||||
<%= f.error_messages %>
|
||||
<% if Rails.version < '3.0.0'%>
|
||||
<%= f.error_messages %>
|
||||
<% else %>
|
||||
<%= render :partial => "/shared/admin/error_messages",
|
||||
:locals => {
|
||||
:object => f.object,
|
||||
:include_object_name => true
|
||||
} %>
|
||||
<% end %>
|
||||
|
||||
<div class='field'>
|
||||
<%= f.label :title -%>
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
:title => t('.edit') %>
|
||||
<%= link_to refinery_icon_tag("delete.png"), admin_blog_post_path(post),
|
||||
:class => "cancel confirm-delete",
|
||||
:title => t('.delete') %>
|
||||
:title => t('.delete'),
|
||||
:'data-method' => 'delete',
|
||||
:'data-confirm' => t('shared.admin.delete.message', :title => post.title) %>
|
||||
</span>
|
||||
</li>
|
||||
|
|
|
@ -35,7 +35,21 @@
|
|||
|
||||
<% if BlogPost.comments_allowed? %>
|
||||
<hr />
|
||||
<% flash.each do |key, value| %>
|
||||
<div id='flash' class="flash flash_<%= key %>">
|
||||
<%= value %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% form_for [:blog_post, @blog_comment] do |f| %>
|
||||
<% if Rails.version < '3.0.0'%>
|
||||
<%= f.error_messages %>
|
||||
<% else %>
|
||||
<%= render :partial => "/shared/admin/error_messages",
|
||||
:locals => {
|
||||
:object => f.object,
|
||||
:include_object_name => true
|
||||
} %>
|
||||
<% end %>
|
||||
<div class='field'>
|
||||
<%= f.label :name %>
|
||||
<%= f.text_field :name %>
|
||||
|
|
|
@ -8,9 +8,9 @@ if Rails.version < '3.0.0'
|
|||
map.namespace(:admin, :path_prefix => 'refinery') do |admin|
|
||||
admin.namespace :blog do |blog|
|
||||
blog.resources :posts
|
||||
|
||||
|
||||
blog.resources :categories
|
||||
|
||||
|
||||
blog.resources :comments, :collection => {
|
||||
:approved => :get,
|
||||
:rejected => :get
|
||||
|
@ -18,7 +18,7 @@ if Rails.version < '3.0.0'
|
|||
:approved => :get,
|
||||
:rejected => :get
|
||||
}
|
||||
|
||||
|
||||
blog.resources :settings, :collection => {
|
||||
:notification_recipients => [:get, :post],
|
||||
:moderation => :get
|
||||
|
@ -27,5 +27,40 @@ if Rails.version < '3.0.0'
|
|||
end
|
||||
end
|
||||
else
|
||||
# route for rails3 here.
|
||||
Refinery::Application.routes.draw do
|
||||
match '/blog', :to => 'blog_posts#index', :as => 'blog_post'
|
||||
match '/blog/:id', :to => 'blog_posts#show', :as => 'blog_post'
|
||||
|
||||
match '/blog/categories/:category_id', :to => 'blog_posts#index', :as => 'blog_category'
|
||||
match '/blog/:id/comments', :to => 'blog_posts#comment', :as => 'blog_post_blog_comments'
|
||||
|
||||
scope(:path => 'refinery', :as => 'admin', :module => 'admin') do
|
||||
scope(:path => 'blog', :name_prefix => 'admin', :as => 'blog', :module => 'blog') do
|
||||
root :to => 'posts#index'
|
||||
resources :posts
|
||||
|
||||
resources :categories
|
||||
|
||||
resources :comments do
|
||||
collection do
|
||||
get :approved
|
||||
get :rejected
|
||||
end
|
||||
member do
|
||||
get :approved
|
||||
get :rejected
|
||||
end
|
||||
end
|
||||
|
||||
resources :settings do
|
||||
collection do
|
||||
get :notification_recipients
|
||||
post :notification_recipients
|
||||
|
||||
get :moderation
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -12,24 +12,22 @@ class RefineryBlogGenerator < Rails::Generator::NamedBase
|
|||
|
||||
def manifest
|
||||
record do |m|
|
||||
if Rails.version < '3.0.0'
|
||||
matches = Dir[
|
||||
File.expand_path('../../../public/images/**/*', __FILE__),
|
||||
File.expand_path('../../../public/stylesheets/**/*', __FILE__),
|
||||
File.expand_path('../../../public/javascripts/**/*', __FILE__),
|
||||
]
|
||||
matches.reject{|d| !File.directory?(d)}.each do |dir|
|
||||
m.directory((%w(public) | dir.split('public/').last.split('/')).join('/'))
|
||||
end
|
||||
matches.reject{|f| File.directory?(f)}.each do |image|
|
||||
path = (%w(public) | image.split('public/').last.split('/'))[0...-1].join('/')
|
||||
m.template "../../../#{path}/#{image.split('/').last}", "#{path}/#{image.split('/').last}"
|
||||
end
|
||||
matches = Dir[
|
||||
File.expand_path('../../../public/images/**/*', __FILE__),
|
||||
File.expand_path('../../../public/stylesheets/**/*', __FILE__),
|
||||
File.expand_path('../../../public/javascripts/**/*', __FILE__),
|
||||
]
|
||||
matches.reject{|d| !File.directory?(d)}.each do |dir|
|
||||
m.directory((%w(public) | dir.split('public/').last.split('/')).join('/'))
|
||||
end
|
||||
matches.reject{|f| File.directory?(f)}.each do |image|
|
||||
path = (%w(public) | image.split('public/').last.split('/'))[0...-1].join('/')
|
||||
m.template "../../../#{path}/#{image.split('/').last}", "#{path}/#{image.split('/').last}"
|
||||
end
|
||||
|
||||
m.template('seed.rb', 'db/seeds/refinerycms_blog.rb')
|
||||
m.template('db/seeds/seed.rb', 'db/seeds/refinerycms_blog.rb')
|
||||
|
||||
m.migration_template('migration.rb', 'db/migrate',
|
||||
m.migration_template('db/migrate/migration.rb', 'db/migrate',
|
||||
:migration_file_name => 'create_blog_structure',
|
||||
:assigns => {
|
||||
:migration_name => 'CreateBlogStructure',
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
class Create<%= singular_name.camelize %> < ActiveRecord::Migration
|
||||
|
||||
def self.up<% @refinerycms_blog_tables.each do |table| %>
|
||||
create_table :<%= table[:table_name] %>, :id => <%= table[:id].to_s %> do |t|
|
||||
<% table[:attributes].each do |attribute| -%>
|
||||
t.<%= attribute.type %> :<%= attribute.name %>
|
||||
<% end -%>
|
||||
<%= 't.timestamps' if table[:id] %>
|
||||
end
|
||||
|
||||
<%= "add_index :#{table[:table_name]}, :id" if table[:id] %>
|
||||
<% end -%>
|
||||
load(Rails.root.join('db', 'seeds', 'refinerycms_blog.rb').to_s)
|
||||
end
|
||||
|
||||
def self.down
|
||||
UserPlugin.destroy_all({:name => "refinerycms_blog"})
|
||||
|
||||
Page.delete_all({:link_url => "/blog"})
|
||||
|
||||
<% @refinerycms_blog_tables.each do |table| -%>
|
||||
drop_table :<%= table[:table_name] %>
|
||||
<% end -%>
|
||||
end
|
||||
|
||||
end
|
16
lib/generators/refinery_blog/templates/db/seeds/seed.rb
Normal file
16
lib/generators/refinery_blog/templates/db/seeds/seed.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
User.find(:all).each do |user|
|
||||
user.plugins.create(:name => "<%= singular_name %>",
|
||||
:position => (user.plugins.maximum(:position) || -1) +1)
|
||||
end
|
||||
|
||||
page = Page.create(
|
||||
:title => "Blog",
|
||||
:link_url => "/blog",
|
||||
:deletable => false,
|
||||
:position => ((Page.maximum(:position, :conditions => {:parent_id => nil}) || -1)+1),
|
||||
:menu_match => "^/blogs?(\/|\/.+?|)$"
|
||||
)
|
||||
|
||||
Page.default_parts.each do |default_page_part|
|
||||
page.parts.create(:title => default_page_part, :body => nil)
|
||||
end
|
79
lib/generators/refinery_blog_generator.rb
Normal file
79
lib/generators/refinery_blog_generator.rb
Normal file
|
@ -0,0 +1,79 @@
|
|||
require 'rails/generators/migration'
|
||||
|
||||
class RefineryBlogGenerator < Rails::Generators::NamedBase
|
||||
include Rails::Generators::Migration
|
||||
|
||||
source_root File.expand_path('../refinery_blog/templates/', __FILE__)
|
||||
argument :name, :type => :string, :default => 'blog_structure', :banner => ''
|
||||
|
||||
def generate
|
||||
# seed file
|
||||
template 'db/seeds/seed.rb', Rails.root.join('db/seeds/refinerycms_blog.rb')
|
||||
|
||||
# migration file
|
||||
@refinerycms_blog_tables = [{
|
||||
:table_name => 'blog_posts',
|
||||
:attributes => [
|
||||
Rails::Generators::GeneratedAttribute.new('title', 'string'),
|
||||
Rails::Generators::GeneratedAttribute.new('body', 'text'),
|
||||
Rails::Generators::GeneratedAttribute.new('draft', 'boolean')
|
||||
], :id => true
|
||||
},{
|
||||
:table_name => 'blog_comments',
|
||||
:attributes => [
|
||||
Rails::Generators::GeneratedAttribute.new('blog_post_id', 'integer'),
|
||||
Rails::Generators::GeneratedAttribute.new('spam', 'boolean'),
|
||||
Rails::Generators::GeneratedAttribute.new('name', 'string'),
|
||||
Rails::Generators::GeneratedAttribute.new('email', 'string'),
|
||||
Rails::Generators::GeneratedAttribute.new('body', 'text'),
|
||||
Rails::Generators::GeneratedAttribute.new('state', 'string'),
|
||||
], :id => true
|
||||
},{
|
||||
:table_name => 'blog_categories',
|
||||
:attributes => [
|
||||
Rails::Generators::GeneratedAttribute.new('title', 'string')
|
||||
], :id => true
|
||||
},{
|
||||
:table_name => 'blog_categories_blog_posts',
|
||||
:attributes => [
|
||||
Rails::Generators::GeneratedAttribute.new('blog_category_id', 'integer'),
|
||||
Rails::Generators::GeneratedAttribute.new('blog_post_id', 'integer')
|
||||
], :id => false
|
||||
}]
|
||||
next_migration_number = ActiveRecord::Generators::Base.next_migration_number(File.dirname(__FILE__))
|
||||
template('db/migrate/migration_number_create_singular_name.rb',
|
||||
Rails.root.join("db/migrate/#{next_migration_number}_create_#{singular_name}.rb"))
|
||||
|
||||
puts "------------------------"
|
||||
puts "Now run:"
|
||||
puts "rake db:migrate"
|
||||
puts "------------------------"
|
||||
end
|
||||
end
|
||||
|
||||
# Below is a hack until this issue:
|
||||
# https://rails.lighthouseapp.com/projects/8994/tickets/3820-make-railsgeneratorsmigrationnext_migration_number-method-a-class-method-so-it-possible-to-use-it-in-custom-generators
|
||||
# is fixed on the Rails project.
|
||||
|
||||
require 'rails/generators/named_base'
|
||||
require 'rails/generators/migration'
|
||||
require 'rails/generators/active_model'
|
||||
require 'active_record'
|
||||
|
||||
module ActiveRecord
|
||||
module Generators
|
||||
class Base < Rails::Generators::NamedBase #:nodoc:
|
||||
include Rails::Generators::Migration
|
||||
|
||||
# Implement the required interface for Rails::Generators::Migration.
|
||||
def self.next_migration_number(dirname) #:nodoc:
|
||||
next_migration_number = current_migration_number(dirname) + 1
|
||||
if ActiveRecord::Base.timestamped_migrations
|
||||
[Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max
|
||||
else
|
||||
"%.3d" % next_migration_number
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -21,12 +21,28 @@ module Refinery
|
|||
:class => BlogPost
|
||||
}
|
||||
end
|
||||
|
||||
# refinery 0.9.8 had a bug that we later found through using this engine.
|
||||
# the bug was that the plugin urls were not :controller => '/admin/whatever'
|
||||
if Refinery.version == '0.9.8'
|
||||
::Refinery::Plugin.class_eval %{
|
||||
alias_method :old_url, :url
|
||||
|
||||
def url
|
||||
if (plugin_url = self.old_url).is_a?(Hash) and plugin_url[:controller] =~ %r{^admin}
|
||||
plugin_url[:controller] = "/\#{plugin_url[:controller]}"
|
||||
end
|
||||
|
||||
plugin_url
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
end if defined?(Rails::Engine)
|
||||
|
||||
class << self
|
||||
def version
|
||||
%q{1.0.rc3}
|
||||
%q{1.0.rc4}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
$(document).ready(function(){
|
||||
$('nav#actions.multilist > ul:not(.search_list) li a[href$=' + window.location.pathname + ']')
|
||||
.parent().addClass('selected');
|
||||
if($('nav#actions.multilist > ul:not(.search_list) li.selected').length == 0) {
|
||||
$('nav#actions.multilist > ul:not(.search_list) li a:nth(1)').parent().addClass('selected');
|
||||
}
|
||||
|
||||
$('nav#actions.multilist > ul:not(.search_list) li > a').each(function(i,a){
|
||||
if ($(this).data('dialog-title') == null) {
|
||||
|
@ -16,7 +19,7 @@ $(document).ready(function(){
|
|||
div.hide();
|
||||
}
|
||||
$(this).children('li:not(:first)').appendTo(div);
|
||||
|
||||
|
||||
first_li.find('> a').click(function(e){
|
||||
$(this).parent().next('div').animate({
|
||||
opacity: 'toggle'
|
||||
|
@ -32,8 +35,8 @@ $(document).ready(function(){
|
|||
$('.success_icon, .failure_icon').bind('click', function(e) {
|
||||
$.get($(this).attr('href'), $.proxy(function(data){
|
||||
$(this).css('background-image', null)
|
||||
.toggleClass('success_icon')
|
||||
.toggleClass('failure_icon');
|
||||
.removeClass('failure_icon').removeClass('success_icon')
|
||||
.addClass(data.enabled ? 'success_icon' : 'failure_icon');
|
||||
}, $(this)));
|
||||
e.preventDefault();
|
||||
});
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
Gem::Specification.new do |s|
|
||||
s.name = %q{refinerycms-blog}
|
||||
s.version = %q{1.0.rc3}
|
||||
s.version = %q{1.0.rc4}
|
||||
s.description = %q{A really straightforward open source Ruby on Rails blog engine designed for integration with RefineryCMS.}
|
||||
s.date = %q{2010-09-03}
|
||||
s.summary = %q{Ruby on Rails blogging engine for RefineryCMS.}
|
||||
|
@ -69,10 +69,22 @@ Gem::Specification.new do |s|
|
|||
generators/refinery_blog
|
||||
generators/refinery_blog/refinery_blog_generator.rb
|
||||
generators/refinery_blog/templates
|
||||
generators/refinery_blog/templates/migration.rb
|
||||
generators/refinery_blog/templates/seed.rb
|
||||
generators/refinery_blog/templates/db
|
||||
generators/refinery_blog/templates/db/migrate
|
||||
generators/refinery_blog/templates/db/migrate/migration.rb
|
||||
generators/refinery_blog/templates/db/seeds
|
||||
generators/refinery_blog/templates/db/seeds/seed.rb
|
||||
lib
|
||||
lib/gemspec.rb
|
||||
lib/generators
|
||||
lib/generators/refinery_blog
|
||||
lib/generators/refinery_blog/templates
|
||||
lib/generators/refinery_blog/templates/db
|
||||
lib/generators/refinery_blog/templates/db/migrate
|
||||
lib/generators/refinery_blog/templates/db/migrate/migration_number_create_singular_name.rb
|
||||
lib/generators/refinery_blog/templates/db/seeds
|
||||
lib/generators/refinery_blog/templates/db/seeds/seed.rb
|
||||
lib/generators/refinery_blog_generator.rb
|
||||
lib/refinerycms-blog.rb
|
||||
public
|
||||
public/images
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue