Permalink
Browse files

Hello rails3 support.

  • Loading branch information...
1 parent c4222bf commit a2f655b55eb30a900020e8aff9601ed0606ce58f @parndt parndt committed Sep 3, 2010
@@ -16,7 +16,7 @@ def notification_recipients
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 @@ def show
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
View
@@ -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 @@ module Moderation
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 @@ def toggle
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
View
@@ -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">&nbsp;</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 %>
View
@@ -8,17 +8,17 @@
map.namespace(:admin, :path_prefix => 'refinery') do |admin|
admin.namespace :blog do |blog|
blog.resources :posts
-
+
blog.resources :categories
-
+
blog.resources :comments, :collection => {
:approved => :get,
:rejected => :get
}, :member => {
:approved => :get,
:rejected => :get
}
-
+
blog.resources :settings, :collection => {
:notification_recipients => [:get, :post],
:moderation => :get
@@ -27,5 +27,40 @@
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 @@ def banner
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
@@ -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
Oops, something went wrong.

0 comments on commit a2f655b

Please sign in to comment.