aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb
diff options
context:
space:
mode:
authorJosh Kalderimis <josh.kalderimis@gmail.com>2011-02-13 05:00:30 +0800
committerJosé Valim <jose.valim@gmail.com>2011-02-13 05:50:24 +0800
commit1363bb8f7215fadb65e9296217be2ae96e82dd7e (patch)
tree2c43f8efb8aa4879c155ac0818f38b6de452de13 /actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb
parentad5b4d980aec128e028b721156aa4433199e30ab (diff)
downloadrails-1363bb8f7215fadb65e9296217be2ae96e82dd7e.tar.gz
rails-1363bb8f7215fadb65e9296217be2ae96e82dd7e.tar.bz2
rails-1363bb8f7215fadb65e9296217be2ae96e82dd7e.zip
This corrects two issues with javascript_include_tag, the order at which they are expanded, and removing duplicates.
When individual js assets are specified, they will override the order of the same asset specified in an expansion. [#5938 state:resolved]
Diffstat (limited to 'actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb')
-rw-r--r--actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb27
1 files changed, 23 insertions, 4 deletions
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 c95808a219..4781832711 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
@@ -33,13 +33,32 @@ module ActionView
all_asset_files = (collect_asset_files(custom_dir, ('**' if recursive), "*.#{extension}") - ['application']) << 'application'
((determine_source(:defaults, expansions).dup & all_asset_files) + all_asset_files).uniq
else
- expanded_sources = sources.collect do |source|
- determine_source(source, expansions)
- end.flatten
- expanded_sources << "application" if sources.include?(:defaults) && File.exist?(File.join(custom_dir, "application.#{extension}"))
+ expanded_sources = sources.inject([]) do |list, source|
+ determined_source = determine_source(source, expansions)
+ update_source_list(list, determined_source)
+ end
+ add_application_js(expanded_sources, sources)
expanded_sources
end
end
+
+ def update_source_list(list, source)
+ case source
+ when String
+ list.delete(source)
+ list << source
+ when Array
+ updated_sources = source - list
+ list.concat(updated_sources)
+ end
+ end
+
+ def add_application_js(expanded_sources, sources)
+ if sources.include?(:defaults) && File.exist?(File.join(custom_dir, "application.#{extension}"))
+ expanded_sources.delete('application')
+ expanded_sources << "application"
+ end
+ end
end