mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Generate app/* stubs directories for full plugins to show ththat it is possible to extend them.
This commit is contained in:
parent
5952d4f860
commit
eb75f15a1a
3 changed files with 33 additions and 16 deletions
|
@ -9,10 +9,15 @@ module Rails
|
||||||
end
|
end
|
||||||
|
|
||||||
def app
|
def app
|
||||||
if options[:mountable]
|
if mountable?
|
||||||
directory "app"
|
directory "app"
|
||||||
template "#{app_templates_dir}/app/views/layouts/application.html.erb.tt",
|
template "#{app_templates_dir}/app/views/layouts/application.html.erb.tt",
|
||||||
"app/views/layouts/#{name}/application.html.erb"
|
"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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -61,8 +66,12 @@ task :default => :test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
PASSTHROUGH_OPTIONS = [
|
||||||
|
:skip_active_record, :skip_javascript, :database, :javascript, :quiet, :pretend, :force, :skip
|
||||||
|
]
|
||||||
|
|
||||||
def generate_test_dummy(force = false)
|
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
|
opts[:force] = force
|
||||||
|
|
||||||
invoke Rails::Generators::AppGenerator,
|
invoke Rails::Generators::AppGenerator,
|
||||||
|
@ -94,19 +103,18 @@ task :default => :test
|
||||||
end
|
end
|
||||||
|
|
||||||
def stylesheets
|
def stylesheets
|
||||||
if options[:mountable]
|
if mountable?
|
||||||
empty_directory_with_gitkeep "app/stylesheets"
|
|
||||||
copy_file "#{app_templates_dir}/app/assets/stylesheets/application.css",
|
copy_file "#{app_templates_dir}/app/assets/stylesheets/application.css",
|
||||||
"app/assets/stylesheets/application.css"
|
"app/assets/stylesheets/application.css"
|
||||||
|
elsif full?
|
||||||
|
empty_directory_with_gitkeep "app/assets/stylesheets"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def javascripts
|
def javascripts
|
||||||
return unless options[:mountable]
|
return if options.skip_javascript?
|
||||||
|
|
||||||
if options[:skip_javascript]
|
if mountable?
|
||||||
empty_directory_with_gitkeep "vendor/assets/javascripts"
|
|
||||||
else
|
|
||||||
copy_file "#{app_templates_dir}/app/assets/javascripts/application.js.tt",
|
copy_file "#{app_templates_dir}/app/assets/javascripts/application.js.tt",
|
||||||
"app/assets/javascripts/application.js"
|
"app/assets/javascripts/application.js"
|
||||||
copy_file "#{app_templates_dir}/vendor/assets/javascripts/#{options[:javascript]}.js",
|
copy_file "#{app_templates_dir}/vendor/assets/javascripts/#{options[:javascript]}.js",
|
||||||
|
@ -122,6 +130,8 @@ task :default => :test
|
||||||
copy_file "#{app_templates_dir}/vendor/assets/javascripts/effects.js",
|
copy_file "#{app_templates_dir}/vendor/assets/javascripts/effects.js",
|
||||||
"vendor/assets/javascripts/effects.js"
|
"vendor/assets/javascripts/effects.js"
|
||||||
end
|
end
|
||||||
|
elsif full?
|
||||||
|
empty_directory_with_gitkeep "app/assets/javascripts"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -139,17 +149,17 @@ task :default => :test
|
||||||
|
|
||||||
alias_method :plugin_path, :app_path
|
alias_method :plugin_path, :app_path
|
||||||
|
|
||||||
class_option :dummy_path, :type => :string, :default => "test/dummy",
|
class_option :dummy_path, :type => :string, :default => "test/dummy",
|
||||||
:desc => "Create dummy application at given path"
|
:desc => "Create dummy application at given path"
|
||||||
|
|
||||||
class_option :full, :type => :boolean, :default => false,
|
class_option :full, :type => :boolean, :default => false,
|
||||||
:desc => "Generate rails engine with integration tests"
|
:desc => "Generate rails engine with integration tests"
|
||||||
|
|
||||||
class_option :mountable, :type => :boolean, :default => false,
|
class_option :mountable, :type => :boolean, :default => false,
|
||||||
:desc => "Generate mountable isolated application"
|
:desc => "Generate mountable isolated application"
|
||||||
|
|
||||||
class_option :skip_gemspec, :type => :boolean, :default => false,
|
class_option :skip_gemspec, :type => :boolean, :default => false,
|
||||||
:desc => "Skip gemspec file"
|
:desc => "Skip gemspec file"
|
||||||
|
|
||||||
def initialize(*args)
|
def initialize(*args)
|
||||||
raise Error, "Options should be given after the plugin name. For details run: rails plugin --help" if args[0].blank?
|
raise Error, "Options should be given after the plugin name. For details run: rails plugin --help" if args[0].blank?
|
||||||
|
@ -209,6 +219,7 @@ task :default => :test
|
||||||
public_task :apply_rails_template, :bundle_if_dev_or_edge
|
public_task :apply_rails_template, :bundle_if_dev_or_edge
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def app_templates_dir
|
def app_templates_dir
|
||||||
"../../app/templates"
|
"../../app/templates"
|
||||||
end
|
end
|
||||||
|
|
|
@ -145,6 +145,12 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase
|
||||||
|
|
||||||
def test_creating_engine_in_full_mode
|
def test_creating_engine_in_full_mode
|
||||||
run_generator [destination_root, "--full"]
|
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 "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/engine.rb", /module Bukkits\n class Engine < Rails::Engine\n end\nend/
|
||||||
assert_file "lib/bukkits.rb", /require "bukkits\/engine"/
|
assert_file "lib/bukkits.rb", /require "bukkits\/engine"/
|
||||||
|
|
Loading…
Reference in a new issue