erio 0.0.0 → 0.0.1.1
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/CHANGELOG.md +5 -1
- data/README.md +71 -12
- data/config.ru +3 -0
- data/lib/erio/short.rb +106 -0
- data/lib/erio/version.rb +2 -2
- data/lib/erio.rb +64 -19
- data/sig/erio.rbs +1 -1
- metadata +4 -3
- data/.vscode/settings.json +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fad8b7185fc96b49a17922cc7f2c20e5efd44151b733b07de05a73bd193bd3b9
|
4
|
+
data.tar.gz: 82c45e8763b8c1ccf18845b411e9056ffcc30161ab15ebee7cb4f53643634cf9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f10bc473794c43f0bdbb07578cf754d6fa14462f00c763d3c12265b492848dff4ebcdc307fe5ca28d66c92d771a43993c65cd7972d16d652fe72feb069dfd4d
|
7
|
+
data.tar.gz: cec14bb2d9b93afb8e959fb76de8dc6a6a10dd7fd89404ae77747767a9258490ed27d13b2c1164a7ee13a1aaccf83e778132864907a33b3d7600a5c18b2d35b6
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,34 +1,93 @@
|
|
1
|
-
# Erio
|
1
|
+
# エリオ :: Erio
|
2
2
|
|
3
3
|
A very chubby, tiny and lightweight Web Framework(base on Rack)
|
4
4
|
|
5
|
-
|
5
|
+
凄く小さいなウェブ・フラムワーク。
|
6
|
+
|
7
|
+
## インストール :: Installation
|
6
8
|
|
7
9
|
```bash
|
8
10
|
gem install erio
|
9
11
|
```
|
10
12
|
|
11
|
-
## Usage
|
13
|
+
## 使い方法 :: Usage
|
12
14
|
|
13
15
|
```ruby
|
14
16
|
require 'erio'
|
15
17
|
|
16
|
-
class
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
class Touwa < Erio
|
19
|
+
enter do
|
20
|
+
status 200
|
21
|
+
header content_type: 'html'
|
22
|
+
if accept? 'image' and not accept? %w[text application]
|
23
|
+
send_file '/public'+path
|
24
|
+
elsif path? '/'
|
25
|
+
'<h1>Hello, Erio!</h1>'
|
26
|
+
elsif query? id: 1
|
27
|
+
content_type 'json'
|
28
|
+
{ id: 1, name: 'Touwa Erio', country: 'Japan' }.to_json
|
22
29
|
else
|
30
|
+
status 404
|
31
|
+
"<h1><b>404</b> - not found page</h1><hr><h2>\"#{path}\"</h2>"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
Touwa.run!
|
37
|
+
|
38
|
+
```
|
39
|
+
|
40
|
+
### 綺麗になた :: More Usefule
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
|
44
|
+
# エリオは何の為?
|
45
|
+
Erio.enter do |o|
|
46
|
+
# 来訪ノ時に記録。
|
47
|
+
t0 = Time.now
|
48
|
+
# 状態番号 200
|
49
|
+
o.status 200
|
50
|
+
|
51
|
+
# 見目タイプに判断と反応する。
|
52
|
+
if o.accept? %w[image video audio] and not o.accept? %w[text application]
|
53
|
+
# 内容タイプのヘーダに設定。
|
54
|
+
o.header content_type: o.path.split('.')[-1]
|
55
|
+
begin
|
56
|
+
# ファイルに発送。
|
57
|
+
o.body File.binread('public'+path)
|
58
|
+
rescue => err
|
59
|
+
# ファイルに有りませんならば、異常ニ報告する。
|
60
|
+
puts err
|
61
|
+
o.status 404
|
62
|
+
o.body 'miss'
|
63
|
+
end
|
64
|
+
# HPに展覧。
|
65
|
+
elsif o.path? '/'
|
66
|
+
o.header content_type: 'text'
|
67
|
+
o.body 'hi'
|
68
|
+
else
|
69
|
+
# いないノ場合...
|
70
|
+
o.status 404
|
71
|
+
o.body 'miss'
|
23
72
|
end
|
73
|
+
# 毎回ノ来訪をログ。
|
74
|
+
puts "#{o.ip} [#{t0}] #{o.verb} #{o.path} #{o.query} #{o.accept.scan(/\w+(?=\/)/).uniq.join(',')} #{"%.04f" % (Time.now-t0).to_f}"
|
24
75
|
end
|
25
76
|
|
77
|
+
# エリオ開始。
|
78
|
+
Erio.run!
|
26
79
|
```
|
27
80
|
|
28
|
-
##
|
81
|
+
## 作ル人 :: Creator
|
82
|
+
|
83
|
+
__SAISUI__ :: 彩穂
|
84
|
+
|
85
|
+
tip from `rack`, `sinatra`
|
86
|
+
|
87
|
+
## コード協力 :: Contributing
|
29
88
|
|
30
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
89
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/saisui/erio-rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/saisui/erio-rb/blob/master/CODE_OF_CONDUCT.md).
|
31
90
|
|
32
|
-
## License
|
91
|
+
## ライセンス :: License
|
33
92
|
|
34
93
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/config.ru
ADDED
data/lib/erio/short.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
class << Erio
|
2
|
+
def ip; @_env['REMOTE_ADDR'] end
|
3
|
+
def user_agent; @_env['HTTP_USER_AGENT'] end
|
4
|
+
def req_body; @_env['rack.input'].read end
|
5
|
+
def req_scheme; @_env['rack.url_scheme'] end
|
6
|
+
def req_host; @_env['HTTP_HOST'] end
|
7
|
+
def query; @_env['QUERY_STRING'] end
|
8
|
+
|
9
|
+
def decode_www str
|
10
|
+
str.gsub('+','%2B').gsub(/%([\da-fA-F]{2})/) { $1.to_i(16).chr }
|
11
|
+
end
|
12
|
+
def encode_www str
|
13
|
+
str.gsub(/[^ 0-9a-zA-Z\-_~]/) {|c| c.bytes.map { '%%%02X' % _1 }.join }.gsub(' ', '+')
|
14
|
+
end
|
15
|
+
|
16
|
+
def queries q_str=nil
|
17
|
+
(q_str || @_env['QUERY_STRING']).split('&')
|
18
|
+
.map { k,v = [*_1.split('='),''][0,2]; [k, decode_www(v)] }.to_h
|
19
|
+
end
|
20
|
+
|
21
|
+
def content_type type
|
22
|
+
type = type.to_s
|
23
|
+
type = case type
|
24
|
+
when *%w[html json xml yaml ruby javascript python ini toml rust go vue md markdown rdoc]
|
25
|
+
'text/'+type
|
26
|
+
when *%w[png jpg jpeg webp tiff gif bmp ico]
|
27
|
+
'image/'+type
|
28
|
+
when *%w[mp4 webm mkv mov ts]
|
29
|
+
'video/'+type
|
30
|
+
when *%w[mp3 ogg wav flac ape m4a midi]
|
31
|
+
'audio/'+type
|
32
|
+
else type
|
33
|
+
end
|
34
|
+
@header['content-type'] = type
|
35
|
+
end
|
36
|
+
|
37
|
+
def send_file filename
|
38
|
+
ext = File.extname filename
|
39
|
+
content_type ext
|
40
|
+
File.binread filename
|
41
|
+
end
|
42
|
+
|
43
|
+
def request; Rack::Request.new(@_env) end
|
44
|
+
def header(**kws); kws.empty? ? @header : @header.merge!(kws.to_a.map { [_1.to_s.gsub('_','-'),_2] }.to_h) end
|
45
|
+
def status(s=nil); s ? @status=s : @status end
|
46
|
+
def path; @_env['PATH_INFO'] end
|
47
|
+
def path? pattern=nil; block_given? ? (yield if pattern === path) : path end
|
48
|
+
def verb word=nil; block_given? ? (yield if verb == word) : @_env['REQUEST_METHOD'] end
|
49
|
+
def body str=nil; str ? @body=str : @body end
|
50
|
+
def accept; @_env['HTTP_ACCEPT'] end
|
51
|
+
|
52
|
+
def status? s=200, &block
|
53
|
+
bool = s === @status
|
54
|
+
return bool unless bool && block
|
55
|
+
block.call
|
56
|
+
end
|
57
|
+
|
58
|
+
def ip? cond, &block
|
59
|
+
bool = cond === @_env['REMOTE_ADDR']
|
60
|
+
return bool unless bool && block
|
61
|
+
block.call
|
62
|
+
end
|
63
|
+
|
64
|
+
def header? **kws, &block
|
65
|
+
bool = kws.keys.map { kws[_1] === @header[_1] ? return false : true }.all?
|
66
|
+
return bool unless bool && block
|
67
|
+
block.call
|
68
|
+
end
|
69
|
+
|
70
|
+
def host? url, &block
|
71
|
+
bool = url === env['HOST']
|
72
|
+
return bool unless bool && block
|
73
|
+
block.call
|
74
|
+
end
|
75
|
+
|
76
|
+
def body?; !!@body end
|
77
|
+
|
78
|
+
def query? **kws, &block
|
79
|
+
bool = kws.keys.map { kws[_1] === queries[_1] ? return false : true }.all?
|
80
|
+
return bool unless bool && block
|
81
|
+
block.call
|
82
|
+
end
|
83
|
+
|
84
|
+
def accept? *types, &block
|
85
|
+
acc = @_env['HTTP_ACCEPT']
|
86
|
+
bool = types.map do |type|
|
87
|
+
rt = %r[\b#{type}\b]
|
88
|
+
case type
|
89
|
+
when nil then true
|
90
|
+
when /\b\w+\b/i then acc =~ rt
|
91
|
+
when Array
|
92
|
+
type.map do |type|
|
93
|
+
case type
|
94
|
+
when /\b\w+\b/i then acc =~ rt
|
95
|
+
else type === acc
|
96
|
+
end
|
97
|
+
end.any?
|
98
|
+
else type === acc
|
99
|
+
end
|
100
|
+
# bool
|
101
|
+
end.all?
|
102
|
+
return bool unless bool && block
|
103
|
+
block.call
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
data/lib/erio/version.rb
CHANGED
data/lib/erio.rb
CHANGED
@@ -1,43 +1,88 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "erio/version"
|
4
|
+
require_relative "erio/short"
|
5
|
+
require'rack'
|
6
|
+
require'rack/handler/puma'
|
4
7
|
|
8
|
+
#
|
9
|
+
# An very tiny and chubby Web Framework base on Rack
|
10
|
+
# Fast and tiny Code
|
11
|
+
#
|
12
|
+
# class Touwa < Erio
|
13
|
+
# enter do
|
14
|
+
# status 200
|
15
|
+
# if header? http_accept: /image|video|audio/ and
|
16
|
+
# not header? http_accept: /text|application/
|
17
|
+
# header content_type: path.split('.')[-1]
|
18
|
+
# begin
|
19
|
+
# File.binread('public'+path)
|
20
|
+
# rescue => err
|
21
|
+
# puts err
|
22
|
+
# status 404
|
23
|
+
# 'miss'
|
24
|
+
# end
|
25
|
+
# elsif path? '/'
|
26
|
+
# header content_type: 'text'
|
27
|
+
# 'hi'
|
28
|
+
# else
|
29
|
+
# status 404
|
30
|
+
# 'miss'
|
31
|
+
# end
|
32
|
+
# end
|
33
|
+
# end
|
5
34
|
class Erio
|
6
|
-
@
|
7
|
-
|
8
|
-
@_middle = -> { @status=200; 'set `middle do ... end\' to set routes.'}
|
35
|
+
@_enter = -> { @status=200; 'set `enter do ... end\' to set routes.'}
|
36
|
+
|
9
37
|
def self.inherited(subclass)
|
10
38
|
instance_variables.map { |k| subclass.instance_variable_set(k, instance_variable_get(k)) }
|
11
39
|
end
|
12
40
|
end
|
13
41
|
|
14
42
|
class << Erio
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
43
|
+
# App's ENTER.
|
44
|
+
# When Request will once run
|
45
|
+
#
|
46
|
+
# example:
|
47
|
+
# class App < Erio
|
48
|
+
# enter do |o|
|
49
|
+
# o.status 200
|
50
|
+
# if o.path? '/'
|
51
|
+
# 'hi'
|
52
|
+
# else o.status 404
|
53
|
+
# 'miss'
|
54
|
+
# end
|
55
|
+
# end
|
56
|
+
# end
|
57
|
+
#
|
58
|
+
# @yield run for rack-triad
|
59
|
+
# @return [String, Object] maybe response body
|
60
|
+
def enter &blk; blk ? @_enter = blk : @_enter.arity == 1 ? @_enter.call(self) : class_exec(&@_enter) end
|
21
61
|
|
22
|
-
def
|
62
|
+
def _call env
|
23
63
|
@_env = env
|
24
64
|
@header = {}
|
25
65
|
@status = nil
|
26
66
|
@body = nil
|
27
|
-
|
28
|
-
|
29
|
-
@
|
30
|
-
@_spent = Time.now - @_t0
|
31
|
-
logger
|
32
|
-
after
|
33
|
-
[@status,@header,[@body]]
|
67
|
+
last_res = enter
|
68
|
+
@body ||= last_res || ''
|
69
|
+
[@status, @header, [@body]]
|
34
70
|
end
|
35
71
|
|
72
|
+
# create a dup to indiv variables scope
|
73
|
+
# and call its enter.
|
74
|
+
# returns rack-triad for rack
|
75
|
+
#
|
76
|
+
# @param env
|
77
|
+
# @return Array<Numeric, Hash, Array<String>> triad of
|
36
78
|
def call env
|
37
|
-
|
79
|
+
dup._call(env)
|
80
|
+
end
|
81
|
+
|
82
|
+
def run!
|
83
|
+
Rack::Handler::Puma.run(self)
|
38
84
|
end
|
39
85
|
|
40
86
|
def [] key; instance_variable_get :"@#{key}" end
|
41
87
|
def []= key, value; instance_variable_set :"@#{key}", value end
|
42
|
-
|
43
88
|
end
|
data/sig/erio.rbs
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: erio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kozmozEnjel
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-03-
|
10
|
+
date: 2025-03-14 00:00:00.000000000 Z
|
11
11
|
dependencies: []
|
12
12
|
description: For Education but powerful and useful.
|
13
13
|
email:
|
@@ -18,13 +18,14 @@ extra_rdoc_files: []
|
|
18
18
|
files:
|
19
19
|
- ".rspec"
|
20
20
|
- ".standard.yml"
|
21
|
-
- ".vscode/settings.json"
|
22
21
|
- CHANGELOG.md
|
23
22
|
- CODE_OF_CONDUCT.md
|
24
23
|
- LICENSE.txt
|
25
24
|
- README.md
|
26
25
|
- Rakefile
|
26
|
+
- config.ru
|
27
27
|
- lib/erio.rb
|
28
|
+
- lib/erio/short.rb
|
28
29
|
- lib/erio/version.rb
|
29
30
|
- sig/erio.rbs
|
30
31
|
homepage: https://github.com/saisui/erio-rb
|