error_page_assets 0.1 → 0.2
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.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/error_page_assets/version.rb +1 -1
- data/lib/tasks/error_page_assets.rake +30 -14
- data/spec/error_page_assets_spec.rb +14 -9
- data/spec/stub_assets_precompile.rake +4 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c94f48a67e85f4d220fc08f05f865f51acde686c
|
4
|
+
data.tar.gz: 0e48288914c588abadc2a62f6060a021e3635724
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9bf39fb7184d1c9eebbc15cbf965439a0088a05f064cb0b1a00e51570ae65a008b771048f7a30b8a4f8d3928bc83a616e6ce02e7867171045bb729bb8daaea46
|
7
|
+
data.tar.gz: b953fe9850e031dace399c59129b40ab4bab79fc17ea801e53ff34f50ff0a211bad268077f173c432fe9e768f941319e1f0b01ee5d7bfb470ea7c85b6096558a
|
data/README.md
CHANGED
@@ -38,12 +38,12 @@ config.assets.precompile += %w[404.html 422.html 500.html]
|
|
38
38
|
## Usage
|
39
39
|
|
40
40
|
Whenever assets are precompiled (i.e. during each deploy),
|
41
|
-
your error pages will be generated and
|
41
|
+
your error pages will be generated and saved in `/public`.
|
42
42
|
|
43
43
|
```sh
|
44
|
-
# public/404.html doesn't exist
|
44
|
+
# (public/404.html doesn't exist)
|
45
45
|
rails assets:precompile
|
46
|
-
# public/404.html
|
46
|
+
# (public/404.html is your newest code)
|
47
47
|
```
|
48
48
|
|
49
49
|
Your error pages are automatically generated along with the
|
@@ -8,27 +8,43 @@ Rake::Task['assets:precompile'].enhance do
|
|
8
8
|
Rake::Task['assets:precompile:error_pages'].invoke
|
9
9
|
end
|
10
10
|
|
11
|
+
Rake::Task['assets:clobber'].enhance ['assets:clobber:error_pages']
|
12
|
+
|
13
|
+
|
11
14
|
namespace :assets do
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
def log msg
|
16
|
+
# try to log like Sprockets even though their stuff is all private
|
17
|
+
STDERR.puts msg
|
18
|
+
Rails.logger.info(msg) if Rails.respond_to?(:logger) && Rails.logger
|
19
|
+
end
|
20
|
+
|
21
|
+
def process_error_files
|
22
|
+
pattern = Rails.root.join('public', 'assets', "[0-9][0-9][0-9]*.html")
|
23
|
+
groups = Dir[pattern].group_by { |s| File.basename(s)[0..2] }
|
24
|
+
groups.sort_by { |base,_| base }.each do |base, group|
|
25
|
+
src = group.sort_by { |f| File.mtime(f) }.last
|
26
|
+
dst = Rails.root.join('public', "#{base}.html")
|
27
|
+
yield src, dst
|
17
28
|
end
|
29
|
+
end
|
18
30
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
FileUtils.cp latest, Rails.root.join('public', "#{base}.html")
|
31
|
+
namespace :precompile do
|
32
|
+
desc 'Copy the newest error page assets into /public'
|
33
|
+
task :error_pages do
|
34
|
+
process_error_files do |src,dst|
|
35
|
+
log "copy #{src} to #{dst}"
|
36
|
+
FileUtils.cp src, dst
|
26
37
|
end
|
27
38
|
end
|
39
|
+
end
|
28
40
|
|
29
|
-
|
41
|
+
namespace :clobber do
|
42
|
+
desc 'Remove the error page assets in /public'
|
30
43
|
task :error_pages do
|
31
|
-
|
44
|
+
process_error_files do |src,dst|
|
45
|
+
log "clobber #{dst}"
|
46
|
+
FileUtils.rm_f dst
|
47
|
+
end
|
32
48
|
end
|
33
49
|
end
|
34
50
|
end
|
@@ -1,30 +1,35 @@
|
|
1
1
|
require 'rake'
|
2
2
|
|
3
3
|
describe 'assets:precompile:error_pages' do
|
4
|
-
before do
|
5
|
-
# load rake task
|
4
|
+
before(:all) do
|
6
5
|
Rake.application = Rake::Application.new
|
7
6
|
Rake.application.rake_require('stub_assets_precompile', ['spec'])
|
8
7
|
Rake.application.rake_require('error_page_assets', ['lib/tasks'])
|
8
|
+
end
|
9
9
|
|
10
|
+
before do
|
10
11
|
# allow rake task to call Rails.root.join
|
11
12
|
stub_const('Rails', Class.new)
|
12
13
|
allow(Rails).to receive_message_chain(:root, :join) { |*args| File.join('spec', *args) }
|
13
|
-
end
|
14
14
|
|
15
|
-
it "copies the error pages" do
|
16
15
|
# ensure the rake task uses the most recent asset file
|
17
16
|
expect(File).to receive(:mtime).with('spec/public/assets/404-digestnew.html').and_return(Time.now)
|
18
17
|
expect(File).to receive(:mtime).with('spec/public/assets/404-digestold.html').and_return(Time.now - 3600)
|
19
18
|
expect(File).to receive(:mtime).with('spec/public/assets/500.html').and_return(Time.now)
|
20
19
|
|
21
|
-
# ensure the rake task doesn't actually perform the copies
|
22
|
-
expect(FileUtils).to receive(:cp).with('spec/public/assets/404-digestnew.html', 'spec/public/404.html')
|
23
|
-
expect(FileUtils).to receive(:cp).with('spec/public/assets/500.html', 'spec/public/500.html')
|
24
|
-
|
25
20
|
# suppress our logging while testing
|
26
21
|
expect(STDERR).to receive(:puts).twice
|
22
|
+
end
|
23
|
+
|
24
|
+
it "copies the error pages" do
|
25
|
+
expect(FileUtils).to receive(:cp).with('spec/public/assets/404-digestnew.html', 'spec/public/404.html')
|
26
|
+
expect(FileUtils).to receive(:cp).with('spec/public/assets/500.html', 'spec/public/500.html')
|
27
|
+
Rake.application['assets:precompile'].invoke
|
28
|
+
end
|
27
29
|
|
28
|
-
|
30
|
+
it "clobbers the error pages" do
|
31
|
+
expect(FileUtils).to receive(:rm_f).with('spec/public/404.html')
|
32
|
+
expect(FileUtils).to receive(:rm_f).with('spec/public/500.html')
|
33
|
+
Rake.application['assets:clobber'].invoke
|
29
34
|
end
|
30
35
|
end
|