acrylic 0.6.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f624b0a908e767b7e1b416726f251c5d7e53cc196f77fdec15e40d677d6357e5
4
- data.tar.gz: 1e3998a4a7e6dad2aa7dc1b05cc509fb500028997bdecf024b09414c82b3da09
3
+ metadata.gz: 5d56b01160b2f719dc5f906818499d48b758e079cee6f80cd78cb5683c4a3711
4
+ data.tar.gz: 2f91c0b5dc26a21c9089a847319b298c05486a5f953e28872f1f47d357c3de9a
5
5
  SHA512:
6
- metadata.gz: a9b292f911a8f8815ad6cfe9cea9d1730826e2f73394f82939c6c57e43d1ba8cc3166cef88b3e6b08f7fcecce91dd508109a1752566340b7a379d133acc8831f
7
- data.tar.gz: 0011c94a89c3268bf8007f9be758e9b7473314d8b2f2f726495b86093a84d40797b9d4d49c353f8fcbb3bd9507cf4ba6ec96c8f4ac8f1a54487e0b30a65faefa
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 render path, args
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
@@ -27,80 +27,82 @@ module Acrylic
27
27
  end
28
28
 
29
29
  class Cascade
30
- def self.default_error_body code, req, *args
31
- mab = Markaby::Builder.new
32
-
33
- mab.html do
34
- style <<-CSS
35
- body,html { font-family:"arial"; background-color:#fed; height:100%; display:flex; justify-content:center; align-items:center }
36
- .pane { padding:10px 20px; width:500px; background:#F004; border:5px solid #F006; border-radius:20px; position:absolute }
37
- .pane .description { padding:10px; background-color:#FFF4; display:flex;gap:5px; flex-direction:column; }
38
- .pane .description p { margin:0 }
39
- CSS
40
-
41
- meta charset: 'utf-8'
42
- body do
43
- div.pane do
44
- p do
45
- span code, style: "font-size: 5em"
46
- sub do
47
- span (Rack::Utils::HTTP_STATUS_CODES[code]&.downcase), style: "font-size: 2em"
48
- end
49
- end
50
-
51
- div.description do
52
- case code
53
- when 400
54
- p do "Your browser (or HTTP client) sent a request that completely bamboozled the server." end
55
- p do "If you're a developer, please <strong>RTFM</strong>. If you're a user, please tell the developer to fix their app." end
56
-
57
- when 403
58
- p do "You are not allowed to access the resource at this address." end
59
- p do "A solution would be to mind your own damn business." end
60
-
61
- when 404
62
- p do "You've stumbled on a path which maps to <em>nothing</em>." end
63
- p do "If someone sent you here, please tell them to <strong>fix their hyperlinks</strong>." end
64
-
65
- when 410
66
- p "This resource has been deleted. Reduced to ashes. Thrown into the bit bucket - you get my point!"
67
-
68
- when 418
69
- p "Your pathetic attempt at an HTTP Request was so humerous, it even made the webserver laugh."
70
-
71
- when 429
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, *args
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 code, req, *args
103
+ default_error_body(code, req)
102
104
  else
103
- route.call req, *args
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
- throw :response, error
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
@@ -2,7 +2,7 @@ module Acrylic
2
2
  class Version
3
3
  MAJOR = 0
4
4
  MINOR = 6
5
- HOTFIX = 2
5
+ HOTFIX = 3
6
6
 
7
7
  def self.semver
8
8
  "#{MAJOR}.#{MINOR}.#{HOTFIX}"
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.2
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-14 00:00:00.000000000 Z
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