Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add --mountable option to 'plugin new' generator which generates full…

… mountable application (engine)
  • Loading branch information...
commit cbe391b517f55caad8cbefa6f864289d76fab653 1 parent c159b50
Piotr Sarnacki drogus authored
28 railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
View
@@ -7,6 +7,10 @@ def rakefile
template "Rakefile"
end
+ def app
+ directory "app" if options[:mountable]
+ end
+
def readme
copy_file "README.rdoc"
end
@@ -35,6 +39,10 @@ def lib
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 @@ def generate_test_dummy(force = false)
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 @@ class PluginNewGenerator < AppBase
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 @@ def create_root_files
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 @@ def create_dummy_app(path = nil)
end
def full?
- options[:full]
+ options[:full] || options[:mountable]
+ end
+
+ def mountable?
+ options[:mountable]
end
def self.banner
4 ...ties/lib/rails/generators/rails/plugin_new/templates/app/controllers/%name%/application_controller.rb.tt
View
@@ -0,0 +1,4 @@
+module <%= camelized %>
+ class ApplicationController < ActiveController::Base
+ end
+end
4 railties/lib/rails/generators/rails/plugin_new/templates/app/helpers/%name%/application_helper.rb.tt
View
@@ -0,0 +1,4 @@
+module <%= camelized %>
+ module ApplicationHelper
+ end
+end
3  railties/lib/rails/generators/rails/plugin_new/templates/config/routes.rb
View
@@ -0,0 +1,3 @@
+<%= camelized %>::Engine.routes.draw do
+
+end
3  railties/lib/rails/generators/rails/plugin_new/templates/lib/%name%/engine.rb
View
@@ -1,4 +1,7 @@
module <%= camelized %>
class Engine < Rails::Engine
+<% if mountable? -%>
+ isolate_namespace <%= camelized %>
+<% end -%>
end
end
4 railties/lib/rails/generators/rails/plugin_new/templates/rails/routes.rb
View
@@ -0,0 +1,4 @@
+Rails.application.routes.draw do
+
+ mount <%= camelized %>::Engine => "/<%= name %>"
+end
9 railties/test/generators/plugin_new_generator_test.rb
View
@@ -131,6 +131,15 @@ def test_being_quiet_while_creating_dummy_application
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)
Please sign in to comment.
Something went wrong with that request. Please try again.