erio 0.0.1.2 → 0.0.2.0.pre.2
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 -0
- data/README.md +183 -1
- data/demo/blog.ru +34 -0
- data/demo/map.ru +31 -0
- data/lib/erio/kaki.rb +8 -0
- data/lib/erio/short.rb +14 -14
- data/lib/erio/topo.rb +106 -0
- data/lib/erio/version.rb +1 -1
- data/lib/erio.rb +19 -11
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c793930761cbd3b6dcedf1c21ed6ac9a428aecb1090217776c3c52fd17a5f397
|
4
|
+
data.tar.gz: a40ce8b6e6474695be33182ad90a4c30f8ba221cb629c9108f2f64fcfd659e2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15ae3a24e4d181d3b8cfdf227700d4b2534cdbc3cbec903a3d0999f5e70b8b135b2d8f49e592f64833722f934caab0e9744db7b3d0b924ca125289efeac1d2f4
|
7
|
+
data.tar.gz: 1a52c104b6ff1042df2bb11d8a96784c8f443f433e1fe7ea1055d6accb8a03bea51309ce5028f8f55edc4cc32cf47c1cb1b5053aba2d0f8bdafc42eea2cbb86e
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -4,6 +4,12 @@ A very chubby, tiny and lightweight Web Framework(base on Rack)
|
|
4
4
|
|
5
5
|
凄く小さいなウェブ・フラムワーク。
|
6
6
|
|
7
|
+
<style>
|
8
|
+
[cols-2] { column-count: 2 }
|
9
|
+
[cols-3] { column-count: 3 }
|
10
|
+
[cols-4] { column-count: 4 }
|
11
|
+
</style>
|
12
|
+
|
7
13
|
## インストール :: Installation
|
8
14
|
|
9
15
|
```bash
|
@@ -78,11 +84,187 @@ end
|
|
78
84
|
Erio.run!
|
79
85
|
```
|
80
86
|
|
87
|
+
### 迷う宮ノ様な回路ニ作ろう :: Nested Page Sugar
|
88
|
+
|
89
|
+
|
90
|
+
複雑ノ回路もサポートします。
|
91
|
+
同じのコードを繰り返し書き込みの面倒も遠慮なく。
|
92
|
+
|
93
|
+
<figure cols-2>
|
94
|
+
|
95
|
+
タイプ·M
|
96
|
+
|
97
|
+
```yaml
|
98
|
+
- user
|
99
|
+
- 123
|
100
|
+
- album
|
101
|
+
- 23
|
102
|
+
```
|
103
|
+
|
104
|
+
タイプ·S
|
105
|
+
|
106
|
+
```yaml
|
107
|
+
- /user
|
108
|
+
- /user/123
|
109
|
+
- /user/123/album
|
110
|
+
- /user/123/album/23
|
111
|
+
|
112
|
+
```
|
113
|
+
|
114
|
+
</figure>
|
115
|
+
|
116
|
+
そして、処理に引きされば...
|
117
|
+
|
118
|
+
<figure cols-2>
|
119
|
+
|
120
|
+
タイプ·M
|
121
|
+
|
122
|
+
```yaml
|
123
|
+
- user
|
124
|
+
# 処理 user
|
125
|
+
- ''
|
126
|
+
# 処理
|
127
|
+
- 123
|
128
|
+
# 処理 123
|
129
|
+
- ''
|
130
|
+
# 処理
|
131
|
+
- album
|
132
|
+
# 処理 album
|
133
|
+
# 処理
|
134
|
+
- 23
|
135
|
+
# 処理 23
|
136
|
+
```
|
137
|
+
|
138
|
+
タイプ·S
|
139
|
+
|
140
|
+
```yaml
|
141
|
+
- /user
|
142
|
+
# 処理 user
|
143
|
+
- /user/123
|
144
|
+
# 処理 user
|
145
|
+
# 処理 123
|
146
|
+
- /user/123/album
|
147
|
+
# 処理 user
|
148
|
+
# 処理 123
|
149
|
+
# 処理 album
|
150
|
+
- /user/123/album/23
|
151
|
+
# 処理 user
|
152
|
+
# 処理 123
|
153
|
+
# 処理 album
|
154
|
+
# 処理 23
|
155
|
+
|
156
|
+
```
|
157
|
+
|
158
|
+
</figure>
|
159
|
+
|
160
|
+
#### 実のコードご覧。
|
161
|
+
|
162
|
+
|
163
|
+
<figure cols-2>
|
164
|
+
|
165
|
+
回路ニ使える
|
166
|
+
|
167
|
+
```ruby
|
168
|
+
on 'user'
|
169
|
+
content_type 'html'
|
170
|
+
is do
|
171
|
+
echoln 'userlist...'
|
172
|
+
end
|
173
|
+
|
174
|
+
on Integer do |uid|
|
175
|
+
@uid = uid
|
176
|
+
is do
|
177
|
+
echoln "user: #{uid}"
|
178
|
+
end
|
179
|
+
|
180
|
+
on 'album' do
|
181
|
+
echoln "user #{uid}'s album"
|
182
|
+
is do
|
183
|
+
echoln "pics..."
|
184
|
+
for pic in Dir["asset/user/#{@uid}/*.png"]
|
185
|
+
echoln "<img src=\"#{pic}\">"
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
is Integer do |pn|
|
190
|
+
echoln "pic #{pn}"
|
191
|
+
echoln "<img src=\"asset/#{@uid}/#{@pn}.png\">"
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
```
|
197
|
+
|
198
|
+
回路に使えないならば...線性パス
|
199
|
+
|
200
|
+
```ruby
|
201
|
+
on '/user' do
|
202
|
+
echoln 'userlist...'
|
203
|
+
end
|
204
|
+
|
205
|
+
on '/user/:uid' do |uid|
|
206
|
+
@uid = uid
|
207
|
+
echoln "user: #{uid}"
|
208
|
+
end
|
209
|
+
|
210
|
+
on '/user/:uid/album' do |uid|
|
211
|
+
@uid = uid
|
212
|
+
echoln "user #{uid}'s album"
|
213
|
+
echoln "pics..."
|
214
|
+
for pic in Dir["asset/user/#{@uid}/*.png"].map
|
215
|
+
echoln "<img src=\"#{pic}\">"
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
on '/user/:uid/album/:pn' do |uid, pn|
|
220
|
+
@uid = uid
|
221
|
+
@pn = pn
|
222
|
+
echoln "user #{uid}'s album"
|
223
|
+
echoln "pic #{pn}"
|
224
|
+
echoln "<img src=\"asset/#{@uid}/#{@pn}.png\">"
|
225
|
+
end
|
226
|
+
```
|
227
|
+
|
228
|
+
</figure>
|
229
|
+
|
230
|
+
試験コードご覧ください
|
231
|
+
|
232
|
+
```ruby
|
233
|
+
|
234
|
+
Erio.enter do
|
235
|
+
# 唯ルト、残されパスは無いノ場合。
|
236
|
+
is do
|
237
|
+
echo 'home'
|
238
|
+
end
|
239
|
+
# 前に合わせてならば... そして引数を取って。
|
240
|
+
on 'user', Integer do |_, uid|
|
241
|
+
# 唯此れニ合わせて
|
242
|
+
is do
|
243
|
+
echo "space of user: #{uid}."
|
244
|
+
end
|
245
|
+
# リクエストのパラメータも取って。
|
246
|
+
is 'album', param(pn: Integer) do |_, pn|
|
247
|
+
content_type 'html'
|
248
|
+
echo "picture of user: #{uid} <img src=\"#{pn}.png\">"
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
# 後ノ条件も合わせてしたい。
|
253
|
+
also
|
254
|
+
|
255
|
+
# ご報告ニ送りします
|
256
|
+
on param(:warn) do
|
257
|
+
puts "warn #{ip} - #{verb} #{path}"
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
```
|
262
|
+
|
81
263
|
## 作ル人 :: Creator
|
82
264
|
|
83
265
|
__SAISUI__ :: 彩穂
|
84
266
|
|
85
|
-
tip from `rack`, `sinatra`
|
267
|
+
tip from `rack`, `sinatra`, `rum`
|
86
268
|
|
87
269
|
## コード協力 :: Contributing
|
88
270
|
|
data/demo/blog.ru
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require './lib/erio'
|
2
|
+
|
3
|
+
class Blog < Erio
|
4
|
+
enter do
|
5
|
+
# on 'hello' do
|
6
|
+
# on 'daddy' do
|
7
|
+
# on '' do
|
8
|
+
# res.write 'hi, i\'m fine.'
|
9
|
+
# end
|
10
|
+
# end
|
11
|
+
# on true do
|
12
|
+
# res.write 'hi, nobody.'
|
13
|
+
# end
|
14
|
+
# end
|
15
|
+
# on Integer do |id|
|
16
|
+
# res.write "int: #{id}"
|
17
|
+
# pp 'int'
|
18
|
+
# end
|
19
|
+
# on Numeric do |id|
|
20
|
+
# res.write "num: #{id}"
|
21
|
+
# pp 'num'
|
22
|
+
# end
|
23
|
+
# on '' do
|
24
|
+
# res.write 'index'
|
25
|
+
# end
|
26
|
+
pp path
|
27
|
+
if path =~ /\A\/(\d+)\z/
|
28
|
+
res.write "Hi, Your ID is #{$1}!"
|
29
|
+
run proc { res.write 'Fuck you!' }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
run Blog
|
data/demo/map.ru
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require './lib/erio'
|
2
|
+
|
3
|
+
class App < Erio
|
4
|
+
enter do
|
5
|
+
is do
|
6
|
+
res.write 'home'
|
7
|
+
end
|
8
|
+
on 'hello' do
|
9
|
+
is do
|
10
|
+
res.write 'hi'
|
11
|
+
end
|
12
|
+
is 'me' do
|
13
|
+
res.write 'hello, self?'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
also
|
18
|
+
|
19
|
+
on req.params.empty? do
|
20
|
+
res.write "\nNo Parameters."
|
21
|
+
end
|
22
|
+
|
23
|
+
also
|
24
|
+
|
25
|
+
on accept? 'text' do
|
26
|
+
res.write "\nAccept: Text."
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
run App
|
data/lib/erio/kaki.rb
ADDED
data/lib/erio/short.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
class << Erio
|
2
|
-
def ip; @
|
3
|
-
def user_agent; @
|
4
|
-
def req_body; @
|
5
|
-
def req_scheme; @
|
6
|
-
def req_host; @
|
7
|
-
def query; @
|
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
8
|
|
9
9
|
def decode_www str
|
10
10
|
str.gsub('+','%2B').gsub(/%([\da-fA-F]{2})/) { $1.to_i(16).chr }
|
@@ -14,7 +14,7 @@ class << Erio
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def queries q_str=nil
|
17
|
-
(q_str || @
|
17
|
+
(q_str || @env['QUERY_STRING']).split('&')
|
18
18
|
.map { k,v = [*_1.split('='),''][0,2]; [k, decode_www(v)] }.to_h
|
19
19
|
end
|
20
20
|
|
@@ -40,14 +40,14 @@ class << Erio
|
|
40
40
|
File.binread filename
|
41
41
|
end
|
42
42
|
|
43
|
-
def
|
43
|
+
def req; Rack::Request.new(@env) end
|
44
44
|
def header **kws; kws.empty? ? @header : @header.merge!(kws.to_a.map { [_1.to_s.tr('_','-'),_2] }.to_h) end
|
45
45
|
def status s=nil; s ? @status=s : @status end
|
46
|
-
def path; @
|
47
|
-
def path? pattern=nil; block_given? ? (yield if pattern === path) : path end
|
48
|
-
def verb word=nil; block_given? ? (yield if verb == word) : @
|
46
|
+
def path; @env['REQUEST_PATH'] end
|
47
|
+
def path? pattern=nil; block_given? ? (yield if pattern === path) : pattern === path end
|
48
|
+
def verb word=nil; block_given? ? (yield if verb == word) : @env['REQUEST_METHOD'] end
|
49
49
|
def body str=nil; str ? @body=str : @body end
|
50
|
-
def accept; @
|
50
|
+
def accept; @env['HTTP_ACCEPT'] end
|
51
51
|
|
52
52
|
def status? s=200, &block
|
53
53
|
bool = s === @status
|
@@ -56,7 +56,7 @@ class << Erio
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def ip? cond, &block
|
59
|
-
bool = cond === @
|
59
|
+
bool = cond === @env['REMOTE_ADDR']
|
60
60
|
return bool unless bool && block
|
61
61
|
block.call
|
62
62
|
end
|
@@ -82,7 +82,7 @@ class << Erio
|
|
82
82
|
end
|
83
83
|
|
84
84
|
def accept? *types, &block
|
85
|
-
acc = @
|
85
|
+
acc = @env['HTTP_ACCEPT']
|
86
86
|
bool = types.map do |type|
|
87
87
|
rt = %r[\b#{type}\b]
|
88
88
|
case type
|
data/lib/erio/topo.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
class << Erio
|
2
|
+
|
3
|
+
# a map router for Erio.
|
4
|
+
# nested with `on`
|
5
|
+
# root in `is`
|
6
|
+
# repeated slashes(/) is 1 slash:
|
7
|
+
# `////` == `/`
|
8
|
+
# `/hello/` == `/hello`
|
9
|
+
#
|
10
|
+
# on 'hello' # match '/hello', '/hello/mine', '/hello/'
|
11
|
+
# # not '/helloabc'
|
12
|
+
# on param? :a # match '/?a'
|
13
|
+
# on accept? 'text' # match Header[Accept-Type] like Text.
|
14
|
+
#
|
15
|
+
# class App < Erio
|
16
|
+
# enter do
|
17
|
+
# on 'hello' do
|
18
|
+
# res.write 'hi'
|
19
|
+
# on String, res.params.empty? do |name|
|
20
|
+
# res.write "hi, #{name}!"
|
21
|
+
# end
|
22
|
+
# end
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# @param Bool, String, Class, Proc match path-pattern or any condition then run
|
27
|
+
# @yield take matched args and run.
|
28
|
+
def on(*arg)
|
29
|
+
def path(p)
|
30
|
+
if @_isis
|
31
|
+
lambda {
|
32
|
+
if env['PATH_INFO'] =~ /\A\/*(#{p}\/*)\z/
|
33
|
+
env['SCRIPT_NAME'] += $1||''
|
34
|
+
env['PATH_INFO'] = ''
|
35
|
+
$1
|
36
|
+
end
|
37
|
+
}
|
38
|
+
else
|
39
|
+
lambda {
|
40
|
+
if env['PATH_INFO'] =~ /\A\/(#{p})(\/|\z)/
|
41
|
+
env['SCRIPT_NAME'] += "/#{$1}"
|
42
|
+
env['PATH_INFO'] = $2 + $'
|
43
|
+
$1
|
44
|
+
end
|
45
|
+
}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def eq obj
|
50
|
+
-> { _1 == obj }
|
51
|
+
end
|
52
|
+
|
53
|
+
def match(pat)
|
54
|
+
case pat
|
55
|
+
when eq(Numeric); path('\\d+(?:\\.\\d+)?').call
|
56
|
+
when eq(Integer); path('\\d+').call
|
57
|
+
when eq(String); path('[^\\/]+').call
|
58
|
+
when String, Numeric; path(pat).call
|
59
|
+
when Regexp; path(pat.source).call
|
60
|
+
when true, false; pat
|
61
|
+
when Proc; pat.call
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
return if @_matched
|
66
|
+
s, p = env['SCRIPT_NAME'], env['PATH_INFO']
|
67
|
+
yield *arg.map { |pat| match(pat) || (@_isis=false; return) }
|
68
|
+
env['SCRIPT_NAME'], env['PATH_INFO'] = s, p
|
69
|
+
@_matched = true
|
70
|
+
end
|
71
|
+
#
|
72
|
+
# match path excluded rest characters
|
73
|
+
|
74
|
+
# is 'hi' # match '/hi' not match '/hi/123'
|
75
|
+
# is 'hi/mine' # match '/hi/mine'
|
76
|
+
#
|
77
|
+
# @param String, Regexp whole match
|
78
|
+
# @yield run if matched
|
79
|
+
def is(s='', &block)
|
80
|
+
@_isis = true
|
81
|
+
on(s, &block)
|
82
|
+
end
|
83
|
+
|
84
|
+
# matched but also match another for run block
|
85
|
+
def also; @_matched = false; end
|
86
|
+
|
87
|
+
# alias res.finish, app needed
|
88
|
+
def finish; res.finish; end
|
89
|
+
|
90
|
+
def _call(env)
|
91
|
+
@env = env
|
92
|
+
@res = Rack::Response.new
|
93
|
+
@req = Rack::Request.new(env)
|
94
|
+
catch :erio_run_next_app do
|
95
|
+
@res.status = 404 unless @_matched
|
96
|
+
enter
|
97
|
+
return @res.finish
|
98
|
+
end.call(env)
|
99
|
+
end
|
100
|
+
|
101
|
+
attr :env, :req, :res
|
102
|
+
|
103
|
+
def run(app)
|
104
|
+
throw :erio_run_next_app, app
|
105
|
+
end
|
106
|
+
end
|
data/lib/erio/version.rb
CHANGED
data/lib/erio.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
require_relative "erio/version"
|
4
4
|
require_relative "erio/short"
|
5
|
+
require_relative "erio/topo"
|
6
|
+
require_relative "erio/kaki"
|
5
7
|
require'rack'
|
6
8
|
require'rack/handler/puma'
|
7
9
|
|
@@ -57,22 +59,28 @@ class << Erio
|
|
57
59
|
#
|
58
60
|
# @yield run for rack-triad
|
59
61
|
# @return [String, Object] maybe response body
|
60
|
-
def enter
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
@body = nil
|
67
|
-
last_res = enter
|
68
|
-
@body ||= last_res || ''
|
69
|
-
[@status, @header, [@body]]
|
62
|
+
def enter(&blk)
|
63
|
+
if blk
|
64
|
+
@_enter = blk
|
65
|
+
else
|
66
|
+
@_enter.arity == 1 ? @_enter.call(self) : class_exec(&@_enter)
|
67
|
+
end
|
70
68
|
end
|
71
69
|
|
70
|
+
# def _call env
|
71
|
+
# @_env = env
|
72
|
+
# @header = {}
|
73
|
+
# @status = nil
|
74
|
+
# @body = nil
|
75
|
+
# last_res = enter
|
76
|
+
# @body ||= last_res || ''
|
77
|
+
# [@status, @header, [@body]]
|
78
|
+
# end
|
79
|
+
|
72
80
|
# create a dup to indiv variables scope
|
73
81
|
# and call its enter.
|
74
82
|
# returns rack-triad for rack
|
75
|
-
|
83
|
+
|
76
84
|
# @param env
|
77
85
|
# @return Array<Numeric, Hash, Array<String>> triad of
|
78
86
|
def call env
|
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.2.0.pre.2
|
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-23 00:00:00.000000000 Z
|
11
11
|
dependencies: []
|
12
12
|
description: For Education but powerful and useful.
|
13
13
|
email:
|
@@ -24,8 +24,12 @@ files:
|
|
24
24
|
- README.md
|
25
25
|
- Rakefile
|
26
26
|
- config.ru
|
27
|
+
- demo/blog.ru
|
28
|
+
- demo/map.ru
|
27
29
|
- lib/erio.rb
|
30
|
+
- lib/erio/kaki.rb
|
28
31
|
- lib/erio/short.rb
|
32
|
+
- lib/erio/topo.rb
|
29
33
|
- lib/erio/version.rb
|
30
34
|
- sig/erio.rbs
|
31
35
|
homepage: https://github.com/saisui/erio-rb
|
@@ -50,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
54
|
- !ruby/object:Gem::Version
|
51
55
|
version: '0'
|
52
56
|
requirements: []
|
53
|
-
rubygems_version: 3.6.
|
57
|
+
rubygems_version: 3.6.6
|
54
58
|
specification_version: 4
|
55
59
|
summary: Touwa Erio - A very tiny and lightweight web framework using Rack.
|
56
60
|
test_files: []
|