aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2011-05-02 00:59:57 +0200
committerXavier Noria <fxn@hashref.com>2011-05-04 10:33:53 +0200
commitd9c39c3ae9aa9d0f50a4b557781be39e39e5b752 (patch)
treefeab3d5b27ae177f71cdcd043aadb5d8cb6bbf23 /railties
parent5d2cdb190ad4eb35ab78180b2fd2e72a3d7a61f7 (diff)
downloadrails-d9c39c3ae9aa9d0f50a4b557781be39e39e5b752.tar.gz
rails-d9c39c3ae9aa9d0f50a4b557781be39e39e5b752.tar.bz2
rails-d9c39c3ae9aa9d0f50a4b557781be39e39e5b752.zip
restores the -j option, but now it accepts the name of any library
If passed "foo", a gem "foo-rails" is added to the Gemfile and "foo" and "foo_ujs" are required in the application JavaScript manifest.
Diffstat (limited to 'railties')
-rw-r--r--railties/CHANGELOG7
-rw-r--r--railties/guides/source/action_view_overview.textile2
-rw-r--r--railties/lib/rails/generators/app_base.rb8
-rw-r--r--railties/lib/rails/generators/rails/app/app_generator.rb10
-rw-r--r--railties/lib/rails/generators/rails/app/templates/Gemfile3
-rw-r--r--railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt4
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/application.rb2
-rw-r--r--railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb4
-rw-r--r--railties/test/generators/app_generator_test.rb38
9 files changed, 45 insertions, 33 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG
index eb93c144e8..140e74c162 100644
--- a/railties/CHANGELOG
+++ b/railties/CHANGELOG
@@ -1,8 +1,11 @@
*Rails 3.1.0 (unreleased)*
-* jQuery is no longer vendored, it is provided from now on by the jquery-rails gem. [fxn]
+* The -j option of the application generator accepts an arbitrary string. If passed "foo",
+the gem "foo-rails" is added to the Gemfile, and the application JavaScript manifest
+requires "foo" and "foo_ujs". As of this writing "prototype-rails" and "jquery-rails"
+exist and provide those files via de asset pipeline. Default is "jquery". [fxn]
-* Application generation no longer supports the -j option. [fxn]
+* jQuery is no longer vendored, it is provided from now on by the jquery-rails gem. [fxn]
* Prototype and Scriptaculous are no longer vendored, they are provided from now on
by the prototype-rails gem. [fxn]
diff --git a/railties/guides/source/action_view_overview.textile b/railties/guides/source/action_view_overview.textile
index 9e59383315..2b2c197f46 100644
--- a/railties/guides/source/action_view_overview.textile
+++ b/railties/guides/source/action_view_overview.textile
@@ -1301,8 +1301,6 @@ h4. JavaScriptHelper
Provides functionality for working with JavaScript in your views.
-Rails includes by default the jQuery JavaScript library. If you wish to use these libraries and they are in your asset pipeline, or otherwise make sure +&lt;%= javascript_include_tag :defaults, :cache => true %&gt;+ is in the HEAD section of your page. This function will include the necessary JavaScript files Rails generated in the +public/javascripts+ directory.
-
h5. button_to_function
Returns a button that'll trigger a JavaScript function using the onclick handler. Examples:
diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb
index b5110fa9b7..998957f313 100644
--- a/railties/lib/rails/generators/app_base.rb
+++ b/railties/lib/rails/generators/app_base.rb
@@ -12,7 +12,6 @@ module Rails
DATABASES = %w( mysql oracle postgresql sqlite3 frontbase ibm_db )
JDBC_DATABASES = %w( jdbcmysql jdbcsqlite3 jdbcpostgresql )
DATABASES.concat(JDBC_DATABASES)
- JAVASCRIPTS = %w( jquery prototype )
attr_accessor :rails_template
add_shebang_option!
@@ -38,6 +37,9 @@ module Rails
class_option :database, :type => :string, :aliases => "-d", :default => "sqlite3",
:desc => "Preconfigure for selected database (options: #{DATABASES.join('/')})"
+ class_option :javascript, :type => :string, :aliases => '-j', :default => 'jquery',
+ :desc => 'Preconfigure for selected JavaScript library'
+
class_option :skip_javascript, :type => :boolean, :aliases => "-J", :default => false,
:desc => "Skip JavaScript files"
@@ -178,6 +180,10 @@ module Rails
end
end
+ def gem_for_javascript
+ "gem '#{options[:javascript]}-rails'" unless options[:skip_javascript]
+ end
+
def bundle_if_dev_or_edge
bundle_command = File.basename(Thor::Util.ruby_command).sub(/ruby/, 'bundle')
run "#{bundle_command} install" if dev_or_edge?
diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb
index 559f61e265..d79f76c799 100644
--- a/railties/lib/rails/generators/rails/app/app_generator.rb
+++ b/railties/lib/rails/generators/rails/app/app_generator.rb
@@ -111,20 +111,10 @@ module Rails
end
def vendor
- vendor_javascripts
vendor_stylesheets
vendor_plugins
end
- def vendor_javascripts
- if options[:skip_javascript]
- empty_directory_with_gitkeep "vendor/assets/javascripts"
- else
- copy_file "vendor/assets/javascripts/jquery.js"
- copy_file "vendor/assets/javascripts/jquery_ujs.js"
- end
- end
-
def vendor_stylesheets
empty_directory_with_gitkeep "vendor/assets/stylesheets"
end
diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile
index de7d51d030..b046edd5b7 100644
--- a/railties/lib/rails/generators/rails/app/templates/Gemfile
+++ b/railties/lib/rails/generators/rails/app/templates/Gemfile
@@ -10,8 +10,7 @@ gem 'sass'
gem 'coffee-script'
gem 'uglifier'
-# Prototype, Scriptaculous, and RJS.
-# gem 'prototype-rails'
+<%= gem_for_javascript %>
# Use unicorn as the web server
# gem 'unicorn'
diff --git a/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt b/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt
index c04c33e321..612c614f2e 100644
--- a/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt
+++ b/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt
@@ -2,7 +2,7 @@
// FIXME: Tell people how Sprockets and CoffeeScript works
//
<% unless options[:skip_javascript] -%>
-//= require jquery
-//= require jquery_ujs
+//= require <%= options[:javascript] %>
+//= require <%= options[:javascript] %>_ujs
<% end -%>
//= require_tree .
diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb
index 7bf4c779a0..3723addf2b 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/application.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb
@@ -47,7 +47,7 @@ module <%= app_const_base %>
<% if options[:skip_javascript] -%>
# config.action_view.javascript_expansions[:defaults] = %w()
<% else -%>
- # config.action_view.javascript_expansions[:defaults] = %w(prototype effects dragdrop controls rails)
+ # config.action_view.javascript_expansions[:defaults] = %w(prototype prototype_ujs)
<% end -%>
<% if options[:skip_test_unit] -%>
diff --git a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
index 2bfe8b09f3..6201595308 100644
--- a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
+++ b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
@@ -119,10 +119,6 @@ task :default => :test
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/jquery.js",
- "vendor/assets/javascripts/jquery.js"
- copy_file "#{app_templates_dir}/vendor/assets/javascripts/jquery_ujs.js",
- "vendor/assets/javascripts/jquery_ujs.js"
elsif full?
empty_directory_with_gitkeep "app/assets/javascripts"
end
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index 3cf92aed07..81263a6ce9 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -163,21 +163,41 @@ class AppGeneratorTest < Rails::Generators::TestCase
assert_file "config/application.rb", /#\s+require\s+["']active_record\/railtie["']/
end
- def test_jquery_and_test_unit_are_added_by_default
+ def test_creation_of_a_test_directory
run_generator
- assert_file "config/application.rb", /#\s+config\.action_view\.javascript_expansions\[:defaults\]\s+=\s+%w\(prototype effects dragdrop controls rails\)/
- assert_file "app/assets/javascripts/application.js"
- assert_file "vendor/assets/javascripts/jquery.js"
- assert_file "vendor/assets/javascripts/jquery_ujs.js"
- assert_file "test"
+ assert_file 'test'
+ end
+
+ def test_jquery_is_the_default_javascript_library
+ run_generator
+ assert_file "config/application.rb", /#\s+config\.action_view\.javascript_expansions\[:defaults\]\s+=\s+%w\(prototype prototype_ujs\)/
+ assert_file "app/assets/javascripts/application.js" do |contents|
+ assert_match %r{^//= require jquery}, contents
+ assert_match %r{^//= require jquery_ujs}, contents
+ end
+ assert_file 'Gemfile' do |contents|
+ assert_match /^gem 'jquery-rails'/, contents
+ end
+ end
+
+ def test_other_javascript_libraries
+ run_generator [destination_root, '-j', 'prototype']
+ assert_file "config/application.rb", /#\s+config\.action_view\.javascript_expansions\[:defaults\]\s+=\s+%w\(prototype prototype_ujs\)/
+ assert_file "app/assets/javascripts/application.js" do |contents|
+ assert_match %r{^//= require prototype}, contents
+ assert_match %r{^//= require prototype_ujs}, contents
+ end
+ assert_file 'Gemfile' do |contents|
+ assert_match /^gem 'prototype-rails'/, contents
+ end
end
def test_javascript_is_skipped_if_required
run_generator [destination_root, "--skip-javascript"]
assert_file "config/application.rb", /^\s+# config\.action_view\.javascript_expansions\[:defaults\]\s+=\s+%w\(\)/
- assert_file "app/assets/javascripts/application.js"
- assert_no_file "vendor/assets/javascripts/jquery.js"
- assert_no_file "vendor/assets/javascripts/jquery_ujs.js"
+ assert_file "app/assets/javascripts/application.js" do |contents|
+ assert_no_match %r{^//=\s+require\s}, contents
+ end
end
def test_template_from_dir_pwd