Skip to content

Commit e56c4cb

Browse files
committedDec 18, 2013
Make engine generators work correctly.
`rails generate/destroy` now correctly place files in the engine rather than test/dummy. * Move dependencies loading to gem file (lib/browsercms) which avoids loading all of them during rails tasks.
1 parent 879860e commit e56c4cb

File tree

3 files changed

+50
-42
lines changed

3 files changed

+50
-42
lines changed
 

‎lib/browsercms.rb

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
1+
# Load all dependencies needed at boot time.
2+
require 'rails'
3+
require 'cms/configuration'
4+
require 'cms/version'
5+
require 'browsercms'
6+
7+
require 'bootstrap-sass'
8+
require 'compass-rails'
9+
10+
# Gem name is different than file name
11+
# Must be required FIRST, so that our assets paths appear before its do.
12+
# This allows app/assets/ckeditor/config.js to set CMS specific defaults.
13+
require 'ckeditor-rails'
14+
15+
# Explicitly require this, so that CMS projects do not need to add it to their Gemfile
16+
# especially while upgrading
17+
require 'jquery-rails'
18+
require 'jquery-ui-rails'
19+
20+
require 'underscore-rails'
21+
require 'will_paginate'
22+
require 'will_paginate/active_record'
23+
require 'actionpack/page_caching'
24+
require 'panoramic'
25+
require 'simple_form'
26+
require 'devise'
27+
128
require 'cms/engine'
229
require 'cms/extensions'
330
require 'cms/route_extensions'
@@ -38,4 +65,4 @@
3865
ActiveRecord::Base.send(:include, Cms::Acts::CmsUser)
3966
require 'cms/responders/content_responder'
4067

41-
require "panoramic"
68+
require "panoramic"

‎lib/cms/engine.rb

+1-26
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,7 @@
1-
require 'rails'
1+
# Load just enough dependencies for this file to be loadable.
22
require 'cms/module'
3-
require 'cms/configuration'
4-
require 'cms/version'
5-
require 'browsercms'
6-
7-
require 'bootstrap-sass'
8-
require 'compass-rails'
9-
10-
# Gem name is different than file name
11-
# Must be required FIRST, so that our assets paths appear before its do.
12-
# This allows app/assets/ckeditor/config.js to set CMS specific defaults.
13-
require 'ckeditor-rails'
14-
15-
# Explicitly require this, so that CMS projects do not need to add it to their Gemfile
16-
# especially while upgrading
17-
require 'jquery-rails'
18-
require 'jquery-ui-rails'
19-
20-
require 'underscore-rails'
21-
require 'will_paginate'
22-
require 'will_paginate/active_record'
23-
require 'actionpack/page_caching'
24-
require 'panoramic'
25-
require 'simple_form'
26-
require 'devise'
273

284
module Cms
29-
305
class Engine < Rails::Engine
316
include Cms::Module
327
isolate_namespace Cms

‎script/rails

+21-15
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
#!/usr/bin/env ruby
2-
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
32

4-
ENGINE_PATH = File.expand_path('../..', __FILE__)
5-
load File.expand_path('../../test/dummy/script/rails', __FILE__)
3+
#This is standard Rails 4 Engine commands behavior.
4+
ENGINE_ROOT = File.expand_path('../..', __FILE__)
5+
ENGINE_PATH = File.expand_path('../../lib/cms/engine', __FILE__)
66

7+
# Modified the core `rails` script so that commands other than generate/destroy work in context of the test/dummy app.
78

8-
# Rails 3.2.2 generates the following instead, but you only get access to:
9-
# - rails generate
10-
# - rails destroy
11-
# I kept the above (for now anyway) so I can get access to rails server, though I will need to test that it works for other commands too.
9+
ARGV << '--help' if ARGV.empty?
1210

13-
# Bugs: Adding the following would:
14-
# 1. Enable generators to work correctly (right now they put code into test/dummy)
15-
# 2. Prevent loading, since engine requires other files directly.
11+
aliases = {
12+
"g" => "generate",
13+
"d" => "destroy"
14+
}
1615

17-
#ENGINE_ROOT = File.expand_path('../..', __FILE__)
18-
#ENGINE_PATH = File.expand_path('../../lib/cms/engine', __FILE__)
19-
##
20-
#require 'rails/all'
21-
#require 'rails/engine/commands'
16+
command = ARGV.first
17+
command = aliases[command] || command
18+
19+
case command
20+
when 'generate', 'destroy'
21+
require 'rails/all'
22+
require 'rails/engine/commands'
23+
else
24+
# Commands like 'server' and 'console' will use test/dummy's rails script.
25+
load File.expand_path('../../test/dummy/script/rails', __FILE__)
26+
27+
end

0 commit comments

Comments
 (0)