summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2017-04-03 05:49:16 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2017-04-03 05:49:16 +0000
commitdf347c5c017d50a503c4c0b630fd45bb77452b44 (patch)
tree3156226d98c921b3e86021cce93caac50d59b366
parent3701f0cd5fdcd0d43e2ba3def031326bef53570a (diff)
downloadredmine-df347c5c017d50a503c4c0b630fd45bb77452b44.tar.gz
redmine-df347c5c017d50a503c4c0b630fd45bb77452b44.zip
Restore timestamp in asset paths (#24617).
Patch by Hiroshi Shirosaki. git-svn-id: http://svn.redmine.org/redmine/trunk@16448 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--config/initializers/10-patches.rb51
-rw-r--r--test/integration/layout_test.rb2
2 files changed, 52 insertions, 1 deletions
diff --git a/config/initializers/10-patches.rb b/config/initializers/10-patches.rb
index 671b6df40..2693f83f4 100644
--- a/config/initializers/10-patches.rb
+++ b/config/initializers/10-patches.rb
@@ -187,3 +187,54 @@ module ActionController
end
end
end
+
+# Adds asset_id parameters to assets like Rails 3 to invalidate caches in browser
+module ActionView
+ module Helpers
+ module AssetUrlHelper
+ @@cache_asset_timestamps = Rails.env.production?
+ @@asset_timestamps_cache = {}
+ @@asset_timestamps_cache_guard = Mutex.new
+
+ def asset_path_with_asset_id(source, options = {})
+ asset_id = rails_asset_id(source, options)
+ unless asset_id.blank?
+ source += "?#{asset_id}"
+ end
+ asset_path(source, options)
+ end
+ alias :path_to_asset :asset_path_with_asset_id
+
+ def rails_asset_id(source, options = {})
+ if asset_id = ENV["RAILS_ASSET_ID"]
+ asset_id
+ else
+ if @@cache_asset_timestamps && (asset_id = @@asset_timestamps_cache[source])
+ asset_id
+ else
+ extname = compute_asset_extname(source, options)
+ path = File.join(Rails.public_path, "#{source}#{extname}")
+ exist = false
+ if File.exist? path
+ exist = true
+ else
+ path = File.join(Rails.public_path, compute_asset_path("#{source}#{extname}", options))
+ if File.exist? path
+ exist = true
+ end
+ end
+ asset_id = exist ? File.mtime(path).to_i.to_s : ''
+
+ if @@cache_asset_timestamps
+ @@asset_timestamps_cache_guard.synchronize do
+ @@asset_timestamps_cache[source] = asset_id
+ end
+ end
+
+ asset_id
+ end
+ end
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/test/integration/layout_test.rb b/test/integration/layout_test.rb
index 2fcf6dab6..1fe1a355e 100644
--- a/test/integration/layout_test.rb
+++ b/test/integration/layout_test.rb
@@ -63,7 +63,7 @@ class LayoutTest < Redmine::IntegrationTest
Role.anonymous.add_permission! :add_issues
get '/projects/ecookbook/issues/new'
- assert_select 'head script[src=?]', '/javascripts/jstoolbar/jstoolbar-textile.min.js'
+ assert_select 'head script[src^=?]', '/javascripts/jstoolbar/jstoolbar-textile.min.js?'
end
def test_calendar_header_tags