zorglub 0.1.8 → 0.1.9
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 +13 -1
- data/Gemfile +5 -4
- data/Gemfile.lock +30 -20
- data/lib/zorglub/node.rb +32 -17
- data/lib/zorglub/session.rb +4 -32
- data/lib/zorglub.rb +1 -1
- data/spec/node_spec.rb +20 -4
- data/spec/spec_helper.rb +12 -1
- metadata +3 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bf262a5d18465314e40cfa28bf3c547dd4cbbb8c296908c4748d66a4b53facdc
|
|
4
|
+
data.tar.gz: 61210551728871485fcd2f1a4dbba7567aab3df98ad2b904d1b91b750b6e6928
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0ffba7e7b5e57088a261820ea5d997cf62814ed1f61177a1c1e0dcb09b3b70722f46b8390aad4b7cc0a51c92526e878eab1f993a6d726e044b16efe1c7e58ef7
|
|
7
|
+
data.tar.gz: 99ec63041fad6025ebc1feea9aa31e3337184f2bfeeb38a48d5fc8a37f19780f4eaf0c62fdc4447c082319d23368d7bfd75bdd737cf561a9e75bd7ee24d66729
|
data/Changelog
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
|
|
2
|
+
2026-02-16 Jérémy Zurcher <jeremy@asynk.ch>
|
|
3
|
+
* release 0.1.9
|
|
4
|
+
* support nil meth
|
|
5
|
+
* may override view in partial call
|
|
6
|
+
* local variables, recursion check, instance level partial method
|
|
7
|
+
* partial(env, …) -> partial(… env: {}, no_hooks: false)
|
|
8
|
+
* use securerandom
|
|
9
|
+
|
|
10
|
+
2025-04-09 Jérémy Zurcher <jeremy@asynk.ch>
|
|
11
|
+
* release 0.1.8
|
|
12
|
+
* bundle update
|
|
13
|
+
|
|
1
14
|
2024-10-01 Jérémy Zurcher <jeremy@asynk.ch>
|
|
2
15
|
* release 0.1.7
|
|
3
16
|
* debug to stdout
|
|
@@ -5,7 +18,6 @@
|
|
|
5
18
|
* fix error404 msg
|
|
6
19
|
* use keyword arguments
|
|
7
20
|
|
|
8
|
-
|
|
9
21
|
2024-08-20 Jérémy Zurcher <jeremy@asynk.ch>
|
|
10
22
|
* release 0.1.6
|
|
11
23
|
* fix specs
|
data/Gemfile
CHANGED
|
@@ -4,15 +4,16 @@ source "http://rubygems.org"
|
|
|
4
4
|
gemspec
|
|
5
5
|
|
|
6
6
|
gem 'rack'
|
|
7
|
+
gem 'securerandom'
|
|
7
8
|
|
|
8
9
|
group :test do
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
gem 'rake'
|
|
11
|
+
gem 'rspec'
|
|
11
12
|
end
|
|
12
13
|
|
|
13
14
|
group :test, :development do
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
gem 'haml'
|
|
16
|
+
gem 'sassc'
|
|
16
17
|
end
|
|
17
18
|
|
|
18
19
|
gem 'coveralls', require: false
|
data/Gemfile.lock
CHANGED
|
@@ -1,56 +1,65 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
zorglub (0.1.
|
|
4
|
+
zorglub (0.1.9)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: http://rubygems.org/
|
|
8
8
|
specs:
|
|
9
|
-
bigdecimal (
|
|
9
|
+
bigdecimal (4.0.1)
|
|
10
10
|
coveralls (0.8.23)
|
|
11
11
|
json (>= 1.8, < 3)
|
|
12
12
|
simplecov (~> 0.16.1)
|
|
13
13
|
term-ansicolor (~> 1.3)
|
|
14
14
|
thor (>= 0.19.4, < 2.0)
|
|
15
15
|
tins (~> 1.6)
|
|
16
|
-
diff-lcs (1.6.
|
|
16
|
+
diff-lcs (1.6.2)
|
|
17
17
|
docile (1.4.1)
|
|
18
|
-
ffi (1.17.
|
|
19
|
-
haml (
|
|
18
|
+
ffi (1.17.3)
|
|
19
|
+
haml (7.2.0)
|
|
20
20
|
temple (>= 0.8.2)
|
|
21
21
|
thor
|
|
22
22
|
tilt
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
io-console (0.8.2)
|
|
24
|
+
json (2.18.1)
|
|
25
|
+
mize (0.6.1)
|
|
26
|
+
rack (3.2.5)
|
|
27
|
+
rake (13.3.1)
|
|
28
|
+
readline (0.0.4)
|
|
29
|
+
reline
|
|
30
|
+
reline (0.6.3)
|
|
31
|
+
io-console (~> 0.5)
|
|
32
|
+
rspec (3.13.2)
|
|
27
33
|
rspec-core (~> 3.13.0)
|
|
28
34
|
rspec-expectations (~> 3.13.0)
|
|
29
35
|
rspec-mocks (~> 3.13.0)
|
|
30
|
-
rspec-core (3.13.
|
|
36
|
+
rspec-core (3.13.6)
|
|
31
37
|
rspec-support (~> 3.13.0)
|
|
32
|
-
rspec-expectations (3.13.
|
|
38
|
+
rspec-expectations (3.13.5)
|
|
33
39
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
34
40
|
rspec-support (~> 3.13.0)
|
|
35
|
-
rspec-mocks (3.13.
|
|
41
|
+
rspec-mocks (3.13.7)
|
|
36
42
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
37
43
|
rspec-support (~> 3.13.0)
|
|
38
|
-
rspec-support (3.13.
|
|
44
|
+
rspec-support (3.13.7)
|
|
39
45
|
sassc (2.4.0)
|
|
40
46
|
ffi (~> 1.9)
|
|
47
|
+
securerandom (0.4.1)
|
|
41
48
|
simplecov (0.16.1)
|
|
42
49
|
docile (~> 1.1)
|
|
43
50
|
json (>= 1.8, < 3)
|
|
44
51
|
simplecov-html (~> 0.10.0)
|
|
45
52
|
simplecov-html (0.10.2)
|
|
46
53
|
sync (0.5.0)
|
|
47
|
-
temple (0.10.
|
|
48
|
-
term-ansicolor (1.11.
|
|
49
|
-
tins (~> 1
|
|
50
|
-
thor (1.
|
|
51
|
-
tilt (2.
|
|
52
|
-
tins (1.
|
|
54
|
+
temple (0.10.4)
|
|
55
|
+
term-ansicolor (1.11.3)
|
|
56
|
+
tins (~> 1)
|
|
57
|
+
thor (1.5.0)
|
|
58
|
+
tilt (2.7.0)
|
|
59
|
+
tins (1.51.1)
|
|
53
60
|
bigdecimal
|
|
61
|
+
mize (~> 0.6)
|
|
62
|
+
readline
|
|
54
63
|
sync
|
|
55
64
|
|
|
56
65
|
PLATFORMS
|
|
@@ -63,7 +72,8 @@ DEPENDENCIES
|
|
|
63
72
|
rake
|
|
64
73
|
rspec
|
|
65
74
|
sassc
|
|
75
|
+
securerandom
|
|
66
76
|
zorglub!
|
|
67
77
|
|
|
68
78
|
BUNDLED WITH
|
|
69
|
-
|
|
79
|
+
4.0.6
|
data/lib/zorglub/node.rb
CHANGED
|
@@ -146,6 +146,10 @@ module Zorglub
|
|
|
146
146
|
File.join map, (args.empty? ? meth : args.map(&:to_s))
|
|
147
147
|
end
|
|
148
148
|
|
|
149
|
+
def partial(meth, *args, **options)
|
|
150
|
+
self.class.partial(meth, *args, env: request.env, parent: self, **options)
|
|
151
|
+
end
|
|
152
|
+
|
|
149
153
|
def html
|
|
150
154
|
%i[map r args engine layout view].inject('') { |s, sym| s + "<p>#{sym} => #{send sym}</p>" }
|
|
151
155
|
end
|
|
@@ -231,16 +235,16 @@ module Zorglub
|
|
|
231
235
|
meth ||= 'index'
|
|
232
236
|
$stdout << "=> #{meth}(#{args.join ','})\n" if app.opt :debug
|
|
233
237
|
node = new(env, meth, args)
|
|
234
|
-
return error404
|
|
238
|
+
return error404(node, meth) unless node.respond_to?(meth)
|
|
235
239
|
|
|
236
240
|
node.realize!
|
|
237
241
|
end
|
|
238
242
|
|
|
239
|
-
def partial(
|
|
240
|
-
node = new(env, meth
|
|
241
|
-
return error404
|
|
243
|
+
def partial(meth, *args, **options)
|
|
244
|
+
node = new(options[:env] || {}, meth, args, partial: true, **options)
|
|
245
|
+
return error404(node, meth) unless meth.nil? || node.respond_to?(meth)
|
|
242
246
|
|
|
243
|
-
node.feed!(no_hooks:
|
|
247
|
+
node.feed!(no_hooks: options[:no_hooks] || false)
|
|
244
248
|
node.content
|
|
245
249
|
end
|
|
246
250
|
|
|
@@ -254,22 +258,33 @@ module Zorglub
|
|
|
254
258
|
end
|
|
255
259
|
end
|
|
256
260
|
|
|
257
|
-
attr_reader :request, :response, :content, :mime, :state, :engine, :meth, :args
|
|
261
|
+
attr_reader :request, :response, :content, :mime, :state, :engine, :meth, :args, :depth, :parent
|
|
262
|
+
|
|
263
|
+
def initialize(env, meth, args, **options)
|
|
264
|
+
@parent = options[:parent]
|
|
265
|
+
@depth = @parent ? @parent.depth + 1 : 0
|
|
266
|
+
raise 'Recursive partial depth limit exceeded' if @depth > 20
|
|
258
267
|
|
|
259
|
-
def initialize(env, meth, args, partial: false)
|
|
260
|
-
@meth = meth
|
|
261
|
-
@args = args
|
|
262
|
-
@partial = partial
|
|
263
|
-
@request = Rack::Request.new env
|
|
264
|
-
@response = Rack::Response.new
|
|
265
|
-
@cli_vals = {}
|
|
266
268
|
@debug = app.opt :debug
|
|
267
|
-
@engine = self.class.engine
|
|
268
|
-
@layout = (partial ? nil : self.class.layout)
|
|
269
|
-
@view = r(meth)
|
|
270
269
|
@static = self.class.static
|
|
270
|
+
@engine = self.class.engine
|
|
271
271
|
@cache_lifetime = self.class.cache_lifetime
|
|
272
|
+
|
|
273
|
+
@meth = meth.to_s
|
|
274
|
+
@args = args
|
|
275
|
+
@request = @parent ? @parent.request : Rack::Request.new(env)
|
|
276
|
+
@response = @parent ? @parent.response : Rack::Response.new
|
|
277
|
+
|
|
278
|
+
@view = options[:view] || r(@meth)
|
|
279
|
+
@partial = options[:partial] || false
|
|
280
|
+
@layout = (options[:partial] ? nil : self.class.layout)
|
|
281
|
+
|
|
282
|
+
@cli_vals = {}
|
|
272
283
|
self.class.cli_vals.each { |s, v| cli_val s, *v }
|
|
284
|
+
|
|
285
|
+
(options[:locals] || {}).each do |k, v|
|
|
286
|
+
instance_variable_set("@#{k}", v)
|
|
287
|
+
end
|
|
273
288
|
end
|
|
274
289
|
|
|
275
290
|
def realize!
|
|
@@ -285,7 +300,7 @@ module Zorglub
|
|
|
285
300
|
@state = :pre_cb
|
|
286
301
|
self.class.call_before_hooks self unless no_hooks
|
|
287
302
|
@state = :meth
|
|
288
|
-
@content = send
|
|
303
|
+
@content = send(@meth, *@args) unless @meth.empty?
|
|
289
304
|
if (static_path = static)
|
|
290
305
|
static_page! static_path
|
|
291
306
|
else
|
data/lib/zorglub/session.rb
CHANGED
|
@@ -110,39 +110,11 @@ module Zorglub
|
|
|
110
110
|
end
|
|
111
111
|
|
|
112
112
|
def generate_sid!
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
begin
|
|
118
|
-
require 'securerandom'
|
|
119
|
-
# Using SecureRandom, optional length.
|
|
120
|
-
# SecureRandom is available since Ruby 1.8.7.
|
|
121
|
-
# For Ruby versions earlier than that, you can require the uuidtools gem,
|
|
122
|
-
# which has a drop-in replacement for SecureRandom.
|
|
123
|
-
def sid_algorithm
|
|
124
|
-
SecureRandom.hex(@options[:sid_len])
|
|
125
|
-
end
|
|
126
|
-
rescue LoadError
|
|
127
|
-
require 'openssl'
|
|
128
|
-
# Using OpenSSL::Random for generation, this is comparable in performance
|
|
129
|
-
# with stdlib SecureRandom and also allows for optional length, it should
|
|
130
|
-
# have the same behaviour as the SecureRandom::hex method of the
|
|
131
|
-
# uuidtools gem.
|
|
132
|
-
def sid_algorithm
|
|
133
|
-
OpenSSL::Random.random_bytes(@options[:sid_len] / 2).unpack1('H*')[0]
|
|
134
|
-
end
|
|
135
|
-
rescue LoadError
|
|
136
|
-
# Digest::SHA2::hexdigest produces a string of length 64, although
|
|
137
|
-
# collisions are not very likely, the entropy is still very low and
|
|
138
|
-
# length is not optional.
|
|
139
|
-
#
|
|
140
|
-
# Replacing it with OS-provided random data would take a lot of code and
|
|
141
|
-
# won't be as cross-platform as Ruby.
|
|
142
|
-
def sid_algorithm
|
|
143
|
-
entropy = [srand, rand, Time.now.to_f, rand, $$, rand, object_id]
|
|
144
|
-
Digest::SHA2.hexdigest(entropy.join)
|
|
113
|
+
loop do
|
|
114
|
+
sid = SecureRandom.hex(@options[:sid_len])
|
|
115
|
+
break unless @sessions.key?(sid)
|
|
145
116
|
end
|
|
117
|
+
sid
|
|
146
118
|
end
|
|
147
119
|
end
|
|
148
120
|
end
|
data/lib/zorglub.rb
CHANGED
data/spec/node_spec.rb
CHANGED
|
@@ -169,17 +169,21 @@ describe Zorglub do
|
|
|
169
169
|
end
|
|
170
170
|
|
|
171
171
|
it 'partial should render correctly' do
|
|
172
|
-
expect(Node0.partial(
|
|
172
|
+
expect(Node0.partial(:do_partial, 1, 2)).to eq 'partial_content'
|
|
173
173
|
end
|
|
174
174
|
|
|
175
175
|
it 'method level view should work' do
|
|
176
|
-
expect(Node0.partial(
|
|
176
|
+
expect(Node0.partial(:other_view)).to eq 'partial_content'
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
it 'partial may override the view' do
|
|
180
|
+
expect(Node0.partial(:do_partial, 1, 2, view: Node0.r(:do_render))).to eq 'do_render'
|
|
177
181
|
end
|
|
178
182
|
|
|
179
183
|
it 'partial with hooks should be default' do
|
|
180
184
|
Node3.before = 0
|
|
181
185
|
Node3.after = 0
|
|
182
|
-
expect(Node3.partial(
|
|
186
|
+
expect(Node3.partial(:do_partial, 1, 2)).to eq 'partial_content'
|
|
183
187
|
expect(Node3.before).to eq 1
|
|
184
188
|
expect(Node3.after).to eq 1
|
|
185
189
|
end
|
|
@@ -187,11 +191,23 @@ describe Zorglub do
|
|
|
187
191
|
it 'partial without hooks should work' do
|
|
188
192
|
Node3.before = 0
|
|
189
193
|
Node3.after = 0
|
|
190
|
-
expect(Node3.partial(
|
|
194
|
+
expect(Node3.partial(:do_partial, 1, 2, no_hooks: true)).to eq 'partial_content'
|
|
191
195
|
expect(Node3.before).to eq 0
|
|
192
196
|
expect(Node3.after).to eq 0
|
|
193
197
|
end
|
|
194
198
|
|
|
199
|
+
it 'partial with locals should work' do
|
|
200
|
+
expect(Node0.partial(:test_locals, locals: { my_local: 'hello' })).to eq 'hello'
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
it 'recursive partial should work' do
|
|
204
|
+
expect(Node0.partial(:test_recursive, 3)).to eq '3-2-1-end'
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
it 'recursive partial depth limit should be enforced' do
|
|
208
|
+
expect { Node0.partial(:test_recursive, 25) }.to raise_error('Recursive partial depth limit exceeded')
|
|
209
|
+
end
|
|
210
|
+
|
|
195
211
|
it 'static pages should be generated' do
|
|
196
212
|
r = Node6.my_call '/do_static'
|
|
197
213
|
expect(r[2][0]).to eq 'VAL 1'
|
data/spec/spec_helper.rb
CHANGED
|
@@ -33,7 +33,7 @@ RENDER_PROC = proc { |_path, obj|
|
|
|
33
33
|
when :view
|
|
34
34
|
['view_content', 'text/view']
|
|
35
35
|
when :partial
|
|
36
|
-
['partial_content', 'text/partial']
|
|
36
|
+
[obj.view =~ /do_render/ ? 'do_render' : 'partial_content', 'text/partial']
|
|
37
37
|
else
|
|
38
38
|
raise Exception.new
|
|
39
39
|
end
|
|
@@ -118,6 +118,17 @@ class Node0 < Zorglub::Node
|
|
|
118
118
|
engine! :sass
|
|
119
119
|
end
|
|
120
120
|
end
|
|
121
|
+
|
|
122
|
+
def test_locals
|
|
123
|
+
@my_local
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def test_recursive(val)
|
|
127
|
+
val = val.to_i
|
|
128
|
+
return 'end' if val <= 0
|
|
129
|
+
|
|
130
|
+
"#{val}-" + partial(:test_recursive, val - 1)
|
|
131
|
+
end
|
|
121
132
|
end
|
|
122
133
|
|
|
123
134
|
class Node1 < Zorglub::Node
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: zorglub
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.9
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jérémy Zurcher
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies: []
|
|
13
12
|
description: A very stripped down version of innate.
|
|
14
13
|
email:
|
|
@@ -59,7 +58,6 @@ files:
|
|
|
59
58
|
homepage: http://github.com/jeremyz/zorglub
|
|
60
59
|
licenses: []
|
|
61
60
|
metadata: {}
|
|
62
|
-
post_install_message:
|
|
63
61
|
rdoc_options: []
|
|
64
62
|
require_paths:
|
|
65
63
|
- lib
|
|
@@ -74,8 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
74
72
|
- !ruby/object:Gem::Version
|
|
75
73
|
version: '0'
|
|
76
74
|
requirements: []
|
|
77
|
-
rubygems_version: 3.
|
|
78
|
-
signing_key:
|
|
75
|
+
rubygems_version: 3.6.9
|
|
79
76
|
specification_version: 4
|
|
80
77
|
summary: a rack based nano web application framework
|
|
81
78
|
test_files:
|