Browse files

Merge remote-tracking branch 'enmasse-entertainment/decorators'

  • Loading branch information...
2 parents a2b8066 + d92aab9 commit 0069c1a79f94dbf9ac364671cd7776254b097479 @parndt parndt committed Sep 21, 2011
View
26 core/lib/generators/cms_generator.rb
@@ -14,7 +14,7 @@ def generate
self.silence_puts = true
# Only pretend to do the next actions if this is Refinery to stay DRY
- if Rails.root == Refinery.root
+ if destination_path == Refinery.root
say_status :'-- pretending to make changes that happen in an actual installation --', nil, :yellow
old_pretend = self.options[:pretend]
new_options = self.options.dup
@@ -25,7 +25,7 @@ def generate
unless self.options[:update]
# First, effectively move / rename files that get in the way of Refinery CMS
%w(public/index.html app/views/layouts/application.html.erb).each do |roadblock|
- if (roadblock_path = Rails.root.join(roadblock)).file?
+ if (roadblock_path = destination_path.join(roadblock)).file?
create_file "#{roadblock}.backup",
:verbose => true do roadblock_path.read end
remove_file roadblock_path, :verbose => true
@@ -35,9 +35,11 @@ def generate
# Massage environment files
%w(development test production).map{|e| "config/environments/#{e}.rb"}.each do |env|
+ next unless destination_path.join(env).file?
+
gsub_file env, "config.assets.compile = false", "config.assets.compile = true", :verbose => false
- unless (env_file_contents = Rails.root.join(env).read) =~ %r{Refinery.rescue_not_found}
+ unless (env_file_contents = destination_path.join(env).read) =~ %r{Refinery.rescue_not_found}
append_file env, "Refinery.rescue_not_found = #{env.split('/').last.split('.rb').first == 'production'}\n"
end
@@ -50,21 +52,21 @@ def generate
end
# Stop pretending
- if Rails.root == Refinery.root
+ if destination_path == Refinery.root
say_status :'-- finished pretending --', nil, :yellow
new_options = self.options.dup
new_options[:pretend] = old_pretend
self.options = new_options
end
# Ensure .gitignore exists and append our rules to it.
- create_file ".gitignore" unless Rails.root.join('.gitignore').file?
+ create_file ".gitignore" unless destination_path.join('.gitignore').file?
our_ignore_rules = self.class.source_root.join('.gitignore').read
- our_ignore_rules = our_ignore_rules.split('# REFINERY CMS DEVELOPMENT').first if Rails.root != Refinery.root
+ our_ignore_rules = our_ignore_rules.split('# REFINERY CMS DEVELOPMENT').first if destination_path != Refinery.root
append_file ".gitignore", our_ignore_rules
# If the admin/base_controller.rb file exists, ensure it does not do the old inheritance
- if (admin_base = Rails.root.join('app', 'controllers', 'refinery', 'admin_controller.rb')).file?
+ if (admin_base = destination_path.join('app', 'controllers', 'refinery', 'admin_controller.rb')).file?
gsub_file admin_base,
"# You can extend refinery backend with your own functions here and they will likely not get overriden in an update.",
"",
@@ -75,7 +77,7 @@ def generate
end
# Append seeds.
- create_file "db/seeds.rb" unless Rails.root.join('db', 'seeds.rb').file?
+ create_file "db/seeds.rb" unless destination_path.join('db', 'seeds.rb').file?
append_file 'db/seeds.rb', :verbose => true do
self.class.source_root.join('db', 'seeds.rb').read
end
@@ -97,7 +99,13 @@ def generate
Pathname.glob(self.class.source_root.join('**', '*')).reject{|f|
f.directory? or f.to_s =~ /\/db\//
}.sort.each do |path|
- copy_file path, path.to_s.gsub(self.class.source_root.to_s, Rails.root.to_s)
+ copy_file path, path.to_s.gsub(self.class.source_root.to_s, destination_path.to_s)
+ end
+
+ # Create decorator directories
+ ['controllers', 'models'].each do |decorator_namespace|
+ src_file_path = "app/decorators/#{decorator_namespace}/refinery/.gitkeep"
+ copy_file self.class.source_root.join(src_file_path), destination_path.join(src_file_path)
end
# Ensure i18n exists and is up to date.
View
0 core/lib/generators/templates/app/decorators/controllers/refinery/.gitkeep
No changes.
View
0 core/lib/generators/templates/app/decorators/models/refinery/.gitkeep
No changes.
View
90 core/lib/refinery/core/engine.rb
@@ -0,0 +1,90 @@
+module Refinery
+ module Core
+ class Engine < ::Rails::Engine
+ isolate_namespace ::Refinery
+
+ def self.load_decorators
+ Dir.glob(File.join(Rails.root, "app/decorators/**/*_decorator.rb")) do |c|
+ Rails.application.config.cache_classes ? require(c) : load(c)
+ end
+ end
+
+ config.autoload_paths += %W( #{config.root}/lib )
+
+ # Attach ourselves to the Rails application.
+ config.before_configuration do
+ ::Refinery::Core.attach_to_application!
+ end
+
+ refinery.after_inclusion &method(:load_decorators).to_proc
+
+ # Wrap errors in spans and cache vendored assets.
+ config.to_prepare do
+ # This wraps errors in span not div
+ ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
+ "<span class=\"fieldWithErrors\">#{html_tag}</span>".html_safe
+ end
+ end
+
+ # set per_page globally
+ config.to_prepare do
+ WillPaginate.per_page = 20
+ end
+
+ # Register the plugin
+ config.after_initialize do
+ ::Refinery::Plugin.register do |plugin|
+ plugin.pathname = root
+ plugin.name = 'refinery_core'
+ plugin.class_name = 'RefineryEngine'
+ plugin.version = ::Refinery.version
+ plugin.hide_from_menu = true
+ plugin.always_allow_access = true
+ plugin.menu_match = /refinery\/(refinery_core)$/
+ end
+
+ # Register the dialogs plugin
+ ::Refinery::Plugin.register do |plugin|
+ plugin.pathname = root
+ plugin.name = 'refinery_dialogs'
+ plugin.version = ::Refinery.version
+ plugin.hide_from_menu = true
+ plugin.always_allow_access = true
+ plugin.menu_match = /refinery\/(refinery_)?dialogs/
+ end
+ end
+
+ initializer 'add catch all routes' do |app|
+ app.routes_reloader.paths << File.expand_path('../../catch_all_routes.rb', __FILE__)
+ end
+
+ initializer 'add presenters' do |app|
+ app.config.autoload_paths += [
+ Rails.root.join('app', 'presenters'),
+ Rails.root.join('vendor', '**', '**', 'app', 'presenters'),
+ Refinery.roots.map{|r| r.join('**', 'app', 'presenters')}
+ ].flatten
+ end
+
+ initializer 'configure acts_as_indexed' do |app|
+ ActsAsIndexed.configure do |config|
+ config.index_file = Rails.root.join('tmp', 'index')
+ config.index_file_depth = 3
+ config.min_word_size = 3
+ end
+ end
+
+ initializer "refinery.assets.precompile" do |app|
+ app.config.assets.precompile += [
+ "refinery/*",
+ "refinery/icons/*",
+ "wymeditor/lang/*",
+ "wymeditor/skins/refinery/*",
+ "wymeditor/skins/refinery/**/*",
+ "modernizr-min.js",
+ "dd_belatedpng.js"
+ ]
+ end
+ end
+ end
+end
View
81 core/lib/refinerycms-core.rb
@@ -56,87 +56,8 @@ def root
end
::Rails::Engine.send :include, ::Refinery::Engine
-
- class Engine < ::Rails::Engine
- isolate_namespace ::Refinery
-
- config.autoload_paths += %W( #{config.root}/lib )
-
- # Attach ourselves to the Rails application.
- config.before_configuration do
- ::Refinery::Core.attach_to_application!
- end
-
- # Wrap errors in spans and cache vendored assets.
- config.to_prepare do
- # This wraps errors in span not div
- ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
- "<span class=\"fieldWithErrors\">#{html_tag}</span>".html_safe
- end
- end
-
- # set per_page globally
- config.to_prepare do
- WillPaginate.per_page = 20
- end
-
- # Register the plugin
- config.after_initialize do
- ::Refinery::Plugin.register do |plugin|
- plugin.pathname = root
- plugin.name = 'refinery_core'
- plugin.class_name = 'RefineryEngine'
- plugin.version = ::Refinery.version
- plugin.hide_from_menu = true
- plugin.always_allow_access = true
- plugin.menu_match = /refinery\/(refinery_core)$/
- end
-
- # Register the dialogs plugin
- ::Refinery::Plugin.register do |plugin|
- plugin.pathname = root
- plugin.name = 'refinery_dialogs'
- plugin.version = ::Refinery.version
- plugin.hide_from_menu = true
- plugin.always_allow_access = true
- plugin.menu_match = /refinery\/(refinery_)?dialogs/
- end
- end
-
- initializer 'add catch all routes' do |app|
- app.routes_reloader.paths << File.expand_path('../refinery/catch_all_routes.rb', __FILE__)
- end
-
- initializer 'add presenters' do |app|
- app.config.autoload_paths += [
- Rails.root.join('app', 'presenters'),
- Rails.root.join('vendor', '**', '**', 'app', 'presenters'),
- Refinery.roots.map{|r| r.join('**', 'app', 'presenters')}
- ].flatten
- end
-
- initializer 'configure acts_as_indexed' do |app|
- ActsAsIndexed.configure do |config|
- config.index_file = Rails.root.join('tmp', 'index')
- config.index_file_depth = 3
- config.min_word_size = 3
- end
- end
-
- initializer "refinery.assets.precompile" do |app|
- app.config.assets.precompile += [
- "refinery/*",
- "refinery/icons/*",
- "wymeditor/lang/*",
- "wymeditor/skins/refinery/*",
- "wymeditor/skins/refinery/**/*",
- "modernizr-min.js",
- "dd_belatedpng.js"
- ]
- end
- end
end
-
end
+require 'refinery/core/engine'
::Refinery.engines << 'core'
View
9 core/refinerycms-core.gemspec
@@ -360,6 +360,11 @@ Gem::Specification.new do |s|
'lib/generators/templates',
'lib/generators/templates/.gitignore',
'lib/generators/templates/app',
+ 'lib/generators/templates/app/decorators',
+ 'lib/generators/templates/app/decorators/controllers',
+ 'lib/generators/templates/app/decorators/controllers/refinery',
+ 'lib/generators/templates/app/decorators/models',
+ 'lib/generators/templates/app/decorators/models/refinery',
'lib/generators/templates/app/views',
'lib/generators/templates/app/views/sitemap',
'lib/generators/templates/app/views/sitemap/index.xml.builder',
@@ -384,6 +389,8 @@ Gem::Specification.new do |s|
'lib/refinery/base_presenter.rb',
'lib/refinery/catch_all_routes.rb',
'lib/refinery/configuration.rb',
+ 'lib/refinery/core',
+ 'lib/refinery/core/engine.rb',
'lib/refinery/crud.rb',
'lib/refinery/engine.rb',
'lib/refinery/helpers',
@@ -426,6 +433,8 @@ Gem::Specification.new do |s|
'spec/controllers/refinery/fast_controller_spec.rb',
'spec/controllers/refinery/sitemap_controller_spec.rb',
'spec/lib',
+ 'spec/lib/generators',
+ 'spec/lib/generators/cms_generator_spec.rb',
'spec/lib/refinery',
'spec/lib/refinery/activity_spec.rb',
'spec/lib/refinery/plugin_spec.rb',
View
49 core/spec/lib/generators/cms_generator_spec.rb
@@ -0,0 +1,49 @@
+require 'spec_helper'
+require "generator_spec/test_case"
+
+module Refinery
+ describe CmsGenerator do
+ include GeneratorSpec::TestCase
+ destination File.expand_path("../../tmp", __FILE__)
+
+ before(:each) do
+ prepare_destination
+ run_generator
+ end
+
+ specify do
+ destination_root.should have_structure {
+ directory "app" do
+ directory "decorators" do
+ directory "controllers" do
+ directory "refinery" do
+ file ".gitkeep"
+ end
+ end
+ directory "models" do
+ directory "refinery" do
+ file ".gitkeep"
+ end
+ end
+ end
+ directory "views" do
+ directory "sitemap" do
+ file "index.xml.builder"
+ end
+ end
+ end
+ directory "db" do
+ file "seeds.rb"
+ end
+ directory "config" do
+ file "database.yml.mysql"
+ file "database.yml.postgresql"
+ file "database.yml.sqlite3"
+ directory "initializers" do
+ file "devise.rb"
+ end
+ end
+ }
+ end
+ end
+end

0 comments on commit 0069c1a

Please sign in to comment.