acrylic 0.1.1 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7f964f398be355711d7cd892038190775d049259f99570198a41a9ddfb36161
4
- data.tar.gz: 6536f6f878d30c39ef30ffdb05f2d7e55be715ffcd0fd17b03cce62dac2ba004
3
+ metadata.gz: 4a0411b437d94694ff9761a6f9466fa909d650eb933ecd5fc0b6438f66ff10fc
4
+ data.tar.gz: c04dd9a1311e53216b18600f0847dc6004895ae826daf36cea728ede98b59c70
5
5
  SHA512:
6
- metadata.gz: 3b3a59a768344665563753be56e7ff6d1dd577cb1d0787a2c46fd09e4d30b1228e7b57e8c26f916f6e252f9e831d9437fd2cd88faab6d3a6c94dda509a6165d8
7
- data.tar.gz: aba291196d77af51d3ccb79575d8a5cdab4dee0dcfc5a5b36062b0a7e90c56d97632483aa7beb4696eed9e4fb99e0a627f0bb1c02191b0b0fbef873a01efb3cd
6
+ metadata.gz: 71b6752fa603ed57e4c2f30545456baf445a011a54d21b13c4223825b646d0e4c5fe2e0ef80a106eb6c1732611663e31b38c2b8e3fdcc8c0a69fd1723c1fe5b5
7
+ data.tar.gz: c7ebde805dd400055725b095ea7f1ce78e0ac6fafb03ec3904dcf8a777aadc3111d09e9a7d868623f377abf4387115fcc42af841386dfc936a34c47d3ed16750
data/lib/bits.rb CHANGED
@@ -15,7 +15,7 @@ class Class
15
15
  end
16
16
 
17
17
  class Hash
18
- def self.from_keys keys
19
- keys.map do |k| [k, nil] end.to_h
18
+ def self.from_keys keys, value = nil
19
+ keys.map do |k| [k, value] end.to_h
20
20
  end
21
21
  end
@@ -4,6 +4,10 @@
4
4
  # response with an empty body.
5
5
  # to add content to this empty response, Cascade.error_page will
6
6
  # use a similar route definition system to regular Cascade routes to create error pages.
7
+ require 'markaby'
8
+ require 'rack/utils'
9
+
10
+ Rack::Utils::HTTP_STATUS_CODES[418] = "I'm a Teapot"
7
11
 
8
12
  module Acrylic
9
13
  ERROR_ROUTES = []
@@ -22,17 +26,65 @@ module Acrylic
22
26
  end
23
27
 
24
28
  class Cascade
