error_page_assets 0.1
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 +7 -0
- data/.gitignore +22 -0
- data/.rspec +2 -0
- data/Gemfile +8 -0
- data/Guardfile +17 -0
- data/LICENSE.txt +22 -0
- data/README.md +99 -0
- data/Rakefile +6 -0
- data/error_page_assets.gemspec +23 -0
- data/lib/error_page_assets/railtie.rb +13 -0
- data/lib/error_page_assets/version.rb +3 -0
- data/lib/error_page_assets.rb +3 -0
- data/lib/tasks/error_page_assets.rake +35 -0
- data/spec/error_page_assets_spec.rb +30 -0
- data/spec/public/assets/404-digestnew.html +0 -0
- data/spec/public/assets/404-digestold.html +0 -0
- data/spec/public/assets/500.html +0 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/stub_assets_precompile.rake +6 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 16bbd1059b6b3587f6f2a9255a4b5b99b2c92303
|
4
|
+
data.tar.gz: 6518f7a7f144ae70e68d0b00070dadf45195ec62
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a1eeab19d61714b3f5c6205cadeec29aea56c6014a0929679cda84d92295173fb0815edc0077c1adc927b143dea9338066e77d1b043d71c051d68ec6e6cd6e12
|
7
|
+
data.tar.gz: a4eb0112a9f0dc5751572f45e1908db88fc2fa1fa1357333e21aed505ad1eb2cbfce8a01fd8871b3a3e0db2f6564274b5cc341a459dc3304bd9f506609ddaaf5
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
guard :bundler do
|
2
|
+
watch('Gemfile')
|
3
|
+
watch(/^.+\.gemspec/)
|
4
|
+
end
|
5
|
+
|
6
|
+
guard :rspec, cmd: 'rspec' do
|
7
|
+
# run all specs if any Ruby file is modified
|
8
|
+
watch(%r{^lib/.+\.rb}) { "spec" }
|
9
|
+
# watch(%r{.*\.rb})
|
10
|
+
# watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
11
|
+
|
12
|
+
# re-run just the spec
|
13
|
+
watch(%r{^spec/.+_spec\.rb$})
|
14
|
+
|
15
|
+
# run all specs if the helper is modified
|
16
|
+
watch(%r{spec/spec_helper\.rb}) { "spec" }
|
17
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Scott Bronson
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
# Error Page Assets
|
2
|
+
|
3
|
+
Let the asset pipeline generate your static error pages.
|
4
|
+
|
5
|
+
This gem lets you include Sprockets-generated CSS and JS files,
|
6
|
+
complete with cache-busting digests, in `public/404.html` and friends.
|
7
|
+
You can even use layouts.
|
8
|
+
|
9
|
+
No monkeypatching, no Rails engines, no routing, just idiomatic code.
|
10
|
+
The asset pipeline will generate static files so your
|
11
|
+
web server shows your custom error pages even when your app is down hard.
|
12
|
+
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
Add this line to your Gemfile:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
gem 'error_page_assets'
|
20
|
+
```
|
21
|
+
|
22
|
+
Move your error pages into the asset pipeline
|
23
|
+
|
24
|
+
```sh
|
25
|
+
git mv public/404.html app/assets/html/404.html.erb
|
26
|
+
git mv public/422.html app/assets/html/422.html.erb
|
27
|
+
git mv public/500.html app/assets/html/500.html.erb
|
28
|
+
```
|
29
|
+
|
30
|
+
And tell the asset pipeline to compile your error pages.
|
31
|
+
In `config/application.rb`:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
config.assets.precompile += %w[404.html 422.html 500.html]
|
35
|
+
```
|
36
|
+
|
37
|
+
|
38
|
+
## Usage
|
39
|
+
|
40
|
+
Whenever assets are precompiled (i.e. during each deploy),
|
41
|
+
your error pages will be generated and dropped into `/public`.
|
42
|
+
|
43
|
+
```sh
|
44
|
+
# public/404.html doesn't exist
|
45
|
+
rails assets:precompile
|
46
|
+
# public/404.html exists and includes your most recent code
|
47
|
+
```
|
48
|
+
|
49
|
+
Your error pages are automatically generated along with the
|
50
|
+
rest of your assets each time you deploy.
|
51
|
+
|
52
|
+
### Rails Helpers
|
53
|
+
|
54
|
+
Now you can update your error pages to use Rails helpers:
|
55
|
+
|
56
|
+
```erb
|
57
|
+
old:
|
58
|
+
<link href="/css/application.css" media="all" rel="stylesheet"/>
|
59
|
+
<script src="/js/application.js"></script>
|
60
|
+
new:
|
61
|
+
<%= stylesheet_link_tag 'application', media: 'all', digest: true %>
|
62
|
+
<%= javascript_include_tag "application" %>
|
63
|
+
```
|
64
|
+
|
65
|
+
|
66
|
+
## Layouts
|
67
|
+
|
68
|
+
The Asset pipeline knows how to include stylesheets in your html,
|
69
|
+
but it doesn't know how to render layouts. If you'd like your
|
70
|
+
static error pages to use layouts too, use the
|
71
|
+
[render anywhere](https://github.com/yappbox/render_anywhere) gem.
|
72
|
+
|
73
|
+
|
74
|
+
## Roadmap
|
75
|
+
|
76
|
+
* Do we still need to use digest:true?
|
77
|
+
* Use an initializer to automatically add error pages to the sprockets config?
|
78
|
+
* Rails generator to move your error pages?
|
79
|
+
|
80
|
+
|
81
|
+
## Alternatives
|
82
|
+
|
83
|
+
* Inspired by: http://icelab.com.au/articles/precompiled-rails-static-404-and-500-pages/
|
84
|
+
* Rails Engine: https://github.com/marcusg/dynamic_error_pages
|
85
|
+
* Dynamic Route: https://github.com/eric1234/better_exception_app
|
86
|
+
|
87
|
+
|
88
|
+
## License
|
89
|
+
|
90
|
+
Pain-free MIT.
|
91
|
+
|
92
|
+
|
93
|
+
## Contributing
|
94
|
+
|
95
|
+
My app isn't localized so I haven't bothered with `I18n.available_locales`.
|
96
|
+
If you want localization, please file an issue.
|
97
|
+
|
98
|
+
To make this gem less imperfect, please submit your issues and patches on
|
99
|
+
[GitHub](https://github.com/bronson/error_page_assets/).
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'error_page_assets/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "error_page_assets"
|
7
|
+
spec.version = ErrorPageAssets::VERSION
|
8
|
+
spec.authors = ["Scott Bronson"]
|
9
|
+
spec.email = ["brons_errpage@rinspin.com"]
|
10
|
+
spec.summary = "Uses the asset pipeline to generate your static error pages."
|
11
|
+
# spec.description = "Uses the asset pipeline to generate your static error pages."
|
12
|
+
spec.homepage = "http://github.com/bronson/static_error_pages"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rspec"
|
23
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
# Use the Asset Pipeline to generate static error pages.
|
4
|
+
# For example, /app/assets/html/404.html.erb will be compiled to /public/404.html
|
5
|
+
|
6
|
+
|
7
|
+
Rake::Task['assets:precompile'].enhance do
|
8
|
+
Rake::Task['assets:precompile:error_pages'].invoke
|
9
|
+
end
|
10
|
+
|
11
|
+
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)
|
17
|
+
end
|
18
|
+
|
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")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
desc 'Copies the newest error pages into /public'
|
30
|
+
task :error_pages do
|
31
|
+
copy_error_files
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rake'
|
2
|
+
|
3
|
+
describe 'assets:precompile:error_pages' do
|
4
|
+
before do
|
5
|
+
# load rake task
|
6
|
+
Rake.application = Rake::Application.new
|
7
|
+
Rake.application.rake_require('stub_assets_precompile', ['spec'])
|
8
|
+
Rake.application.rake_require('error_page_assets', ['lib/tasks'])
|
9
|
+
|
10
|
+
# allow rake task to call Rails.root.join
|
11
|
+
stub_const('Rails', Class.new)
|
12
|
+
allow(Rails).to receive_message_chain(:root, :join) { |*args| File.join('spec', *args) }
|
13
|
+
end
|
14
|
+
|
15
|
+
it "copies the error pages" do
|
16
|
+
# ensure the rake task uses the most recent asset file
|
17
|
+
expect(File).to receive(:mtime).with('spec/public/assets/404-digestnew.html').and_return(Time.now)
|
18
|
+
expect(File).to receive(:mtime).with('spec/public/assets/404-digestold.html').and_return(Time.now - 3600)
|
19
|
+
expect(File).to receive(:mtime).with('spec/public/assets/500.html').and_return(Time.now)
|
20
|
+
|
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
|
+
# suppress our logging while testing
|
26
|
+
expect(STDERR).to receive(:puts).twice
|
27
|
+
|
28
|
+
Rake.application['assets:precompile:error_pages'].invoke
|
29
|
+
end
|
30
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: error_page_assets
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Scott Bronson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- brons_errpage@rinspin.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- Gemfile
|
65
|
+
- Guardfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- error_page_assets.gemspec
|
70
|
+
- lib/error_page_assets.rb
|
71
|
+
- lib/error_page_assets/railtie.rb
|
72
|
+
- lib/error_page_assets/version.rb
|
73
|
+
- lib/tasks/error_page_assets.rake
|
74
|
+
- spec/error_page_assets_spec.rb
|
75
|
+
- spec/public/assets/404-digestnew.html
|
76
|
+
- spec/public/assets/404-digestold.html
|
77
|
+
- spec/public/assets/500.html
|
78
|
+
- spec/spec_helper.rb
|
79
|
+
- spec/stub_assets_precompile.rake
|
80
|
+
homepage: http://github.com/bronson/static_error_pages
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
metadata: {}
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 2.4.5
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: Uses the asset pipeline to generate your static error pages.
|
104
|
+
test_files:
|
105
|
+
- spec/error_page_assets_spec.rb
|
106
|
+
- spec/public/assets/404-digestnew.html
|
107
|
+
- spec/public/assets/404-digestold.html
|
108
|
+
- spec/public/assets/500.html
|
109
|
+
- spec/spec_helper.rb
|
110
|
+
- spec/stub_assets_precompile.rake
|