mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Generate javascripts in engine with --mountable option
This commit is contained in:
parent
a462a76bd3
commit
978314c4e1
4 changed files with 70 additions and 5 deletions
|
@ -171,6 +171,12 @@ gem 'rails', '#{Rails::VERSION::STRING}'
|
|||
def dev_or_edge?
|
||||
options.dev? || options.edge?
|
||||
end
|
||||
|
||||
def empty_directory_with_gitkeep(destination, config = {})
|
||||
empty_directory(destination, config)
|
||||
create_file("#{destination}/.gitkeep") unless options[:skip_git]
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -317,11 +317,6 @@ module Rails
|
|||
].find { |f| File.exist?(f) } unless RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
|
||||
end
|
||||
|
||||
def empty_directory_with_gitkeep(destination, config = {})
|
||||
empty_directory(destination, config)
|
||||
create_file("#{destination}/.gitkeep") unless options[:skip_git]
|
||||
end
|
||||
|
||||
def get_builder_class
|
||||
defined?(::AppBuilder) ? ::AppBuilder : Rails::AppBuilder
|
||||
end
|
||||
|
|
|
@ -88,6 +88,29 @@ task :default => :test
|
|||
end
|
||||
end
|
||||
|
||||
def stylesheets
|
||||
empty_directory_with_gitkeep "public/stylesheets" if options[:mountable]
|
||||
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[: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"
|
||||
end
|
||||
end
|
||||
|
||||
copy_file "#{app_templates_dir}/public/javascripts/application.js", "public/javascripts/application.js"
|
||||
end
|
||||
|
||||
def script(force = false)
|
||||
directory "script", :force => force do |content|
|
||||
"#{shebang}\n" + content
|
||||
|
@ -143,6 +166,14 @@ task :default => :test
|
|||
build(:lib)
|
||||
end
|
||||
|
||||
def create_public_stylesheets_files
|
||||
build(:stylesheets)
|
||||
end
|
||||
|
||||
def create_javascript_files
|
||||
build(:javascripts)
|
||||
end
|
||||
|
||||
def create_script_files
|
||||
build(:script)
|
||||
end
|
||||
|
@ -163,6 +194,10 @@ task :default => :test
|
|||
public_task :apply_rails_template, :bundle_if_dev_or_edge
|
||||
|
||||
protected
|
||||
def app_templates_dir
|
||||
"../../app/templates"
|
||||
end
|
||||
|
||||
def create_dummy_app(path = nil)
|
||||
dummy_path(path) if path
|
||||
|
||||
|
|
|
@ -91,6 +91,35 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase
|
|||
assert_file "test/dummy/config/database.yml", /postgres/
|
||||
end
|
||||
|
||||
def test_skipping_javascripts_without_mountable_option
|
||||
run_generator
|
||||
assert_no_file "public/javascripts/prototype.js"
|
||||
assert_no_file "public/javascripts/rails.js"
|
||||
assert_no_file "public/javascripts/controls.js"
|
||||
assert_no_file "public/javascripts/dragdrop.js"
|
||||
assert_no_file "public/javascripts/dragdrop.js"
|
||||
assert_no_file "public/javascripts/application.js"
|
||||
end
|
||||
|
||||
def test_javascripts_generation
|
||||
run_generator [destination_root, "--mountable"]
|
||||
assert_file "public/javascripts/rails.js"
|
||||
assert_file "public/javascripts/prototype.js"
|
||||
assert_file "public/javascripts/controls.js"
|
||||
assert_file "public/javascripts/dragdrop.js"
|
||||
assert_file "public/javascripts/dragdrop.js"
|
||||
assert_file "public/javascripts/application.js"
|
||||
end
|
||||
|
||||
def test_skip_javascripts
|
||||
run_generator [destination_root, "--skip-javascript", "--mountable"]
|
||||
assert_no_file "public/javascripts/prototype.js"
|
||||
assert_no_file "public/javascripts/rails.js"
|
||||
assert_no_file "public/javascripts/controls.js"
|
||||
assert_no_file "public/javascripts/dragdrop.js"
|
||||
assert_no_file "public/javascripts/dragdrop.js"
|
||||
end
|
||||
|
||||
def test_ensure_that_javascript_option_is_passed_to_app_generator
|
||||
run_generator [destination_root, "--javascript", "jquery"]
|
||||
assert_file "test/dummy/public/javascripts/jquery.js"
|
||||
|
|
Loading…
Reference in a new issue