Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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.
  • Loading branch information...
commit d9c39c3ae9aa9d0f50a4b557781be39e39e5b752 1 parent 5d2cdb1
@fxn fxn authored
View
2  actionpack/lib/action_view/railtie.rb
@@ -6,7 +6,7 @@ module ActionView
class Railtie < Rails::Railtie
config.action_view = ActiveSupport::OrderedOptions.new
config.action_view.stylesheet_expansions = {}
- config.action_view.javascript_expansions = { :defaults => %w(jquery rails) }
+ config.action_view.javascript_expansions = { :defaults => %w(jquery jquery_ujs) }
initializer "action_view.cache_asset_ids" do |app|
unless app.config.cache_classes
View
7 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]
View
2  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:
View
8 railties/lib/rails/generators/app_base.rb
@@ -12,7 +12,6 @@ class AppBase < Base
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 @@ def self.add_shared_options_for(name)
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 @@ def gem_for_turn
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?
View
10 railties/lib/rails/generators/rails/app/app_generator.rb
@@ -111,20 +111,10 @@ def tmp
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
View
3  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'
View
4 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 .
View
2  railties/lib/rails/generators/rails/app/templates/config/application.rb
@@ -47,7 +47,7 @@ class Application < Rails::Application
<% 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] -%>
View
4 railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
@@ -119,10 +119,6 @@ def javascripts
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
View
38 railties/test/generators/app_generator_test.rb
@@ -163,21 +163,41 @@ def test_active_record_is_removed_from_frameworks_if_skip_active_record_is_given
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
Please sign in to comment.
Something went wrong with that request. Please try again.