<%= f.label :title -%>
<%= f.text_field :title, :class => 'larger widest' -%>
diff --git a/app/views/admin/blog/comments/_comment.html.erb b/app/views/admin/blog/comments/_comment.html.erb
index 3435c75..52a8167 100644
--- a/app/views/admin/blog/comments/_comment.html.erb
+++ b/app/views/admin/blog/comments/_comment.html.erb
@@ -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? %>
diff --git a/app/views/admin/blog/posts/_form.html.erb b/app/views/admin/blog/posts/_form.html.erb
index f6f332f..bf964e9 100644
--- a/app/views/admin/blog/posts/_form.html.erb
+++ b/app/views/admin/blog/posts/_form.html.erb
@@ -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 %>
<%= f.label :title -%>
diff --git a/app/views/admin/blog/posts/_post.html.erb b/app/views/admin/blog/posts/_post.html.erb
index 3e15543..a768279 100644
--- a/app/views/admin/blog/posts/_post.html.erb
+++ b/app/views/admin/blog/posts/_post.html.erb
@@ -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) %>
diff --git a/app/views/blog_posts/show.html.erb b/app/views/blog_posts/show.html.erb
index 57b2f92..9e3cf4d 100644
--- a/app/views/blog_posts/show.html.erb
+++ b/app/views/blog_posts/show.html.erb
@@ -35,7 +35,21 @@
<% if BlogPost.comments_allowed? %>
+ <% flash.each do |key, value| %>
+
+ <%= value %>
+
+ <% 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 %>
<%= f.label :name %>
<%= f.text_field :name %>
diff --git a/config/routes.rb b/config/routes.rb
index ce4a2ef..70406de 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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
\ No newline at end of file
diff --git a/generators/refinery_blog/refinery_blog_generator.rb b/generators/refinery_blog/refinery_blog_generator.rb
index 2bf39d8..076f709 100644
--- a/generators/refinery_blog/refinery_blog_generator.rb
+++ b/generators/refinery_blog/refinery_blog_generator.rb
@@ -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',
diff --git a/generators/refinery_blog/templates/migration.rb b/generators/refinery_blog/templates/db/migrate/migration.rb
similarity index 100%
rename from generators/refinery_blog/templates/migration.rb
rename to generators/refinery_blog/templates/db/migrate/migration.rb
diff --git a/generators/refinery_blog/templates/seed.rb b/generators/refinery_blog/templates/db/seeds/seed.rb
similarity index 100%
rename from generators/refinery_blog/templates/seed.rb
rename to generators/refinery_blog/templates/db/seeds/seed.rb
diff --git a/lib/generators/refinery_blog/templates/db/migrate/migration_number_create_singular_name.rb b/lib/generators/refinery_blog/templates/db/migrate/migration_number_create_singular_name.rb
new file mode 100644
index 0000000..badb213
--- /dev/null
+++ b/lib/generators/refinery_blog/templates/db/migrate/migration_number_create_singular_name.rb
@@ -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
diff --git a/lib/generators/refinery_blog/templates/db/seeds/seed.rb b/lib/generators/refinery_blog/templates/db/seeds/seed.rb
new file mode 100644
index 0000000..72648d3
--- /dev/null
+++ b/lib/generators/refinery_blog/templates/db/seeds/seed.rb
@@ -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
diff --git a/lib/generators/refinery_blog_generator.rb b/lib/generators/refinery_blog_generator.rb
new file mode 100644
index 0000000..db2e2ef
--- /dev/null
+++ b/lib/generators/refinery_blog_generator.rb
@@ -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
\ No newline at end of file
diff --git a/lib/refinerycms-blog.rb b/lib/refinerycms-blog.rb
index 1235d60..3fd844e 100644
--- a/lib/refinerycms-blog.rb
+++ b/lib/refinerycms-blog.rb
@@ -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
diff --git a/public/javascripts/refinery/refinerycms-blog.js b/public/javascripts/refinery/refinerycms-blog.js
index 0159655..c92ba3e 100644
--- a/public/javascripts/refinery/refinerycms-blog.js
+++ b/public/javascripts/refinery/refinerycms-blog.js
@@ -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();
});
diff --git a/refinerycms-blog.gemspec b/refinerycms-blog.gemspec
index 3b3ed0f..151b4a6 100644
--- a/refinerycms-blog.gemspec
+++ b/refinerycms-blog.gemspec
@@ -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