mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix plugin new generator to work with new javascript/stylesheets conventions
This commit is contained in:
parent
1a1e4d484a
commit
5952d4f860
3 changed files with 40 additions and 29 deletions
|
@ -138,7 +138,7 @@ module Rails
|
|||
def vendor_stylesheets
|
||||
empty_directory_with_gitkeep "vendor/assets/stylesheets"
|
||||
end
|
||||
|
||||
|
||||
def vendor_plugins
|
||||
empty_directory_with_gitkeep "vendor/plugins"
|
||||
end
|
||||
|
@ -166,7 +166,7 @@ module Rails
|
|||
if !options[:skip_active_record] && !DATABASES.include?(options[:database])
|
||||
raise Error, "Invalid value for --database option. Supported for preconfiguration are: #{DATABASES.join(", ")}."
|
||||
end
|
||||
|
||||
|
||||
if !options[:skip_javascript] && !JAVASCRIPTS.include?(options[:javascript])
|
||||
raise Error, "Invalid value for --javascript option. Supported for preconfiguration are: #{JAVASCRIPTS.join(", ")}."
|
||||
end
|
||||
|
|
|
@ -94,26 +94,35 @@ task :default => :test
|
|||
end
|
||||
|
||||
def stylesheets
|
||||
empty_directory_with_gitkeep "public/stylesheets" if options[:mountable]
|
||||
if options[:mountable]
|
||||
empty_directory_with_gitkeep "app/stylesheets"
|
||||
copy_file "#{app_templates_dir}/app/assets/stylesheets/application.css",
|
||||
"app/assets/stylesheets/application.css"
|
||||
end
|
||||
end
|
||||
|
||||
def javascripts
|
||||
return unless options[:mountable]
|
||||
|
||||
empty_directory "#{app_templates_dir}/public/javascripts"
|
||||
|
||||
unless options[:skip_javascript]
|
||||
copy_file "#{app_templates_dir}/public/javascripts/#{options[:javascript]}.js", "public/javascripts/#{options[:javascript]}.js"
|
||||
copy_file "#{app_templates_dir}/public/javascripts/#{options[:javascript]}_ujs.js", "public/javascripts/rails.js"
|
||||
if options[:skip_javascript]
|
||||
empty_directory_with_gitkeep "vendor/assets/javascripts"
|
||||
else
|
||||
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",
|
||||
"vendor/assets/javascripts/#{options[:javascript]}.js"
|
||||
copy_file "#{app_templates_dir}/vendor/assets/javascripts/#{options[:javascript]}_ujs.js",
|
||||
"vendor/assets/javascripts/#{options[:javascript]}_ujs.js"
|
||||
|
||||
if options[:javascript] == "prototype"
|
||||
copy_file "#{app_templates_dir}/public/javascripts/controls.js", "public/javascripts/controls.js"
|
||||
copy_file "#{app_templates_dir}/public/javascripts/dragdrop.js", "public/javascripts/dragdrop.js"
|
||||
copy_file "#{app_templates_dir}/public/javascripts/effects.js", "public/javascripts/effects.js"
|
||||
copy_file "#{app_templates_dir}/vendor/assets/javascripts/controls.js",
|
||||
"vendor/assets/javascripts/controls.js"
|
||||
copy_file "#{app_templates_dir}/vendor/assets/javascripts/dragdrop.js",
|
||||
"vendor/assets/javascripts/dragdrop.js"
|
||||
copy_file "#{app_templates_dir}/vendor/assets/javascripts/effects.js",
|
||||
"vendor/assets/javascripts/effects.js"
|
||||
end
|
||||
end
|
||||
|
||||
copy_file "#{app_templates_dir}/public/javascripts/application.js", "public/javascripts/application.js"
|
||||
end
|
||||
|
||||
def script(force = false)
|
||||
|
|
|
@ -95,32 +95,33 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase
|
|||
|
||||
def test_skipping_javascripts_without_mountable_option
|
||||
run_generator
|
||||
assert_no_file "public/javascripts/jquery.js"
|
||||
assert_no_file "public/javascripts/rails.js"
|
||||
assert_no_file "public/javascripts/application.js"
|
||||
assert_no_file "app/assets/javascripts/application.js"
|
||||
assert_no_file "vendor/assets/javascripts/jquery.js"
|
||||
assert_no_file "vendor/assets/javascripts/jquery_ujs.js"
|
||||
end
|
||||
|
||||
def test_javascripts_generation
|
||||
run_generator [destination_root, "--mountable"]
|
||||
assert_file "public/javascripts/jquery.js"
|
||||
assert_file "public/javascripts/rails.js"
|
||||
assert_file "public/javascripts/application.js"
|
||||
assert_file "app/assets/javascripts/application.js"
|
||||
assert_file "vendor/assets/javascripts/jquery.js"
|
||||
assert_file "vendor/assets/javascripts/jquery_ujs.js"
|
||||
end
|
||||
|
||||
def test_skip_javascripts
|
||||
run_generator [destination_root, "--skip-javascript", "--mountable"]
|
||||
assert_no_file "public/javascripts/jquery.js"
|
||||
assert_no_file "public/javascripts/rails.js"
|
||||
assert_no_file "app/assets/javascripts/application.js"
|
||||
assert_no_file "vendor/assets/javascripts/jquery.js"
|
||||
assert_no_file "vendor/assets/javascripts/jquery_ujs.js"
|
||||
end
|
||||
|
||||
def test_ensure_that_javascript_option_is_passed_to_app_generator
|
||||
run_generator [destination_root, "--javascript", "prototype"]
|
||||
assert_file "test/dummy/public/javascripts/prototype.js"
|
||||
end
|
||||
|
||||
def test_ensure_that_skip_javascript_option_is_passed_to_app_generator
|
||||
run_generator [destination_root, "--skip_javascript"]
|
||||
assert_no_file "test/dummy/public/javascripts/jquery.js"
|
||||
def test_config_prototype_javascript_library
|
||||
run_generator [destination_root, "-j", "prototype", "--mountable"]
|
||||
assert_file "app/assets/javascripts/application.js"
|
||||
assert_file "vendor/assets/javascripts/prototype.js"
|
||||
assert_file "vendor/assets/javascripts/effects.js"
|
||||
assert_file "vendor/assets/javascripts/dragdrop.js"
|
||||
assert_file "vendor/assets/javascripts/controls.js"
|
||||
assert_file "vendor/assets/javascripts/prototype_ujs.js", /prototype/
|
||||
end
|
||||
|
||||
def test_template_from_dir_pwd
|
||||
|
@ -218,3 +219,4 @@ protected
|
|||
silence(:stdout){ generator.send(*args, &block) }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue