turbo-sprockets-rails3 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +22 -8
- data/lib/turbo-sprockets/tasks/assets.rake +27 -3
- data/lib/turbo-sprockets/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -42,10 +42,12 @@ Enjoy your lightning fast deploys!
|
|
42
42
|
|
43
43
|
## Removing Expired Assets
|
44
44
|
|
45
|
-
`turbo-sprockets-rails3` can now remove expired assets after each compile.
|
46
|
-
|
45
|
+
`turbo-sprockets-rails3` can now remove expired assets after each compile. If the environment variable `CLEAN_EXPIRED_ASSETS` is set to `true`, the `assets:clean_expired` task will be run after `assets:precompile`.
|
46
|
+
An asset will be deleted if it is no longer referenced by `manifest.yml`, and is more than 7 days (default) older than the **previous** compiled assets.
|
47
47
|
|
48
|
-
|
48
|
+
Before the `assets:precompile` task runs, it stores the modification time of the current `manifest.yml` in a file called `expire_assets_after.yml`. When the `assets:clean_expired` task runs, it looks up the time in `expire_assets_after.yml`, and won't expire any assets that were created more recently than that time.
|
49
|
+
|
50
|
+
To expire old assets after precompile, you should compile assets by running `CLEAN_EXPIRED_ASSETS=true rake assets:precompile`. Alternatively, you can run `rake assets:precompile assets:clean_expired`.
|
49
51
|
|
50
52
|
You can configure the expiry time by setting `config.assets.expire_after` in `config/environments/production.rb`.
|
51
53
|
An expiry time of 2 weeks could be configured with the following code:
|
@@ -86,13 +88,25 @@ gem "capistrano", :github => "ndbroadbent/capistrano", :branch => "assets_rollba
|
|
86
88
|
|
87
89
|
### Heroku
|
88
90
|
|
89
|
-
|
90
|
-
|
91
|
-
|
91
|
+
I've created a Heroku Buildpack for `turbo-sprockets-rails3` that keeps your assets cached between deploys, so you only need to recompile changed assets. It will automatically expire old assets that are no longer referenced by `manifest.yml` after 7 days, so your `public/assets` folder won't grow out of control.
|
92
|
+
|
93
|
+
To create a new application on Heroku using this buildpack, you can run:
|
94
|
+
|
95
|
+
```bash
|
96
|
+
heroku create --buildpack https://github.com/ndbroadbent/heroku-buildpack-turbo-sprockets.git
|
97
|
+
```
|
98
|
+
|
99
|
+
To add the buildpack to an existing app, you can run:
|
100
|
+
|
101
|
+
```bash
|
102
|
+
heroku config:add BUILDPACK_URL=https://github.com/ndbroadbent/heroku-buildpack-turbo-sprockets.git
|
103
|
+
```
|
104
|
+
|
105
|
+
#### Compiling Assets on Your Local Machine
|
92
106
|
|
93
|
-
|
107
|
+
You can also compile assets on your local machine, and commit the compiled assets. You might want to do this if your local machine is a lot faster than the Heroku VM, or if you also want to generate other files, such as static pages. When you push compiled assets to Heroku, it will automatically skip the `assets:precompile` task.
|
94
108
|
|
95
|
-
I've automated this process in a Rake task for my own projects.
|
109
|
+
I've automated this process in a Rake task for my own projects. The task creates a deployment repo at `tmp/heroku_deploy` so that you can keep working while deploying, and it also rebases and amends the assets commit to keep your repo's history from growing out of control. You can find the deploy task in a gist at https://gist.github.com/3802355. Save this file to `lib/tasks/deploy.rake`, and make sure you have added a `heroku` remote to your repo. You will now be able to run `rake deploy` to deploy your app to Heroku.
|
96
110
|
|
97
111
|
## Debugging
|
98
112
|
|
@@ -61,6 +61,18 @@ namespace :assets do
|
|
61
61
|
env = Rails.application.assets
|
62
62
|
target = File.join(::Rails.public_path, config.assets.prefix)
|
63
63
|
|
64
|
+
# Create `public/assets/expire_assets_after.yml`, containing the timestamp of the previous manifest.yml
|
65
|
+
# (Only for first run)
|
66
|
+
if digest.nil?
|
67
|
+
manifest_path = config.assets.manifest || target
|
68
|
+
manifest_file = File.join(manifest_path, 'manifest.yml')
|
69
|
+
if File.exist?(manifest_file)
|
70
|
+
File.open(File.join(target, 'expire_assets_after.yml'), 'w') do |f|
|
71
|
+
f.puts YAML.dump(:expire_assets_after => File.mtime(manifest_file))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
64
76
|
# If processing non-digest assets, and compiled digest files are
|
65
77
|
# present, then generate non-digest assets from existing assets.
|
66
78
|
# It is assumed that `assets:precompile:nondigest` won't be run manually
|
@@ -108,9 +120,10 @@ namespace :assets do
|
|
108
120
|
end
|
109
121
|
|
110
122
|
namespace :clean_expired do
|
111
|
-
task :all do
|
123
|
+
task :all => ["assets:environment"] do
|
112
124
|
# Remove assets that aren't referenced by manifest.yml,
|
113
|
-
# and are older than `config.assets.expire_after` (default 7 days)
|
125
|
+
# and are older than `config.assets.expire_after` (default 7 days),
|
126
|
+
# counting from the **previous** compile.
|
114
127
|
config = ::Rails.application.config
|
115
128
|
expire_after = config.assets.expire_after || 7.days
|
116
129
|
public_asset_path = File.join(::Rails.public_path, config.assets.prefix)
|
@@ -126,8 +139,19 @@ namespace :assets do
|
|
126
139
|
logical_path = asset.sub("#{public_asset_path}/", '')
|
127
140
|
|
128
141
|
unless logical_path.in?(known_assets)
|
142
|
+
# If 'expire_assets_after.yml' file exists, use that as the base time for expire_after
|
143
|
+
# Otherwise, use Time.now
|
144
|
+
expire_after_base_time = Time.now
|
145
|
+
|
146
|
+
expire_after_file = File.join(::Rails.public_path, config.assets.prefix, 'expire_assets_after.yml')
|
147
|
+
if File.exist?(expire_after_file)
|
148
|
+
if time = YAML.load_file(expire_after_file)[:expire_assets_after]
|
149
|
+
expire_after_base_time = time
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
129
153
|
# Delete asset if older than expire_after seconds
|
130
|
-
if File.mtime(asset) < (
|
154
|
+
if File.mtime(asset) < (expire_after_base_time - expire_after)
|
131
155
|
::Rails.logger.debug "Removing expired asset: #{logical_path}"
|
132
156
|
FileUtils.rm_f asset
|
133
157
|
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.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sprockets
|