acrylic 0.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 +7 -0
- data/COPYING.md +31 -0
- data/README.md +3 -0
- data/VERSION.md +15 -0
- data/lib/acrylic.rb +3 -0
- data/lib/bits.rb +17 -0
- data/lib/cascade/errors.rb +44 -0
- data/lib/cascade.rb +89 -0
- data/lib/version.rb +15 -0
- metadata +62 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: ffa3dcf17f46e9e75b17e95c9ca52b0e82dd7bed3ce4f637cbbab1032f97826b
|
|
4
|
+
data.tar.gz: 5c4a8b1143cdb8c4d0a78287b2b60fde38873f5b7570b73e7fbe8227aceefe86
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: cec1122bf513bce029509915c01c649675c830bc23509a593389a92124266b5d4e2a7d0f8c4124cc25099986dc599f0dd83ad4cae195b8a1fc0f0055f7d5ce1b
|
|
7
|
+
data.tar.gz: 9a3303e5e18660ffec7c13a484db93be42e6d4e37f345ef0cd5394fff2002ae0896678451da7247dc964a6e274116f241c32ece1e6cd5799b77d8e2a9266ff46
|
data/COPYING.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
This project is licensed under the PICO License v1.3, © (project author) (current year)
|
|
2
|
+
|
|
3
|
+
## TERMINOLOGY
|
|
4
|
+
|
|
5
|
+
- accessibility through the network: to be involved in (and not as part of the underlying operating system) the creation, modification, presentation, and/or distribution of online content over the internet.
|
|
6
|
+
- assets: any sort of textual or binary files (or unique fragments of files where applicable) which are part of a project, and included either as a processed output (e.g. through a preprocessing tool, assembler, or compiler) or directly, inside or alongside the main finished output of a project, and/or any intermediate stage.
|
|
7
|
+
|
|
8
|
+
## REQUISITES (for a project)
|
|
9
|
+
|
|
10
|
+
For a project (original or derived) to be licensed under this license, its complete source code must be publicly available in a way that can be used, modified, and set up by anyone, without the prerequisite of any tools or configuration settings not available to the public, except when sharing said settings could compromise the security of the existing instance(s) (in which case sufficient documentation must be provided to allow users to replace said settings with valid values that let the application function).
|
|
11
|
+
|
|
12
|
+
If the project does not follow these requirements, this license shall be considered void, and thus cannot be used to license said project.
|
|
13
|
+
|
|
14
|
+
## TERMS AND CONDITIONS (for the user)
|
|
15
|
+
|
|
16
|
+
Users are granted an irrevocable, perpetual, and royalty-free right to use, distribute, view, reverse-engineer, and modify this project and its assets in any way allowed by law both for non-commercial and commercial purposes with the following clauses:
|
|
17
|
+
|
|
18
|
+
1. Distribution, embedding, and static or dynamic linking of the entire project or assets in binary or source form requires attribution.
|
|
19
|
+
|
|
20
|
+
2. If the project is accessible through the network either privately or publicly, attribution must be given as per the distribution clause.
|
|
21
|
+
|
|
22
|
+
3. Attribution must be in the form of a piece of text accessible to the end user (e.g. through the Help menu in a GUI application) indicating the original project name, author(s), and a link to the complete source code of the project.
|
|
23
|
+
|
|
24
|
+
4. A project derived from the original project must:
|
|
25
|
+
- be licensed under the exact same license, or any later version;
|
|
26
|
+
- and provide attribution to the original author(s) as well as the derived project's.
|
|
27
|
+
|
|
28
|
+
5. Large language models (such as ChatGPT, Claude, or Gemini) or any other generative AI models which train off of publicly available assets are explicitly forbidden from using the project's assets or intellectual property for training.
|
|
29
|
+
|
|
30
|
+
The project is provided "as-is", without any warranty of any kind.
|
|
31
|
+
The author(s) have made their best effort to make sure the product is safe, although no guarantees are offered regarding potential damages that may result from the usage of this project.
|
data/README.md
ADDED
data/VERSION.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
## AcrylicVer
|
|
2
|
+
|
|
3
|
+
```
|
|
4
|
+
<MAJOR>.<MINOR><PATCH>
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
examples: '1.5j', `3.14`, `0.2a`
|
|
8
|
+
|
|
9
|
+
PATCH is omitted for the first release.
|
|
10
|
+
|
|
11
|
+
PATCH shall be incremented for small changes.
|
|
12
|
+
|
|
13
|
+
MINOR shall be incremented for feature additions.
|
|
14
|
+
|
|
15
|
+
MAJOR shall be incremented for large changes (e.g. total API revamps) and/or milestones.
|
data/lib/acrylic.rb
ADDED
data/lib/bits.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
class Object
|
|
2
|
+
def containerize
|
|
3
|
+
if self.is_a? Array then self else [self].compact end
|
|
4
|
+
end
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
class Class
|
|
8
|
+
def new_from object
|
|
9
|
+
if object.is_a? self then object else new object end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class Hash
|
|
14
|
+
def self.from_keys keys
|
|
15
|
+
keys.map do |k| [k, nil] end.to_h
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Provides customizable error pages for Cascade.
|
|
2
|
+
# when an error like 404 is encountered, cascade (and the application)
|
|
3
|
+
# should return just an error code, which will be transformed into a
|
|
4
|
+
# response with an empty body.
|
|
5
|
+
# to add content to this empty response, Cascade.error_page will
|
|
6
|
+
# use a similar route definition system to regular Cascade routes to create error pages.
|
|
7
|
+
|
|
8
|
+
module Acrylic
|
|
9
|
+
ERROR_ROUTES = []
|
|
10
|
+
|
|
11
|
+
class ErrorRoute < Route
|
|
12
|
+
attr_reader :code
|
|
13
|
+
|
|
14
|
+
def initialize code, args, handler
|
|
15
|
+
@code = code
|
|
16
|
+
super args, handler
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def match? code, req
|
|
20
|
+
(@code == code) and super req
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
class Cascade
|
|
25
|
+
def default_error_body code, req
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# returns body of response.
|
|
30
|
+
def error_body code, req
|
|
31
|
+
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
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# route should return body of response
|
|
41
|
+
def error_handler code, *wargs, **kwargs, &route
|
|
42
|
+
args = (Hash.from_keys wargs).merge kwargs
|
|
43
|
+
Acrylic::ERROR_ROUTES << (Acrylic::ErrorRoute.new code, args, route)
|
|
44
|
+
end
|
data/lib/cascade.rb
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
require 'rack'
|
|
2
|
+
|
|
3
|
+
module Acrylic
|
|
4
|
+
ROUTES = []
|
|
5
|
+
|
|
6
|
+
class Route
|
|
7
|
+
# list of HTTP verbs the request will be matched against.
|
|
8
|
+
attr_reader :verbs
|
|
9
|
+
|
|
10
|
+
# list of path rules (wildcards or regexps)
|
|
11
|
+
attr_reader :paths
|
|
12
|
+
|
|
13
|
+
def initialize args, handler
|
|
14
|
+
@handler = handler
|
|
15
|
+
|
|
16
|
+
@paths = args.fetch(:path).containerize
|
|
17
|
+
@verbs = (args[:verb] or :GET).containerize.map do |verb| verb.downcase.to_sym end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# checks if a path matches one of the rules.
|
|
21
|
+
def path_match? path
|
|
22
|
+
@paths.each do |rule|
|
|
23
|
+
if ((rule.is_a? Regexp) and (rule.match? path)) \
|
|
24
|
+
or ((rule.is_a? Proc) and (rule.call path)) \
|
|
25
|
+
or ((rule.is_a? String) and (File.fnmatch rule, path, File::Constants::FNM_EXTGLOB | File::Constants::FNM_PATHNAME))
|
|
26
|
+
then return true end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
return false
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def match? req
|
|
33
|
+
# match against paths
|
|
34
|
+
(path_match? req.path) and (@verbs.include? req.request_method.downcase.to_sym )
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def call req
|
|
38
|
+
@handler.call req
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
class Cascade
|
|
43
|
+
# returns a response based on the defined routes.
|
|
44
|
+
# if the response is empty, it shall be passed through Cascade.ServeError
|
|
45
|
+
def self.handle req
|
|
46
|
+
headers = {}
|
|
47
|
+
|
|
48
|
+
# loop through all the routes to find a final one
|
|
49
|
+
Acrylic::ROUTES.each do |route|
|
|
50
|
+
next unless route.match? req
|
|
51
|
+
|
|
52
|
+
res = route.call req
|
|
53
|
+
res = case true
|
|
54
|
+
when (res.nil?) then next
|
|
55
|
+
when (res.is_a? String) then Rack::Response.new res
|
|
56
|
+
when (res.is_a? Integer) then Rack::Response.new nil, res
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# if the returned route has a body, return it. else, add its headers to the existing response.
|
|
60
|
+
if res.is_a? Rack::Response
|
|
61
|
+
res.headers.merge! headers
|
|
62
|
+
return res
|
|
63
|
+
elsif res.is_a? Hash
|
|
64
|
+
headers.merge! res.headers
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# if no route returned a response, return a 404
|
|
69
|
+
return Rack::Response.new nil, 404
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def self.serve env
|
|
74
|
+
req = Rack::Request.new env
|
|
75
|
+
|
|
76
|
+
res = handle req
|
|
77
|
+
res.body = error_page res.status, req if res.body.nil?
|
|
78
|
+
res
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def route *wargs, **kwargs, &route
|
|
85
|
+
args = (Hash.from_keys wargs).merge kwargs
|
|
86
|
+
Acrylic::ROUTES << (Acrylic::Route.new args, route)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
require 'cascade/errors'
|
data/lib/version.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: acrylic
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- fmixolydian
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 2025-12-14 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: rack
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '3.2'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '3.2'
|
|
26
|
+
description: |2
|
|
27
|
+
Acrylic is a web framework that simplifies your life by automatically generating migrations,
|
|
28
|
+
as well as providing several macros for repeating common operations (e.g. defining REST APIs).
|
|
29
|
+
executables: []
|
|
30
|
+
extensions: []
|
|
31
|
+
extra_rdoc_files: []
|
|
32
|
+
files:
|
|
33
|
+
- COPYING.md
|
|
34
|
+
- README.md
|
|
35
|
+
- VERSION.md
|
|
36
|
+
- lib/acrylic.rb
|
|
37
|
+
- lib/bits.rb
|
|
38
|
+
- lib/cascade.rb
|
|
39
|
+
- lib/cascade/errors.rb
|
|
40
|
+
- lib/version.rb
|
|
41
|
+
homepage: https://codeberg.org/fmixolydian/acrylic
|
|
42
|
+
licenses:
|
|
43
|
+
- LicenseRef-COPYING.md
|
|
44
|
+
metadata: {}
|
|
45
|
+
rdoc_options: []
|
|
46
|
+
require_paths:
|
|
47
|
+
- lib
|
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
49
|
+
requirements:
|
|
50
|
+
- - ">="
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: '3.2'
|
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
|
+
requirements:
|
|
55
|
+
- - ">="
|
|
56
|
+
- !ruby/object:Gem::Version
|
|
57
|
+
version: '0'
|
|
58
|
+
requirements: []
|
|
59
|
+
rubygems_version: 3.6.3
|
|
60
|
+
specification_version: 4
|
|
61
|
+
summary: The web framework that makes your life easier
|
|
62
|
+
test_files: []
|