Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Generate javascripts in engine with --mountable option

  • Loading branch information...
commit 5d63a36ae8c2a839d0a197b10250184a035064e7 1 parent 0e5ee9a
@drogus drogus authored
View
6 railties/lib/rails/generators/app_base.rb
@@ -171,6 +171,12 @@ def bundle_if_dev_or_edge
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
View
5 railties/lib/rails/generators/rails/app/app_generator.rb
@@ -317,11 +317,6 @@ def mysql_socket
].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
View
35 railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
@@ -88,6 +88,29 @@ def test_dummy_clean
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 @@ def create_lib_files
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 @@ def finish_template
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
View
29 railties/test/generators/plugin_new_generator_test.rb
@@ -91,6 +91,35 @@ def test_ensure_that_database_option_is_passed_to_app_generator
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"
Please sign in to comment.
Something went wrong with that request. Please try again.