From 02c9654b9bdcd10ebd2c2ad9c50bbdf578a9aae0 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Mon, 6 Aug 2012 16:22:23 -0400 Subject: Do not include application.js if it doesn't exists Rails were including 'application.js' to the pack when using `javascript_include_tag :all` even there's no application.js in the public directory. --- .../helpers/asset_tag_helpers/javascript_tag_helpers.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'actionpack/lib') 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 14d62af67b..117eb0c571 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 @@ -26,7 +26,8 @@ module ActionView def expand_sources(sources, recursive = false) if sources.include?(:all) - all_asset_files = (collect_asset_files(custom_dir, ('**' if recursive), "*.#{extension}") - ['application']) << 'application' + all_asset_files = (collect_asset_files(custom_dir, ('**' if recursive), "*.#{extension}") - ['application']) + add_application_js(all_asset_files, sources) ((determine_source(:defaults, expansions).dup & all_asset_files) + all_asset_files).uniq else expanded_sources = sources.inject([]) do |list, source| @@ -39,7 +40,7 @@ module ActionView end def add_application_js(expanded_sources, sources) - if sources.include?(:defaults) && File.exist?(File.join(custom_dir, "application.#{extension}")) + if (sources.include?(:defaults) || sources.include?(:all)) && File.exist?(File.join(custom_dir, "application.#{extension}")) expanded_sources.delete('application') expanded_sources << "application" end @@ -106,8 +107,8 @@ module ActionView # # 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. + # When using :defaults or :all, 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. @@ -133,6 +134,8 @@ module ActionView # # # # # + # Note: 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: # # javascript_include_tag :all -- cgit v1.2.3 From 0c4c7d94ed3e16a206bceced679fa129c9a254b8 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Mon, 6 Aug 2012 16:45:59 -0400 Subject: Rearrange example output of javascript_include_tag --- .../action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/lib') 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 117eb0c571..139f4d19ab 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 @@ -141,9 +141,9 @@ module ActionView # javascript_include_tag :all # # => # # - # # # # # # + # # # # Note that your defaults of choice will be included first, so they will be available to all subsequently # included files. @@ -164,9 +164,9 @@ module ActionView # javascript_include_tag :all, :cache => true # # => # # - # # # # # # + # # # # # assuming config.perform_caching is true # javascript_include_tag :all, :cache => true -- cgit v1.2.3