1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Add --mountable option to 'plugin new' generator which generates full mountable application (engine)

This commit is contained in:
Piotr Sarnacki 2010-11-02 16:34:07 +01:00
parent c159b501b0
commit cbe391b517
7 changed files with 52 additions and 3 deletions

View file

@ -7,6 +7,10 @@ module Rails
template "Rakefile"
end
def app
directory "app" if options[:mountable]
end
def readme
copy_file "README.rdoc"
end
@ -35,6 +39,10 @@ module Rails
end
end
def config
template "config/routes.rb" if mountable?
end
def test
template "test/test_helper.rb"
template "test/%name%_test.rb"
@ -59,6 +67,9 @@ task :default => :test
def test_dummy_config
template "rails/boot.rb", "#{dummy_path}/config/boot.rb", :force => true
template "rails/application.rb", "#{dummy_path}/config/application.rb", :force => true
if mountable?
template "rails/routes.rb", "#{dummy_path}/config/routes.rb", :force => true
end
end
def test_dummy_clean
@ -91,8 +102,11 @@ task :default => :test
alias_method :plugin_path, :app_path
class_option :full, :type => :boolean, :default => false,
:desc => "Generate rails engine with integration tests"
class_option :full, :type => :boolean, :default => false,
:desc => "Generate rails engine with integration tests"
class_option :mountable, :type => :boolean, :default => false,
:desc => "Generate mountable isolated application"
def initialize(*args)
raise Error, "Options should be given after the plugin name. For details run: rails plugin --help" if args[0].blank?
@ -111,6 +125,10 @@ task :default => :test
build(:gemfile) unless options[:skip_gemfile]
end
def create_app_files
build(:app)
end
def create_config_files
build(:config)
end
@ -154,7 +172,11 @@ task :default => :test
end
def full?
options[:full]
options[:full] || options[:mountable]
end
def mountable?
options[:mountable]
end
def self.banner

View file

@ -0,0 +1,4 @@
module <%= camelized %>
class ApplicationController < ActiveController::Base
end
end

View file

@ -0,0 +1,4 @@
module <%= camelized %>
module ApplicationHelper
end
end

View file

@ -0,0 +1,3 @@
<%= camelized %>::Engine.routes.draw do
end

View file

@ -1,4 +1,7 @@
module <%= camelized %>
class Engine < Rails::Engine
<% if mountable? -%>
isolate_namespace <%= camelized %>
<% end -%>
end
end

View file

@ -0,0 +1,4 @@
Rails.application.routes.draw do
mount <%= camelized %>::Engine => "/<%= name %>"
end

View file

@ -131,6 +131,15 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase
assert_no_match /create\s+config\/application.rb/, run_generator
end
def test_create_mountable_application_with_mountable_option
run_generator [destination_root, "--mountable"]
assert_file "config/routes.rb", /Bukkits::Engine.routes.draw do/
assert_file "lib/bukkits/engine.rb", /isolate_namespace Bukkits/
assert_file "test/dummy/config/routes.rb", /mount Bukkits::Engine => "\/bukkits"/
assert_file "app/controllers/bukkits/application_controller.rb", /module Bukkits\n class ApplicationController < ActiveController::Base/
assert_file "app/helpers/bukkits/application_helper.rb", /module Bukkits\n module ApplicationHelper/
end
protected
def action(*args, &block)