http-cat-rails 1.1.0 → 2.0.0
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 +28 -0
- data/app/controllers/errors_controller.rb +1 -1
- data/lib/http/cat/rails/version.rb +1 -1
- data/lib/http/cat/rails.rb +1 -0
- data/lib/http/cat/static_page.rb +37 -0
- data/lib/tasks/http/cat/rails_tasks.rake +16 -4
- metadata +25 -10
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5c225ac7bccff14f39c6835fd933f4f2b43e9fa49c571c95060864cc90f3639a
|
|
4
|
+
data.tar.gz: 35f190ea28763b2f74dfe62e0c9773338949595b57c7668c4bf2aa228b1f2995
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '07776684bffaad475619e00b90513f53fca45f38516db4897fba6f235d7119a30b40f04455a66daa144a061e8ee0ef62a5ca266648aa1d881e0b803375df8fb1'
|
|
7
|
+
data.tar.gz: d355d14a3bba21df8f98adb0e9f0ea5b5debd2629bdce2e1d59daeaa9401e0c0808a5295d1dfe4e38528e9e33e95d85ff5f342c6645e1023fe6c0895eb13a4eb
|
data/README.md
CHANGED
|
@@ -89,6 +89,34 @@ This gem won't work if your application.rb or <your_environment>.rb contains the
|
|
|
89
89
|
config.consider_all_requests_local = true
|
|
90
90
|
```
|
|
91
91
|
|
|
92
|
+
## Static error pages
|
|
93
|
+
|
|
94
|
+
Some errors (e.g. `500`) shouldn't depend on Rails to be displayed: if Rails itself is broken, rendering the error page
|
|
95
|
+
can raise another 500 and loop. For these, generate a self-contained HTML file (CSS inline, image loaded from your
|
|
96
|
+
`base_url`) into your app's `public/` folder:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
$ bin/rails "http_cat:generate[500,502,503]"
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
- Writes `public/<code>.html` for each code, **overwriting** any existing file with the same name
|
|
103
|
+
- Codes must be keys of `status_codes`, otherwise the task aborts and writes nothing
|
|
104
|
+
- Uses `base_url`, `extension` and `status_codes` from your configuration; `layout` is ignored (the page has its own
|
|
105
|
+
black background, and the image keeps the `http_error_image` class)
|
|
106
|
+
- Re-run it after changing the configuration
|
|
107
|
+
|
|
108
|
+
The generated files are not used automatically while `exceptions_app` is set to your routes: serve them from your web
|
|
109
|
+
server instead, e.g. nginx: `error_page 500 502 503 /500.html;` (one `error_page` per code, with its own file).
|
|
110
|
+
|
|
111
|
+
## Development
|
|
112
|
+
|
|
113
|
+
Tests run with RSpec, against a minimal Rails app, on each supported Rails version:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
$ BUNDLE_GEMFILE=gemfiles/rails_8.1.2.gemfile bundle install
|
|
117
|
+
$ BUNDLE_GEMFILE=gemfiles/rails_8.1.2.gemfile bundle exec rspec
|
|
118
|
+
```
|
|
119
|
+
|
|
92
120
|
## Contributing
|
|
93
121
|
|
|
94
122
|
It's a small project, but if you want to contribute feel free to send a Pull Request, or open an Issue
|
|
@@ -2,7 +2,7 @@ class ErrorsController < ApplicationController
|
|
|
2
2
|
Http::Cat::Rails.status_codes.each do |code, desc|
|
|
3
3
|
define_method(desc.downcase.gsub(' ', '_')) do
|
|
4
4
|
@code = code
|
|
5
|
-
render
|
|
5
|
+
render "error", layout: Http::Cat::Rails.layout, status: code.to_s.to_i
|
|
6
6
|
end
|
|
7
7
|
end
|
|
8
8
|
end
|
data/lib/http/cat/rails.rb
CHANGED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require "erb"
|
|
2
|
+
|
|
3
|
+
module Http
|
|
4
|
+
module Cat
|
|
5
|
+
module Rails
|
|
6
|
+
# Self-contained HTML (inline CSS, no Rails/asset pipeline needed to serve it)
|
|
7
|
+
TEMPLATE = ERB.new(<<~HTML, trim_mode: "-")
|
|
8
|
+
<!DOCTYPE html>
|
|
9
|
+
<html>
|
|
10
|
+
<head>
|
|
11
|
+
<meta charset="utf-8">
|
|
12
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
13
|
+
<title><%= code %> <%= title %></title>
|
|
14
|
+
<style>
|
|
15
|
+
body { margin: 0; }
|
|
16
|
+
.http_error_container { width: 100vw; height: 100vh; background: black; display: flex; align-items: center; justify-content: center; }
|
|
17
|
+
.http_error_image { width: 50%; }
|
|
18
|
+
</style>
|
|
19
|
+
</head>
|
|
20
|
+
<body>
|
|
21
|
+
<div class="http_error_container">
|
|
22
|
+
<img class="http_error_image" src="<%= src %>" alt="<%= code %> <%= title %>">
|
|
23
|
+
</div>
|
|
24
|
+
</body>
|
|
25
|
+
</html>
|
|
26
|
+
HTML
|
|
27
|
+
|
|
28
|
+
def self.static_html(code)
|
|
29
|
+
code = code.to_s
|
|
30
|
+
title = status_codes.fetch(code.to_sym) { status_codes.fetch(code) { raise ArgumentError, "unknown status code: #{code}" } }
|
|
31
|
+
ext = extension ? ".#{extension}" : ""
|
|
32
|
+
h = ERB::Util.method(:html_escape)
|
|
33
|
+
TEMPLATE.result_with_hash(code: h.(code), title: h.(title), src: h.("#{base_url}#{code}#{ext}"))
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
namespace :http_cat do
|
|
2
|
+
desc "Generate static public/<code>.html error pages (overwrites existing). Usage: rake \"http_cat:generate[500,502]\""
|
|
3
|
+
task :generate, [:code] => :environment do |_, args|
|
|
4
|
+
codes = [args[:code], *args.extras].compact.map(&:to_s)
|
|
5
|
+
abort "No status code given. Usage: rake \"http_cat:generate[500,502]\"" if codes.empty?
|
|
6
|
+
|
|
7
|
+
unknown = codes.reject { |c| Http::Cat::Rails.status_codes.key?(c.to_sym) || Http::Cat::Rails.status_codes.key?(c) }
|
|
8
|
+
abort "Unknown status code(s): #{unknown.join(', ')}" if unknown.any?
|
|
9
|
+
|
|
10
|
+
codes.each do |code|
|
|
11
|
+
path = Rails.public_path.join("#{code}.html")
|
|
12
|
+
File.write(path, Http::Cat::Rails.static_html(code))
|
|
13
|
+
puts "Written #{path}"
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
metadata
CHANGED
|
@@ -1,29 +1,43 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: http-cat-rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Gamberi Elia
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-12-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rspec
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '3.13'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '3.13'
|
|
13
27
|
- !ruby/object:Gem::Dependency
|
|
14
28
|
name: rails
|
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
|
16
30
|
requirements:
|
|
17
31
|
- - ">="
|
|
18
32
|
- !ruby/object:Gem::Version
|
|
19
|
-
version:
|
|
33
|
+
version: '6.1'
|
|
20
34
|
type: :runtime
|
|
21
35
|
prerelease: false
|
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
37
|
requirements:
|
|
24
38
|
- - ">="
|
|
25
39
|
- !ruby/object:Gem::Version
|
|
26
|
-
version:
|
|
40
|
+
version: '6.1'
|
|
27
41
|
description: Configurable Ruby gem that replaces error pages with http.cat image
|
|
28
42
|
email:
|
|
29
43
|
- me@gimbaro.dev
|
|
@@ -42,15 +56,16 @@ files:
|
|
|
42
56
|
- lib/http/cat/rails.rb
|
|
43
57
|
- lib/http/cat/rails/engine.rb
|
|
44
58
|
- lib/http/cat/rails/version.rb
|
|
59
|
+
- lib/http/cat/static_page.rb
|
|
45
60
|
- lib/tasks/http/cat/rails_tasks.rake
|
|
46
|
-
homepage:
|
|
61
|
+
homepage:
|
|
47
62
|
licenses:
|
|
48
63
|
- MIT
|
|
49
64
|
metadata:
|
|
50
65
|
allowed_push_host: https://rubygems.org
|
|
51
66
|
homepage_uri: https://github.com/Gimbardo/http-cat-rails
|
|
52
67
|
source_code_uri: https://github.com/Gimbardo/http-cat-rails
|
|
53
|
-
post_install_message:
|
|
68
|
+
post_install_message:
|
|
54
69
|
rdoc_options: []
|
|
55
70
|
require_paths:
|
|
56
71
|
- lib
|
|
@@ -58,15 +73,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
58
73
|
requirements:
|
|
59
74
|
- - ">="
|
|
60
75
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '
|
|
76
|
+
version: '2.7'
|
|
62
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
78
|
requirements:
|
|
64
79
|
- - ">="
|
|
65
80
|
- !ruby/object:Gem::Version
|
|
66
81
|
version: '0'
|
|
67
82
|
requirements: []
|
|
68
|
-
rubygems_version: 3.
|
|
69
|
-
signing_key:
|
|
83
|
+
rubygems_version: 3.4.19
|
|
84
|
+
signing_key:
|
|
70
85
|
specification_version: 4
|
|
71
86
|
summary: Configurable Ruby gem that replaces error pages with http.cat image
|
|
72
87
|
test_files: []
|