Permalink
Browse files

Now compliant with rails3 with RefineryCMS >= 0.9.8, can no longer us…

…e it in rails2 < Refinery CMS 0.9.8.
  • Loading branch information...
1 parent 5e43371 commit 2e782dae9b20f48bd67a39d65acdea4bcec36093 @parndt parndt committed Sep 9, 2010
View
@@ -11,8 +11,8 @@ class NewsItem < ActiveRecord::Base
# If you're using a named scope that includes a changing variable you need to wrap it in a lambda
# This avoids the query being cached thus becoming unaffected by changes (i.e. Time.now is constant)
- named_scope :latest, lambda { |*limit| { :conditions => ["publish_date < ?", Time.now], :limit => (limit.first || 10) } }
- named_scope :published, lambda { { :conditions => ["publish_date < ?", Time.now] } }
+ scope :latest, lambda { |*limit| { :conditions => ["publish_date < ?", Time.now], :limit => (limit.first || 10) } }
+ scope :published, lambda { { :conditions => ["publish_date < ?", Time.now] } }
def not_published? # has the published date not yet arrived?
publish_date > Time.now
@@ -1,5 +1,9 @@
<% form_for [:admin, @news_item] do |f| %>
- <%= f.error_messages %>
+ <%= render :partial => "/shared/admin/error_messages",
+ :locals => {
+ :object => @news_item,
+ :include_object_name => true
+ } %>
<div class='field'>
<%= f.label :title %>
@@ -19,7 +23,9 @@
<%= render :partial => "/shared/admin/form_actions",
:locals => {
:f => f,
- :continue_editing => true
+ :continue_editing => true,
+ :delete_title => t('admin.news_items.news_item.delete'),
+ :delete_confirmation => t('shared.admin.delete.message', :title => @news_item.title)
} %>
<% end %>
@@ -11,6 +11,8 @@
:title => t('.edit') %>
<%= link_to refinery_icon_tag('delete.png'), admin_news_item_path(news_item),
:class => "cancel confirm-delete",
- :title => t('.delete') %>
+ :title => t('.delete'),
+ :'data-method' => :delete,
+ :'data-confirm' => t('shared.admin.delete.message', :title => news_item.title) %>
</span>
</li>
@@ -1,9 +1,9 @@
-<% content_for :body_content_title, "<h1>#{@news_item.title}</h1>" %>
+<% content_for :body_content_title, @news_item.title %>
<% content_for :body_content_left do %>
<p>
<small><%= t('.published') %> <%= l(@news_item.publish_date, :format => :long) %></small>
</p>
- <%= @news_item.body %>
+ <%= @news_item.body.html_safe %>
<p>
<%= link_to t('.back_to_index'), news_items_url %>
</p>
View
@@ -1,7 +1,8 @@
en:
plugins:
- news:
+ refinerycms_news:
title: News
+ description: Provides a blog-like news section
admin:
news_items:
news_item:
View
@@ -1,7 +1,7 @@
-ActionController::Routing::Routes.draw do |map|
- map.resources :news_items, :as => :news
+Refinery::Application.routes.draw do
+ resources :news, :as => :news_items, :controller => :news_items
- map.namespace(:admin, :path_prefix => (defined?(REFINERY_GEM_VERSION) ? 'admin' : 'refinery')) do |admin|
- admin.resources :news_items, :as => :news
+ scope(:path => 'refinery', :as => 'admin', :module => 'admin') do
+ resources :news, :as => :news_items, :controller => :news_items
end
-end
+end
@@ -1,29 +0,0 @@
-class NewsGenerator < Rails::Generator::NamedBase
-
- def initialize(*runtime_args)
- # set first argument to the table's name so that the user doesn't have to pass it in.
- runtime_args[0] = ["news_items"]
- super(*runtime_args)
- end
-
- def banner
- "Usage: script/generate news"
- end
-
- def manifest
- record do |m|
- m.migration_template 'migration.rb', 'db/migrate',
- :migration_file_name => "create_structure_for_news",
- :assigns => {
- :migration_name => "CreateStructureForNews",
- :table_name => "news_items",
- :attributes => [
- Rails::Generator::GeneratedAttribute.new("title", "string"),
- Rails::Generator::GeneratedAttribute.new("body", "text"),
- Rails::Generator::GeneratedAttribute.new("publish_date", "datetime")
- ]
- }
- end
- end
-
-end if defined?(Rails::Generator::NamedBase)
@@ -1,42 +0,0 @@
-class <%= migration_name %> < ActiveRecord::Migration
-
- def self.up
- create_table :<%= table_name %> do |t|
-<% attributes.each do |attribute| -%>
- t.<%= attribute.type %> :<%= attribute.name %>
-<% end -%>
- t.timestamps
- end
-
- add_index :<%= table_name %>, :id
-
- User.find(:all).each do |user|
- user.plugins.create(:name => "News", :position => (user.plugins.maximum(:position) || -1) + 1)
- end
-
- page = Page.create(:title => "News",
- :link_url => "/news",
- :menu_match => "^/news.*$",
- :deletable => false,
- :position => Page.count)
-
- RefinerySetting.find_or_set(:default_page_parts, ["Body", "Side Body"]).each do |default_page_part|
- page.parts.create(:title => default_page_part, :body => nil)
- end
-
- end
-
- def self.down
- UserPlugin.destroy_all({:title => "News"})
-
- Page.find_all_by_link_url("/news").each do |page|
- page.link_url, page.menu_match = nil
- page.deletable = true
- page.destroy
- end
- Page.destroy_all({:link_url => "/news"})
-
- drop_table :<%= table_name %>
- end
-
-end
View
@@ -18,6 +18,8 @@
s.authors = %w(Resolve\\ Digital)
s.require_paths = %w(lib)
+ s.add_dependency 'refinerycms', '~> 0.9.8'
+
s.files = [
'#{files.join("',\n '")}'
]
@@ -0,0 +1,23 @@
+class Create<%= table_name.camelize %> < ActiveRecord::Migration
+
+ def self.up
+ create_table :<%= table_name %>, :id => true do |t|
+<% attributes.each do |attribute| -%>
+ t.<%= attribute.type %> :<%= attribute.name %>
+<% end -%>
+ t.timestamps
+ end
+
+ add_index :<%= table_name %>, :id
+ load(Rails.root.join('db', 'seeds', 'refinerycms_news.rb').to_s)
+ end
+
+ def self.down
+ UserPlugin.destroy_all({:name => "refinerycms_news"})
+
+ Page.delete_all({:link_url => "/news"})
+
+ drop_table :<%= table_name %>
+ end
+
+end
@@ -0,0 +1,16 @@
+User.find(:all).each do |user|
+ user.plugins.create(:name => "refinerycms_news",
+ :position => (user.plugins.maximum(:position) || -1) +1)
+end
+
+page = Page.create(
+ :title => "News",
+ :link_url => "/news",
+ :deletable => false,
+ :position => ((Page.maximum(:position, :conditions => {:parent_id => nil}) || -1)+1),
+ :menu_match => "^/news.*$"
+)
+
+Page.default_parts.each do |default_page_part|
+ page.parts.create(:title => default_page_part, :body => nil)
+end
@@ -0,0 +1,50 @@
+require 'rails/generators/migration'
+
+class RefinerycmsNewsGenerator < Rails::Generators::NamedBase
+ include Rails::Generators::Migration
+
+ source_root File.expand_path('../refinerycms_news/templates/', __FILE__)
+ argument :name, :type => :string, :default => 'news_items', :banner => ''
+ argument :attributes, :type => :array, :default => ["title:string", "body:text", "publish_date:datetime"]
+
+ def generate
+ # seed file
+ template 'db/seeds/seed.rb', Rails.root.join('db/seeds/refinerycms_news.rb')
+
+ 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
View
@@ -2,7 +2,7 @@ module Refinery
module News
class << self
def version
- %q{0.9.8.4}
+ %q{0.9.9}
end
end
end
View
@@ -0,0 +1,23 @@
+require 'refinery'
+require File.expand_path('../news', __FILE__)
+
+module Refinery
+ module News
+
+ class Engine < Rails::Engine
+ config.after_initialize do
+ Refinery::Plugin.register do |plugin|
+ plugin.name = "refinerycms_news"
+ plugin.menu_match = /(admin|refinery)\/news(_items)?$/
+ plugin.url = {:controller => '/admin/news_items', :action => 'index'}
+ plugin.activity = {
+ :class => NewsItem,
+ :title => 'title',
+ :url_prefix => 'edit'
+ }
+ end
+ end
+ end
+
+ end
+end
View
@@ -1,14 +0,0 @@
-Refinery::Plugin.register do |plugin|
- plugin.title = "News"
- plugin.name = "news"
- plugin.description = "Provides a blog-like news section"
- plugin.version = 1.0
- plugin.menu_match = /(admin|refinery)\/news(_items)?$/
- plugin.url = '/refinery/news'
- plugin.activity = {
- :class => NewsItem,
- :title => 'title',
- :url_prefix => 'edit'
- }
- plugin.directory = directory
-end
View
@@ -17,27 +17,18 @@ To install the news engine, you can either include the gem or install as a plugi
## Requirements
-[RefineryCMS](http://refinerycms.com) version 0.9.6 or later.
+[RefineryCMS](http://refinerycms.com) version 0.9.8 or later.
-### Gem Installation using Bundler
+### Gem Installation using Bundler (The very best way)
Include the latest [gem](http://rubygems.org/gems/refinerycms-news) into your Refinery CMS application's Gemfile:
- gem "refinerycms-news", '~> 0.9.8.4', :require => "news"
+ gem "refinerycms-news", '~> 0.9.9'
Then type the following at command line inside your Refinery CMS application's root directory:
bundle install
- script/generate news
- rake db:migrate
-
-### Rails Engine Installation
-
-If you do not want to install the engine via bundler then you can install it as an engine inside your application's vendor directory.
-Type the following at command line inside your Refinery CMS application's root directory:
-
- script/plugin install git://github.com/resolve/refinerycms-news.git
- script/generate news
+ rails generate refinerycms_news
rake db:migrate
## RSS (Really Simple Syndication)
View
@@ -1,14 +1,16 @@
Gem::Specification.new do |s|
s.name = %q{refinerycms-news}
- s.version = %q{0.9.8.4}
+ s.version = %q{0.9.9}
s.description = %q{A really straightforward open source Ruby on Rails news engine designed for integration with RefineryCMS.}
- s.date = %q{2010-08-31}
+ s.date = %q{2010-09-09}
s.summary = %q{Ruby on Rails news engine for RefineryCMS.}
s.email = %q{info@refinerycms.com}
s.homepage = %q{http://refinerycms.com}
s.authors = %w(Resolve\ Digital)
s.require_paths = %w(lib)
+ s.add_dependency 'refinerycms', '~> 0.9.8'
+
s.files = [
'app',
'app/controllers',
@@ -35,18 +37,22 @@ Gem::Specification.new do |s|
'config/locales/en.yml',
'config/locales/nl.yml',
'config/locales/pt-BR.yml',
+ 'config/locales/ru.yml',
'config/routes.rb',
- 'generators',
- 'generators/news',
- 'generators/news/news_generator.rb',
- 'generators/news/templates',
- 'generators/news/templates/migration.rb',
'lib',
'lib/gemspec.rb',
+ 'lib/generators',
+ 'lib/generators/refinerycms_news',
+ 'lib/generators/refinerycms_news/templates',
+ 'lib/generators/refinerycms_news/templates/db',
+ 'lib/generators/refinerycms_news/templates/db/migrate',
+ 'lib/generators/refinerycms_news/templates/db/migrate/migration_number_create_singular_name.rb',
+ 'lib/generators/refinerycms_news/templates/db/seeds',
+ 'lib/generators/refinerycms_news/templates/db/seeds/seed.rb',
+ 'lib/generators/refinerycms_news_generator.rb',
'lib/news.rb',
+ 'lib/refinerycms-news.rb',
'license.md',
- 'rails',
- 'rails/init.rb',
'readme.md',
'test',
'test/fixtures',

0 comments on commit 2e782da

Please sign in to comment.