acrylic 0.6.1 → 0.6.3
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/lib/acrylic.rb +3 -2
- data/lib/cascade/errors.rb +69 -67
- data/lib/cascade.rb +6 -2
- data/lib/version.rb +1 -1
- metadata +3 -17
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5d56b01160b2f719dc5f906818499d48b758e079cee6f80cd78cb5683c4a3711
|
|
4
|
+
data.tar.gz: 2f91c0b5dc26a21c9089a847319b298c05486a5f953e28872f1f47d357c3de9a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0fcd2132b2803b655fa78b64259f6a1e4b06f7f8c7f95ceb6c8c20709b2826e31c1293a277df557263e61a9ba80c23a1d5ca358cffae40fd0b1b405da7ab10cb
|
|
7
|
+
data.tar.gz: c98658b06742c262d9c59044b935c44d0b0c15dded309ec4eedc079acc25ee2e2c8bda6e84442bbebcd765258feb6e0e3b60bcd58cc98d50b8fb5ec889d3cb50
|
data/lib/acrylic.rb
CHANGED
|
@@ -10,6 +10,7 @@ require 'yaml'
|
|
|
10
10
|
module Acrylic
|
|
11
11
|
TEMPLATE_CACHE = {}
|
|
12
12
|
INITIALIZERS = Queue.new
|
|
13
|
+
MODE = ENV.fetch("RACK_ENV", "development")
|
|
13
14
|
|
|
14
15
|
def self.init!
|
|
15
16
|
until INITIALIZERS.empty?
|
|
@@ -26,10 +27,10 @@ end
|
|
|
26
27
|
# load config
|
|
27
28
|
CONFIG = YAML.load File.read "data/config.yml" rescue {}
|
|
28
29
|
|
|
29
|
-
def
|
|
30
|
+
def render_template path, args
|
|
30
31
|
if Acrylic::TEMPLATE_CACHE[path].nil?
|
|
31
32
|
Acrylic::TEMPLATE_CACHE[path] = Tilt.new path
|
|
32
33
|
end
|
|
33
34
|
|
|
34
|
-
return Acrylic::TEMPLATE_CACHE.render args
|
|
35
|
+
return Acrylic::TEMPLATE_CACHE[path].render args
|
|
35
36
|
end
|
data/lib/cascade/errors.rb
CHANGED
|
@@ -27,80 +27,82 @@ module Acrylic
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
class Cascade
|
|
30
|
-
def self.default_error_body code, req
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
h1 "IT'S TIME TO STOP."
|
|
73
|
-
h1 "IT'S TIME TO STOP, OKAY!???"
|
|
74
|
-
|
|
75
|
-
when 500
|
|
76
|
-
p "This is fine."
|
|
77
|
-
|
|
78
|
-
when 501
|
|
79
|
-
p "i forgor 💀"
|
|
80
|
-
|
|
81
|
-
when 502
|
|
82
|
-
p "One of the applications that power this website probably imploded on itself."
|
|
83
|
-
|
|
84
|
-
else
|
|
85
|
-
p do "An error has occured. I have no idea what it is though. ¯\\_(ツ)_/¯" end
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
small style: "color: #844; font-weight: bold; padding-top: 20px" do
|
|
90
|
-
em "served by acrylic #{Acrylic::Version.version}"
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
end
|
|
30
|
+
def self.default_error_body code, req
|
|
31
|
+
style = <<-CSS
|
|
32
|
+
body,html { font-family:"arial"; background-color:#fed; height:100%; display:flex; justify-content:center; align-items:center }
|
|
33
|
+
.pane { padding:10px 20px; width:500px; background:#F004; border:5px solid #F006; border-radius:20px; position:absolute }
|
|
34
|
+
.pane .description { padding:10px; background-color:#FFF4; display:flex;gap:5px; flex-direction:column; }
|
|
35
|
+
.pane .description p { margin:0 }
|
|
36
|
+
CSS
|
|
37
|
+
|
|
38
|
+
description = case code
|
|
39
|
+
when 400
|
|
40
|
+
"<p>Your browser (or HTTP client) sent a request that completely bamboozled the server.</p>" +
|
|
41
|
+
"<p>If you're a developer, please <strong>RTFM</strong>. If you're a user, please tell the developer to fix their app.</p>"
|
|
42
|
+
|
|
43
|
+
when 403
|
|
44
|
+
"<p>You are not allowed to access the resource at this address.</p>" +
|
|
45
|
+
"<p>A solution would be to mind your own damn business.</p>"
|
|
46
|
+
|
|
47
|
+
when 404
|
|
48
|
+
"<p>You've stumbled on a path which maps to <em>nothing</em>." +
|
|
49
|
+
"<p>If someone sent you here, please tell them to <strong>fix their hyperlinks</strong>.</p>"
|
|
50
|
+
|
|
51
|
+
when 410
|
|
52
|
+
"<p>This resource has been deleted. Reduced to ashes. Thrown into the bit bucket.</p>"
|
|
53
|
+
|
|
54
|
+
when 418
|
|
55
|
+
"<p>Your pathetic attempt at an HTTP Request was so humerous, it even made the webserver laugh.</p>"
|
|
56
|
+
|
|
57
|
+
when 429
|
|
58
|
+
"<h1>IT'S TIME TO STOP.</h1>" +
|
|
59
|
+
"<h1>IT'S TIME TO STOP, OKAY!???</h1>"
|
|
60
|
+
|
|
61
|
+
when 500
|
|
62
|
+
"<p>This is fine.</p>"
|
|
63
|
+
|
|
64
|
+
when 501
|
|
65
|
+
"<p>i forgor 💀</p>"
|
|
66
|
+
|
|
67
|
+
when 502
|
|
68
|
+
"<p>One of the applications that power this website probably imploded on itself.</p>"
|
|
69
|
+
|
|
70
|
+
else
|
|
71
|
+
"<p>An error has occured. I have no idea what it is though. ¯\\_(ツ)_/¯</p>"
|
|
94
72
|
end
|
|
73
|
+
|
|
74
|
+
# it would've been really great if i was able to use markaby to save myself the trouble of using raw html
|
|
75
|
+
# unfortunately tho it's a buggy piece of shit that makes EVERYTHING IMPOSSIBLE TO FUCKING DEBUG WITH ITS METAPROGRAMMING BULLSHIT
|
|
76
|
+
return <<-HTML
|
|
77
|
+
<body>
|
|
78
|
+
<meta charset="utf-8">
|
|
79
|
+
<style>#{style}</style>
|
|
80
|
+
|
|
81
|
+
<div class="pane">
|
|
82
|
+
<p>
|
|
83
|
+
<span style="font-size: 5em">#{code}</span>
|
|
84
|
+
<sub>
|
|
85
|
+
<span style="font-size: 2em">#{Rack::Utils::HTTP_STATUS_CODES[code]&.downcase}</span>
|
|
86
|
+
</sub>
|
|
87
|
+
</p>
|
|
88
|
+
|
|
89
|
+
<div class="description"> #{description} </div>
|
|
90
|
+
|
|
91
|
+
<small style="color: #844; font-weight: bold; padding-top: 20px">
|
|
92
|
+
<em>served by acrylic #{Acrylic::Version.version}</em>
|
|
93
|
+
</div>
|
|
94
|
+
</div>
|
|
95
|
+
</body>
|
|
96
|
+
HTML
|
|
95
97
|
end
|
|
96
98
|
|
|
97
99
|
# returns body of response.
|
|
98
|
-
def self.error_body code, req, *
|
|
100
|
+
def self.error_body code, req, *wargs
|
|
99
101
|
route = ERROR_ROUTES.find do |route| route.match? code, req end
|
|
100
102
|
if route.nil?
|
|
101
|
-
default_error_body
|
|
103
|
+
default_error_body(code, req)
|
|
102
104
|
else
|
|
103
|
-
route.call
|
|
105
|
+
route.call(req)
|
|
104
106
|
end
|
|
105
107
|
end
|
|
106
108
|
end
|
data/lib/cascade.rb
CHANGED
|
@@ -74,7 +74,7 @@ module Acrylic
|
|
|
74
74
|
res = catch(:response) { invoke route, config, req, *(route.args_for_path req.path) }
|
|
75
75
|
|
|
76
76
|
res = case true
|
|
77
|
-
when (res.is_a? Exception) then return error_body 500, req, config, res # also give it the exception
|
|
77
|
+
when (res.is_a? Exception) then return Rack::Response.new (error_body 500, req, config, res), 500 # also give it the exception
|
|
78
78
|
when (res.is_a? Rack::Response) then res
|
|
79
79
|
when (res.respond_to? :to_h) then res.to_h
|
|
80
80
|
when (res.is_a? Integer) then Rack::Response.new nil, res
|
|
@@ -130,7 +130,11 @@ def invoke route, conf, req, *args
|
|
|
130
130
|
begin
|
|
131
131
|
res = (route.call conf, req, *args)
|
|
132
132
|
rescue => error
|
|
133
|
-
|
|
133
|
+
if Acrylic::MODE == "development"
|
|
134
|
+
raise error # let rack handle it
|
|
135
|
+
else
|
|
136
|
+
throw :response, error
|
|
137
|
+
end
|
|
134
138
|
end
|
|
135
139
|
|
|
136
140
|
throw :response, res unless res.nil?
|
data/lib/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: acrylic
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.6.
|
|
4
|
+
version: 0.6.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- fmixolydian
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-01-
|
|
10
|
+
date: 2026-01-16 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: rack
|
|
@@ -23,20 +23,6 @@ dependencies:
|
|
|
23
23
|
- - "~>"
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
25
|
version: '3.2'
|
|
26
|
-
- !ruby/object:Gem::Dependency
|
|
27
|
-
name: markaby
|
|
28
|
-
requirement: !ruby/object:Gem::Requirement
|
|
29
|
-
requirements:
|
|
30
|
-
- - "~>"
|
|
31
|
-
- !ruby/object:Gem::Version
|
|
32
|
-
version: 0.9.4
|
|
33
|
-
type: :runtime
|
|
34
|
-
prerelease: false
|
|
35
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
-
requirements:
|
|
37
|
-
- - "~>"
|
|
38
|
-
- !ruby/object:Gem::Version
|
|
39
|
-
version: 0.9.4
|
|
40
26
|
- !ruby/object:Gem::Dependency
|
|
41
27
|
name: ostruct
|
|
42
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -95,7 +81,7 @@ files:
|
|
|
95
81
|
- lib/palette.rb
|
|
96
82
|
- lib/validator.rb
|
|
97
83
|
- lib/version.rb
|
|
98
|
-
homepage: https://
|
|
84
|
+
homepage: https://git.disroot.org/acrylic/acrylic
|
|
99
85
|
licenses:
|
|
100
86
|
- BSD-3-Clause
|
|
101
87
|
metadata: {}
|