Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Generate app/* stubs directories for full plugins to show ththat it i…

…s possible to extend them.
  • Loading branch information...
commit eb75f15a1aaa570fc0eedd1cb5ad0486e0e48450 1 parent 5952d4f
@josevalim josevalim authored
View
43 railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
@@ -9,10 +9,15 @@ def rakefile
end
def app
- if options[:mountable]
+ if mountable?
directory "app"
template "#{app_templates_dir}/app/views/layouts/application.html.erb.tt",
"app/views/layouts/#{name}/application.html.erb"
+ elsif full?
+ empty_directory_with_gitkeep "app/models"
+ empty_directory_with_gitkeep "app/controllers"
+ empty_directory_with_gitkeep "app/views"
+ empty_directory_with_gitkeep "app/helpers"
end
end
@@ -61,8 +66,12 @@ def test
end
end
+ PASSTHROUGH_OPTIONS = [
+ :skip_active_record, :skip_javascript, :database, :javascript, :quiet, :pretend, :force, :skip
+ ]
+
def generate_test_dummy(force = false)
- opts = (options || {}).slice(:skip_active_record, :skip_javascript, :database, :javascript, :quiet, :pretend, :force, :skip)
+ opts = (options || {}).slice(*PASSTHROUGH_OPTIONS)
opts[:force] = force
invoke Rails::Generators::AppGenerator,
@@ -94,19 +103,18 @@ def test_dummy_clean
end
def stylesheets
- if options[:mountable]
- empty_directory_with_gitkeep "app/stylesheets"
+ if mountable?
copy_file "#{app_templates_dir}/app/assets/stylesheets/application.css",
"app/assets/stylesheets/application.css"
+ elsif full?
+ empty_directory_with_gitkeep "app/assets/stylesheets"
end
end
def javascripts
- return unless options[:mountable]
+ return if options.skip_javascript?
- if options[:skip_javascript]
- empty_directory_with_gitkeep "vendor/assets/javascripts"
- else
+ if mountable?
copy_file "#{app_templates_dir}/app/assets/javascripts/application.js.tt",
"app/assets/javascripts/application.js"
copy_file "#{app_templates_dir}/vendor/assets/javascripts/#{options[:javascript]}.js",
@@ -122,6 +130,8 @@ def javascripts
copy_file "#{app_templates_dir}/vendor/assets/javascripts/effects.js",
"vendor/assets/javascripts/effects.js"
end
+ elsif full?
+ empty_directory_with_gitkeep "app/assets/javascripts"
end
end
@@ -139,17 +149,17 @@ class PluginNewGenerator < AppBase
alias_method :plugin_path, :app_path
- class_option :dummy_path, :type => :string, :default => "test/dummy",
- :desc => "Create dummy application at given path"
+ class_option :dummy_path, :type => :string, :default => "test/dummy",
+ :desc => "Create dummy application at given 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"
+ class_option :mountable, :type => :boolean, :default => false,
+ :desc => "Generate mountable isolated application"
- class_option :skip_gemspec, :type => :boolean, :default => false,
- :desc => "Skip gemspec file"
+ class_option :skip_gemspec, :type => :boolean, :default => false,
+ :desc => "Skip gemspec file"
def initialize(*args)
raise Error, "Options should be given after the plugin name. For details run: rails plugin --help" if args[0].blank?
@@ -209,6 +219,7 @@ def finish_template
public_task :apply_rails_template, :bundle_if_dev_or_edge
protected
+
def app_templates_dir
"../../app/templates"
end
View
0  railties/lib/rails/generators/rails/plugin_new/templates/app/models/.empty_directory
No changes.
View
6 railties/test/generators/plugin_new_generator_test.rb
@@ -145,6 +145,12 @@ def test_ensure_that_tests_works_in_full_mode
def test_creating_engine_in_full_mode
run_generator [destination_root, "--full"]
+ assert_file "app/assets/javascripts"
+ assert_file "app/assets/stylesheets"
+ assert_file "app/models"
+ assert_file "app/controllers"
+ assert_file "app/views"
+ assert_file "app/helpers"
assert_file "config/routes.rb", /Rails.application.routes.draw do/
assert_file "lib/bukkits/engine.rb", /module Bukkits\n class Engine < Rails::Engine\n end\nend/
assert_file "lib/bukkits.rb", /require "bukkits\/engine"/
Please sign in to comment.
Something went wrong with that request. Please try again.