From 096fa1b60f537c7c30db35f5576ab351c67a5064 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Thu, 24 Mar 2011 23:43:37 +0100 Subject: jQuery is the new default --- .../asset_tag_helpers/javascript_tag_helpers.rb | 128 +++++++++++---------- actionpack/lib/action_view/railtie.rb | 2 +- 2 files changed, 71 insertions(+), 59 deletions(-) (limited to 'actionpack/lib/action_view') diff --git a/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb b/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb index ed95f1c018..ce5a7dc2e5 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb @@ -94,84 +94,98 @@ module ActionView end alias_method :path_to_javascript, :javascript_path # aliased to avoid conflicts with a javascript_path named route - # Returns an HTML script tag for each of the +sources+ provided. You - # can pass in the filename (.js extension is optional) of JavaScript files - # that exist in your public/javascripts directory for inclusion into the - # current page or you can pass the full path relative to your document - # root. To include the Prototype and Scriptaculous JavaScript libraries in - # your application, pass :defaults as the source. When using - # :defaults, if an application.js file exists in - # public/javascripts it will be included as well. You can modify the - # HTML attributes of the script tag by passing a hash as the last argument. + # Returns an HTML script tag for each of the +sources+ provided. + # + # Sources may be paths to JavaScript files. Relative paths are assumed to be relative + # to public/javascripts, full paths are assumed to be relative to the document + # root. Relative paths are idiomatic, use absolute paths only when needed. + # + # When passing paths, the ".js" extension is optional. + # + # To include the default JavaScript expansion pass :defaults as source. + # By default, :defaults loads jQuery. If the application was generated + # with "-j prototype" the libraries Prototype and Scriptaculous are loaded instead. + # In any case, the defaults can be overridden in config/application.rb: + # + # config.action_view.javascript_expansions[:defaults] = %w(foo.js bar.js) + # + # When using :defaults, if an application.js file exists in + # public/javascripts it will be included as well at the end. + # + # You can modify the HTML attributes of the script tag by passing a hash as the + # last argument. # # ==== Examples - # javascript_include_tag "xmlhr" # => - # + # javascript_include_tag "xmlhr" + # # => # - # javascript_include_tag "xmlhr.js" # => - # + # javascript_include_tag "xmlhr.js" + # # => # - # javascript_include_tag "common.javascript", "/elsewhere/cools" # => - # - # + # javascript_include_tag "common.javascript", "/elsewhere/cools" + # # => + # # # - # javascript_include_tag "http://www.railsapplication.com/xmlhr" # => - # + # javascript_include_tag "http://www.railsapplication.com/xmlhr" + # # => # - # javascript_include_tag "http://www.railsapplication.com/xmlhr.js" # => - # + # javascript_include_tag "http://www.railsapplication.com/xmlhr.js" + # # => # - # javascript_include_tag :defaults # => - # - # - # ... - # + # javascript_include_tag :defaults + # # => + # # + # # # # * = The application.js file is only referenced if it exists # - # You can also include all javascripts in the +javascripts+ directory using :all as the source: + # You can also include all JavaScripts in the +javascripts+ directory using :all as the source: # - # javascript_include_tag :all # => - # - # - # ... - # - # - # + # javascript_include_tag :all + # # => + # # + # # + # # + # # # - # Note that the default javascript files will be included first. So Prototype and Scriptaculous are available to - # all subsequently included files. + # Note that your defaults of choice will be included first, so they will be available to all subsequently + # included files. # - # If you want Rails to search in all the subdirectories under javascripts, you should explicitly set :recursive: + # If you want Rails to search in all the subdirectories under public/javascripts, you should + # explicitly set :recursive: # # javascript_include_tag :all, :recursive => true # - # == Caching multiple javascripts into one + # == Caching multiple JavaScripts into one # - # You can also cache multiple javascripts into one file, which requires less HTTP connections to download and can better be - # compressed by gzip (leading to faster transfers). Caching will only happen if config.perform_caching - # is set to true (which is the case by default for the Rails production environment, but not for the development - # environment). + # You can also cache multiple JavaScripts into one file, which requires less HTTP connections to download + # and can better be compressed by gzip (leading to faster transfers). Caching will only happen if + # config.perform_caching is set to true (which is the case by default for the Rails + # production environment, but not for the development environment). # # ==== Examples - # javascript_include_tag :all, :cache => true # when config.perform_caching is false => - # - # - # ... - # - # - # # - # javascript_include_tag :all, :cache => true # when config.perform_caching is true => - # + # # assuming config.perform_caching is false + # javascript_include_tag :all, :cache => true + # # => + # # + # # + # # + # # + # + # # assuming config.perform_caching is true + # javascript_include_tag :all, :cache => true + # # => # - # javascript_include_tag "prototype", "cart", "checkout", :cache => "shop" # when config.perform_caching is false => - # - # - # + # # assuming config.perform_caching is false + # javascript_include_tag "jquery", "cart", "checkout", :cache => "shop" + # # => + # # + # # # - # javascript_include_tag "prototype", "cart", "checkout", :cache => "shop" # when config.perform_caching is true => - # + # # assuming config.perform_caching is true + # javascript_include_tag "jquery", "cart", "checkout", :cache => "shop" + # # => # # The :recursive option is also available for caching: # @@ -184,9 +198,7 @@ module ActionView @javascript_include.include_tag(*sources) end end - end - end end end diff --git a/actionpack/lib/action_view/railtie.rb b/actionpack/lib/action_view/railtie.rb index 501ec07b09..f20ba7e6d3 100644 --- a/actionpack/lib/action_view/railtie.rb +++ b/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 => ['prototype', 'effects', 'dragdrop', 'controls', 'rails'] } + config.action_view.javascript_expansions = { :defaults => %w(jquery rails) } initializer "action_view.cache_asset_ids" do |app| unless app.config.cache_classes -- cgit v1.2.3