diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2006-03-29 20:57:53 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2006-03-29 20:57:53 +0000 |
commit | 91383e04265f41c3a8ae9411b05384b7ef2a36c1 (patch) | |
tree | 25721929570e07f35e318c3652dee7ac3e5fcb90 /actionpack/lib/action_view | |
parent | 23fa0395d8d6b0365421b5dea9e5620b95c6b15c (diff) | |
download | rails-91383e04265f41c3a8ae9411b05384b7ef2a36c1.tar.gz rails-91383e04265f41c3a8ae9411b05384b7ef2a36c1.tar.bz2 rails-91383e04265f41c3a8ae9411b05384b7ef2a36c1.zip |
Added automated timestamping to AssetTagHelper methods for stylesheets, javascripts, and images when Action Controller is run under Rails [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4098 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/helpers/asset_tag_helper.rb | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index f05d9a096b..de44ef6531 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -59,11 +59,16 @@ module ActionView # <tt>controllers/application.rb</tt> and <tt>helpers/application_helper.rb</tt>. def javascript_include_tag(*sources) options = sources.last.is_a?(Hash) ? sources.pop.stringify_keys : { } + if sources.include?(:defaults) - sources = sources[0..(sources.index(:defaults))] + @@javascript_default_sources.dup + sources[(sources.index(:defaults) + 1)..sources.length] + sources = sources[0..(sources.index(:defaults))] + + @@javascript_default_sources.dup + + sources[(sources.index(:defaults) + 1)..sources.length] + sources.delete(:defaults) - sources << "application" if defined?(RAILS_ROOT) and File.exists?("#{RAILS_ROOT}/public/javascripts/application.js") + sources << "application" if defined?(RAILS_ROOT) && File.exists?("#{RAILS_ROOT}/public/javascripts/application.js") end + sources.collect { |source| source = javascript_path(source) content_tag("script", "", { "type" => "text/javascript", "src" => source }.merge(options)) @@ -145,12 +150,18 @@ module ActionView private def compute_public_path(source, dir, ext) - source = "/#{dir}/#{source}" unless source.first == "/" || source.include?(":") - source = "#{source}.#{ext}" unless source.split("/").last.include?(".") - source = "#{@controller.request.relative_url_root}#{source}" unless %r{^[-a-z]+://} =~ source + source = "/#{dir}/#{source}" unless source.first == "/" || source.include?(":") + source << ".#{ext}" unless source.split("/").last.include?(".") + source << '?' + rails_asset_id(source) if defined?(RAILS_ROOT) + source = "#{@controller.request.relative_url_root}#{source}" unless %r{^[-a-z]+://} =~ source source = ActionController::Base.asset_host + source unless source.include?(":") source end + + def rails_asset_id(source) + ENV["RAILS_ASSET_ID"] || + File.stat(RAILS_ROOT + "/public/#{source}").mtime.to_i.to_s + end end end end |