http-cat-rails 1.0.0 → 1.1.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 +73 -4
- data/app/controllers/errors_controller.rb +1 -1
- data/app/views/errors/error.html.erb +1 -5
- data/app/views/layouts/layout_default.html.erb +5 -0
- data/lib/http/cat/configuration.rb +11 -2
- data/lib/http/cat/rails/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0791742ed1e6ca6929799b1d0baa8fc0e3954cd8df323b2c3b50d6999ff16e49'
|
4
|
+
data.tar.gz: a14448d8a91b93d91d5302b795168d9f3eb8b0fb75c34289fc933a394c86dd69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da4f093e927466f231cbc337bff2e3860a2e1d51238dcdb9e1e25163d28acbdb00944f1244fe76558fccaa53f57c5690c3f86200f3634faafe87444863c71116
|
7
|
+
data.tar.gz: c4c388cda49bc6a0a871a71ff10b05fbc30b2a981c84d469d87fa1577b2bb45c7d4d46435e1c476534817e1ccca560d31a27591efb9b33b8b19e261c8df85347
|
data/README.md
CHANGED
@@ -1,10 +1,62 @@
|
|
1
1
|
# Http::Cat::Rails
|
2
|
-
Short description and motivation.
|
3
2
|
|
4
|
-
|
5
|
-
|
3
|
+
http-cat-rails is a configurable gem that changes every http-error page in your rails application with an image of a cute
|
4
|
+
little cat, that describes _purrfectly_ the error code (credits for the default images to https://http.cat)
|
5
|
+
|
6
|
+

|
7
|
+
|
8
|
+
## Configuration
|
9
|
+
|
10
|
+
This gem is highly customizable: you could even decide to self host your own error images, and use them.
|
11
|
+
To change this gem's behaviour, you can create a http_cat_rails.rb inside /config/initializers, and structure it as
|
12
|
+
follows:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
Http::Cat::Rails.configure do |c|
|
16
|
+
c.base_url = "https://www.myurl.com/"
|
17
|
+
c.status_codes = { "404": "code_name", "500": "code_name_2" }
|
18
|
+
c.layout = "application"
|
19
|
+
c.extension = :jpg
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
23
|
+
In this example, if an error 404 is raised, your page will load an image inside your application.html.erb from the following
|
24
|
+
url: "https://www.myurl.com/404.jpg"
|
25
|
+
|
26
|
+
### Base Url (default: "https://http.cat/")
|
27
|
+
|
28
|
+
This option is used to set the base url to retrieve images
|
29
|
+
|
30
|
+
### Status Codes (default: _a very long hash_)
|
31
|
+
|
32
|
+
This option is used to pass an Hash of status codes, to limit them, or change the url visited. The value of each
|
33
|
+
element must be **unique**, since it's used to define a function.
|
34
|
+
|
35
|
+
### Layout (default: "layout_default")
|
36
|
+
|
37
|
+
- "application" to embed http error page inside your application.html.erb
|
38
|
+
- false to don't have a layout
|
39
|
+
- "layout_default" (default option: just a black background)
|
40
|
+
- "custom_error_layout" to embed http error page inside "/views/layouts/custom_error_layout.html.erb"
|
41
|
+
|
42
|
+
### Extension (default: :jpg)
|
43
|
+
|
44
|
+
Extension to insert in the url. Can also be false or nil, to dont include an extension
|
45
|
+
|
46
|
+
### CSS
|
47
|
+
|
48
|
+
The img tag that contains the image has the following class: "http_error_image"
|
49
|
+
You can customize its style using that
|
50
|
+
|
51
|
+
## Summary
|
52
|
+
|
53
|
+
url_to_visit:
|
54
|
+
```ruby
|
55
|
+
"#{base_url}#{code_of_this_error}#{".#{extension}" if extension}"
|
56
|
+
```
|
6
57
|
|
7
58
|
## Installation
|
59
|
+
|
8
60
|
Add this line to your application's Gemfile:
|
9
61
|
|
10
62
|
```ruby
|
@@ -12,17 +64,34 @@ gem "http-cat-rails"
|
|
12
64
|
```
|
13
65
|
|
14
66
|
And then execute:
|
67
|
+
|
15
68
|
```bash
|
16
69
|
$ bundle
|
17
70
|
```
|
18
71
|
|
19
72
|
Or install it yourself as:
|
73
|
+
|
20
74
|
```bash
|
21
75
|
$ gem install http-cat-rails
|
22
76
|
```
|
23
77
|
|
78
|
+
Then, you'll need to add this line to your application.rb:
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
config.exceptions_app = self.routes
|
82
|
+
```
|
83
|
+
|
84
|
+
## Troubleshooting
|
85
|
+
|
86
|
+
This gem won't work if your application.rb or <your_environment>.rb contains the following line
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
config.consider_all_requests_local = true
|
90
|
+
```
|
91
|
+
|
24
92
|
## Contributing
|
25
|
-
|
93
|
+
|
94
|
+
It's a small project, but if you want to contribute feel free to send a Pull Request, or open an Issue
|
26
95
|
|
27
96
|
## License
|
28
97
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -1,5 +1 @@
|
|
1
|
-
|
2
|
-
<div style="width: 100vw; height: 100vh; background: black; display: flex; align-items: center; justify-content: center">
|
3
|
-
<%= image_tag "#{Http::Cat::Rails.base_url}#{@code}.jpg", width: "50%" %>
|
4
|
-
</div>
|
5
|
-
</body>
|
1
|
+
<%= image_tag "#{Http::Cat::Rails.base_url}#{@code}#{".#{Http::Cat::Rails.extension}" if Http::Cat::Rails.extension}", width: "50%", class: "http_error_image" %>
|
@@ -28,10 +28,12 @@ module Http
|
|
28
28
|
'509': 'Bandwidth Limit Exceeded', '510': 'Not Extended', '511': 'Network Authentication Required',
|
29
29
|
'521': 'Web Server Is Down', '522': 'Connection Timed Out', '523': 'Origin Is Unreachable',
|
30
30
|
'525': 'SSL Handshake Failed', '530': 'Site Frozen', '599': 'Network Connect Timeout Error' },
|
31
|
-
base_url: "https://http.cat/"
|
31
|
+
base_url: "https://http.cat/",
|
32
|
+
extension: :jpg,
|
33
|
+
layout: "layout_default"
|
32
34
|
}.freeze
|
33
35
|
|
34
|
-
attr_writer :status_codes, :base_url
|
36
|
+
attr_writer :status_codes, :base_url, :extension, :layout
|
35
37
|
|
36
38
|
def configure
|
37
39
|
yield self
|
@@ -45,6 +47,13 @@ module Http
|
|
45
47
|
@base_url || DEFAULTS[:base_url]
|
46
48
|
end
|
47
49
|
|
50
|
+
def extension
|
51
|
+
@extension || DEFAULTS[:extension]
|
52
|
+
end
|
53
|
+
|
54
|
+
def layout
|
55
|
+
@layout || DEFAULTS[:layout]
|
56
|
+
end
|
48
57
|
end
|
49
58
|
end
|
50
59
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http-cat-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gamberi Elia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-11-
|
11
|
+
date: 2023-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- Rakefile
|
37
37
|
- app/controllers/errors_controller.rb
|
38
38
|
- app/views/errors/error.html.erb
|
39
|
+
- app/views/layouts/layout_default.html.erb
|
39
40
|
- config/routes.rb
|
40
41
|
- lib/http/cat/configuration.rb
|
41
42
|
- lib/http/cat/rails.rb
|