Skip to content
This repository
Newer
Older
100644 94 lines (77 sloc) 2.965 kb
13990d50 »
2011-07-01 require 'thread' before using mutex
1 require 'thread'
0ff1c593 »
2010-11-15 reorganised the the common asset helpers module into a class and have…
2 require 'active_support/core_ext/file'
6b8a3a0a »
2012-04-21 Add missing require when helpers are used in isolation
3 require 'active_support/core_ext/module/attribute_accessors'
0ff1c593 »
2010-11-15 reorganised the the common asset helpers module into a class and have…
4
5 module ActionView
6 module Helpers
7 module AssetTagHelper
8
354709fe »
2011-06-21 Rename AV::Helpers::AssetPaths to AV::AssetPaths to solve autoload mess.
9 class AssetPaths < ::ActionView::AssetPaths #:nodoc:
2bed4d94 »
2010-11-15 changed asset_timestamps_cache to asset_ids_cache, added an rdoc comm…
10 # You can enable or disable the asset tag ids cache.
ce1f8767 »
2010-11-15 corrected the AV railtie to use the new home for cache_asset_timestam…
11 # With the cache enabled, the asset tag helper methods will make fewer
2bed4d94 »
2010-11-15 changed asset_timestamps_cache to asset_ids_cache, added an rdoc comm…
12 # expensive file system calls (the default implementation checks the file
13 # system timestamp). However this prevents you from modifying any asset
14 # files while the server is running.
ce1f8767 »
2010-11-15 corrected the AV railtie to use the new home for cache_asset_timestam…
15 #
2bed4d94 »
2010-11-15 changed asset_timestamps_cache to asset_ids_cache, added an rdoc comm…
16 # ActionView::Helpers::AssetTagHelper::AssetPaths.cache_asset_ids = false
17 mattr_accessor :cache_asset_ids
0ff1c593 »
2010-11-15 reorganised the the common asset helpers module into a class and have…
18
2bed4d94 »
2010-11-15 changed asset_timestamps_cache to asset_ids_cache, added an rdoc comm…
19 # Add or change an asset id in the asset id cache. This can be used
20 # for SASS on Heroku.
21 # :api: public
22 def add_to_asset_ids_cache(source, asset_id)
23 self.asset_ids_cache_guard.synchronize do
24 self.asset_ids_cache[source] = asset_id
ce1f8767 »
2010-11-15 corrected the AV railtie to use the new home for cache_asset_timestam…
25 end
26 end
27
22fcef90 »
2011-04-19 Actually add an abstract class, so it is easier to get rid of old ass…
28 private
0ff1c593 »
2010-11-15 reorganised the the common asset helpers module into a class and have…
29
22fcef90 »
2011-04-19 Actually add an abstract class, so it is easier to get rid of old ass…
30 def rewrite_extension(source, dir, ext)
31 source_ext = File.extname(source)
0ff1c593 »
2010-11-15 reorganised the the common asset helpers module into a class and have…
32
22fcef90 »
2011-04-19 Actually add an abstract class, so it is easier to get rid of old ass…
33 source_with_ext = if source_ext.empty?
34 "#{source}.#{ext}"
35 elsif ext != source_ext[1..-1]
36 with_ext = "#{source}.#{ext}"
37 with_ext if File.exist?(File.join(config.assets_dir, dir, with_ext))
0ff1c593 »
2010-11-15 reorganised the the common asset helpers module into a class and have…
38 end
39
22fcef90 »
2011-04-19 Actually add an abstract class, so it is easier to get rid of old ass…
40 source_with_ext || source
41 end
914218ef »
2011-04-19 Let's use inheritance here, shall we?
42
22fcef90 »
2011-04-19 Actually add an abstract class, so it is easier to get rid of old ass…
43 # Break out the asset path rewrite in case plugins wish to put the asset id
44 # someplace other than the query string.
da7f0426 »
2011-09-14 Allow asset tag helper methods to accept :digest => false option in o…
45 def rewrite_asset_path(source, dir, options = nil)
f7c711ba »
2011-05-03 No need for a regexp here.
46 source = "/#{dir}/#{source}" unless source[0] == ?/
22fcef90 »
2011-04-19 Actually add an abstract class, so it is easier to get rid of old ass…
47 path = config.asset_path
ce1f8767 »
2010-11-15 corrected the AV railtie to use the new home for cache_asset_timestam…
48
22fcef90 »
2011-04-19 Actually add an abstract class, so it is easier to get rid of old ass…
49 if path && path.respond_to?(:call)
50 return path.call(source)
51 elsif path && path.is_a?(String)
52 return path % [source]
ce1f8767 »
2010-11-15 corrected the AV railtie to use the new home for cache_asset_timestam…
53 end
54
22fcef90 »
2011-04-19 Actually add an abstract class, so it is easier to get rid of old ass…
55 asset_id = rails_asset_id(source)
56 if asset_id.empty?
57 source
58 else
59 "#{source}?#{asset_id}"
60 end
61 end
62
63 mattr_accessor :asset_ids_cache
64 self.asset_ids_cache = {}
ce1f8767 »
2010-11-15 corrected the AV railtie to use the new home for cache_asset_timestam…
65
22fcef90 »
2011-04-19 Actually add an abstract class, so it is easier to get rid of old ass…
66 mattr_accessor :asset_ids_cache_guard
67 self.asset_ids_cache_guard = Mutex.new
ce1f8767 »
2010-11-15 corrected the AV railtie to use the new home for cache_asset_timestam…
68
22fcef90 »
2011-04-19 Actually add an abstract class, so it is easier to get rid of old ass…
69 # Use the RAILS_ASSET_ID environment variable or the source's
70 # modification time as its cache-busting asset id.
71 def rails_asset_id(source)
72 if asset_id = ENV["RAILS_ASSET_ID"]
73 asset_id
74 else
75 if self.cache_asset_ids && (asset_id = self.asset_ids_cache[source])
ce1f8767 »
2010-11-15 corrected the AV railtie to use the new home for cache_asset_timestam…
76 asset_id
0ff1c593 »
2010-11-15 reorganised the the common asset helpers module into a class and have…
77 else
22fcef90 »
2011-04-19 Actually add an abstract class, so it is easier to get rid of old ass…
78 path = File.join(config.assets_dir, source)
79 asset_id = File.exist?(path) ? File.mtime(path).to_i.to_s : ''
ce1f8767 »
2010-11-15 corrected the AV railtie to use the new home for cache_asset_timestam…
80
22fcef90 »
2011-04-19 Actually add an abstract class, so it is easier to get rid of old ass…
81 if self.cache_asset_ids
82 add_to_asset_ids_cache(source, asset_id)
ce1f8767 »
2010-11-15 corrected the AV railtie to use the new home for cache_asset_timestam…
83 end
0ff1c593 »
2010-11-15 reorganised the the common asset helpers module into a class and have…
84
22fcef90 »
2011-04-19 Actually add an abstract class, so it is easier to get rid of old ass…
85 asset_id
0ff1c593 »
2010-11-15 reorganised the the common asset helpers module into a class and have…
86 end
87 end
22fcef90 »
2011-04-19 Actually add an abstract class, so it is easier to get rid of old ass…
88 end
0ff1c593 »
2010-11-15 reorganised the the common asset helpers module into a class and have…
89 end
90
91 end
92 end
db5adf2d »
2011-05-28 fixed asset_paths when called from sprockets for relative_url_root
93 end
Something went wrong with that request. Please try again.