error_page_assets 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 16bbd1059b6b3587f6f2a9255a4b5b99b2c92303
4
- data.tar.gz: 6518f7a7f144ae70e68d0b00070dadf45195ec62
3
+ metadata.gz: c94f48a67e85f4d220fc08f05f865f51acde686c
4
+ data.tar.gz: 0e48288914c588abadc2a62f6060a021e3635724
5
5
  SHA512:
6
- metadata.gz: a1eeab19d61714b3f5c6205cadeec29aea56c6014a0929679cda84d92295173fb0815edc0077c1adc927b143dea9338066e77d1b043d71c051d68ec6e6cd6e12
7
- data.tar.gz: a4eb0112a9f0dc5751572f45e1908db88fc2fa1fa1357333e21aed505ad1eb2cbfce8a01fd8871b3a3e0db2f6564274b5cc341a459dc3304bd9f506609ddaaf5
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 dropped into `/public`.
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 exists and includes your most recent code
46
+ # (public/404.html is your newest code)
47
47
  ```
48
48
 
49
49
  Your error pages are automatically generated along with the
@@ -1,3 +1,3 @@
1
1
  module ErrorPageAssets
2
- VERSION = "0.1"
2
+ VERSION = "0.2"
3
3
  end
@@ -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
- namespace :precompile do
13
- def log msg
14
- # try to log like Sprockets even though their stuff is all private
15
- STDERR.puts msg
16
- Rails.logger.info(msg) if Rails.respond_to?(:logger)
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
- def copy_error_files
20
- pattern = Rails.root.join('public', 'assets', "[0-9][0-9][0-9]*.html")
21
- groups = Dir[pattern].group_by { |s| File.basename(s)[0..2] }
22
- groups.sort_by { |base,_| base }.each do |base, group|
23
- latest = group.sort_by { |f| File.mtime(f) }.last
24
- log "copy #{latest} to public/#{base}.html"
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
- desc 'Copies the newest error pages into /public'
41
+ namespace :clobber do
42
+ desc 'Remove the error page assets in /public'
30
43
  task :error_pages do
31
- copy_error_files
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
- Rake.application['assets:precompile:error_pages'].invoke
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
@@ -1,6 +1,9 @@
1
1
  namespace :assets do
2
2
  desc 'stubs assets:precompile for testing'
3
3
  task :precompile do
4
- puts 'precompiling'
4
+ end
5
+
6
+ desc 'stubs assets:clobber for testing'
7
+ task :clobber do
5
8
  end
6
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: error_page_assets
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Bronson