25
- def default_error_body code, req
26
-
29
+ def self.default_error_body code, req
30
+ mab = Markaby::Builder.new
31
+
32
+ mab.html do
33
+ style <<-CSS
34
+ body,html { font-family:"arial"; background-color:#fed; height:100%; display:flex; justify-content:center; align-items:center }
35
+ .pane { padding:10px 20px; width:500px; background:#F004; border:5px solid #F006; border-radius:20px; position:absolute }
36
+ .pane .description { padding:10px; background-color:#FFF4; display:flex;gap:5px; flex-direction:column; }
37
+ .pane .description p { margin:0 }
38
+ CSS
39
+
40
+ meta charset: 'utf-8'
41
+ body do
42
+ div.pane do
43
+ p do
44
+ span code, style: "font-size: 5em"
45
+ sub do
46
+ span (Rack::Utils::HTTP_STATUS_CODES[code]&.downcase), style: "font-size: 2em"
47
+ end
48
+ end
49
+
50
+ div.description do
51
+ case code
52
+ when 400
53
+ p do "Your browser (or HTTP client) sent a request that completely bamboozled the server." end
54
+ p do "If you're a developer, please RTFM. If you're a user, please tell the developer to fix their app." end
55
+
56
+ when 403
57
+ p do "You are not allowed to access the resource at this address." end
58
+ p do "A solution would be to mind your own damn business." end
59
+
60
+ when 404
61
+ p do "You've stumbled on a path which maps to <em>nothing</em>." end
62
+ p do "If someone sent you here, please tell them to <strong>fix their hyperlinks</strong>." end
63
+
64
+ when 418
65
+ p do "You pathetic attempt at an HTTP Request was so humerous, it even made the server laugh." end
66
+
67
+ when 429
68
+ h1 do "IT'S TIME TO STOP." end
69
+ h1 do "IT'S TIME TO STOP, OKAY!???" end
70
+
71
+ else
72
+ p do "An error has occured. I have no idea what it is though. ¯\\_(ツ)_/¯" end
73
+ end
74
+ end
75
+
76
+ small style: "color: #844; font-weight: bold; padding-top: 20px" do
77
+ em "served by acrylic #{Acrylic::Version.version}"
78
+ end
79
+ end
80
+ end
81
+ end
27
82
  end
28
83
 
29
84
  # returns body of response.
30
- def error_body code, req
85
+ def self.error_body code, req
31
86
  route = ERROR_ROUTES.find do |route| route.match? code, req end
32
- body = if route.nil? then default_error_page code, req else route.call req end
33
-
34
- raise TypeError("return value of error_handler body must be a string") unless body.is_a? String
35
- body
87
+ if route.nil? then default_error_body code, req else route.call req end
36
88
  end
37
89
  end
38
90
  end
data/lib/cascade.rb CHANGED
@@ -55,7 +55,7 @@ module Acrylic
55
55
  when (res.is_a? Integer) then Rack::Response.new nil, res
56
56
  when (res.is_a? String) then Rack::Response.new res
57
57
  when (res.nil?) then next
58
- else raise TypeError
58
+ else raise TypeError
59
59
  end
60
60
 
61
61
  # if the returned route has a body, return it. else, add its headers to the existing response.
@@ -68,7 +68,7 @@ module Acrylic
68
68
  end
69
69
 
70
70
  # if no route returned a response, return a 404
71
- return Rack::Response.new nil, 404, headers
71
+ Rack::Response.new nil, 404, headers
72
72
  end
73
73
 
74
74
 
@@ -78,14 +78,15 @@ module Acrylic
78
78
  res = handle req
79
79
  # apply a series of transformations to the response
80
80
  # unfortunately since Response is immutable we have to make a copy
81
- # 1. if res is an error code, transform it into a full response with cascade/errors
82
- body = res.body.fallback "" # (error_page res.status, req)
81
+ # 1. if res has an empty body, transform it into a full response with cascade/errors
82
+ # why rack uses a goddamn empty array instead of nil i have no clue of
83
+ # (it doesnt give a fuck about strings, but it TURNS NILS INTO ARRAYS!? WHY!? WHY!!!!!!?)
84
+ if res.body == [] then res.body = error_body res.status, req end
83
85
 
84
86
  # 2. transform every header key of res into a string
85
87
  headers = res.headers.map do |k, v| [k.to_s, v] end.to_h
86
88
 
87
- p body
88
- Rack::Response.new body, res.status, headers
89
+ Rack::Response.new res.body, res.status, headers
89
90
  end
90
91
  end
91
92
  end
data/lib/version.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  module Acrylic
2
2
  class Version
3
3
  MAJOR = 0
4
- MINOR = 1
5
- HOTFIX = 1
4
+ MINOR = 2
5
+ HOTFIX = 0
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.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - fmixolydian
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-12-14 00:00:00.000000000 Z
10
+ date: 2025-12-16 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rack
@@ -23,6 +23,26 @@ 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'
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 0.9.4
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '0.9'
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 0.9.4
26
46
  description: |2
27
47
  Acrylic is a web framework that simplifies your life by automatically generating migrations,
28
48
  as well as providing several macros for repeating common operations (e.g. defining REST APIs).