turbo-sprockets-rails3 0.2.7 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/turbo-sprockets/tasks/assets.rake +37 -11
- data/lib/turbo-sprockets/version.rb +1 -1
- metadata +3 -3
@@ -35,6 +35,15 @@ namespace :assets do
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
# Returns an array of assets recognized by config.assets.digests,
|
39
|
+
# including gzipped assets and manifests
|
40
|
+
def known_assets
|
41
|
+
assets = Rails.application.config.assets.digests.to_a.flatten.map do |asset|
|
42
|
+
[asset, "#{asset}.gz"]
|
43
|
+
end.flatten
|
44
|
+
assets + %w(manifest.yml sources_manifest.yml)
|
45
|
+
end
|
46
|
+
|
38
47
|
desc "Compile all the assets named in config.assets.precompile"
|
39
48
|
task :precompile do
|
40
49
|
invoke_or_reboot_rake_task "assets:precompile:all"
|
@@ -61,6 +70,18 @@ namespace :assets do
|
|
61
70
|
env = Rails.application.assets
|
62
71
|
target = File.join(::Rails.public_path, config.assets.prefix)
|
63
72
|
|
73
|
+
# Before first compile, set the mtime of all current assets to current time.
|
74
|
+
# This time reflects the last time the assets were being used.
|
75
|
+
if digest.nil?
|
76
|
+
::Rails.logger.debug "Updating mtimes for current assets..."
|
77
|
+
known_assets.each do |asset|
|
78
|
+
full_path = File.join(target, asset)
|
79
|
+
if File.exist?(full_path)
|
80
|
+
File.utime(Time.now, Time.now, full_path)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
64
85
|
# If processing non-digest assets, and compiled digest files are
|
65
86
|
# present, then generate non-digest assets from existing assets.
|
66
87
|
# It is assumed that `assets:precompile:nondigest` won't be run manually
|
@@ -107,26 +128,31 @@ namespace :assets do
|
|
107
128
|
invoke_or_reboot_rake_task "assets:clean_expired:all"
|
108
129
|
end
|
109
130
|
|
110
|
-
# Remove assets that
|
131
|
+
# Remove assets that haven't been deployed since `config.assets.expire_after` (default 1 day).
|
132
|
+
# This provides a buffer between deploys, so that older assets can still be requested.
|
133
|
+
# The precompile task updates the mtime of the current assets before compiling,
|
134
|
+
# which indicates when they were last in use.
|
135
|
+
#
|
136
|
+
# The current assets are ignored, which is faster than the alternative of
|
137
|
+
# setting their mtimes only to check them again.
|
111
138
|
namespace :clean_expired do
|
112
139
|
task :all => ["assets:environment"] do
|
113
140
|
config = ::Rails.application.config
|
141
|
+
expire_after = config.assets.expire_after || 1.day
|
114
142
|
public_asset_path = File.join(::Rails.public_path, config.assets.prefix)
|
115
143
|
|
116
|
-
|
117
|
-
# including gzipped assets and manifests
|
118
|
-
known_assets = Rails.application.config.assets.digests.to_a.flatten.map do |asset|
|
119
|
-
[asset, "#{asset}.gz"]
|
120
|
-
end.flatten
|
121
|
-
known_assets += %w(manifest.yml sources_manifest.yml)
|
144
|
+
@known_assets = known_assets
|
122
145
|
|
123
146
|
Dir.glob(File.join(public_asset_path, '**/*')).each do |asset|
|
124
147
|
next if File.directory?(asset)
|
125
148
|
logical_path = asset.sub("#{public_asset_path}/", '')
|
126
|
-
|
127
|
-
unless logical_path.in?(known_assets)
|
128
|
-
|
129
|
-
|
149
|
+
|
150
|
+
unless logical_path.in?(@known_assets)
|
151
|
+
# Delete asset if not used for more than expire_after seconds
|
152
|
+
if File.mtime(asset) < (Time.now - expire_after)
|
153
|
+
::Rails.logger.debug "Removing expired asset: #{logical_path}"
|
154
|
+
FileUtils.rm_f asset
|
155
|
+
end
|
130
156
|
end
|
131
157
|
end
|
132
158
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: turbo-sprockets-rails3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -102,7 +102,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
102
102
|
version: '0'
|
103
103
|
segments:
|
104
104
|
- 0
|
105
|
-
hash:
|
105
|
+
hash: -4077615069865876576
|
106
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
107
|
none: false
|
108
108
|
requirements:
|
@@ -111,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
111
|
version: '0'
|
112
112
|
segments:
|
113
113
|
- 0
|
114
|
-
hash:
|
114
|
+
hash: -4077615069865876576
|
115
115
|
requirements: []
|
116
116
|
rubyforge_project:
|
117
117
|
rubygems_version: 1.8.24
|