zorglub 0.1.5 → 0.1.7

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: abcf28ed3f097126ca87285fb4e856139ea4cd3ee410d3ff294604d5becca95f
4
- data.tar.gz: ecd7ad7f09153e4e847652f448284d559404f6c5682bfd15fcc05a72fe9ffb72
3
+ metadata.gz: be6b53fccd29ce596c15253af31b7c4b7470e1a55075aa34cd541edd54144f57
4
+ data.tar.gz: cda16f4674a73d6ce3659db5e5cf7f51eea5fe0779324990b406046a341b6a04
5
5
  SHA512:
6
- metadata.gz: eb190cc7abd3bf94341d807491b8432c323674e49ed9d52bf151b926ec8f31efd6f61f9c27bfab17e6d1e27f3f4f6d0c1b63e7263340d5dab9edda97c98ad8e2
7
- data.tar.gz: 52e826f544530e6cdadb65b53fda7ec771ed72621a51a72565507515b931da49b3ac5b1c1af93d35c93596db0b0d00be10cf51054acd935a6be1949c35536a27
6
+ metadata.gz: 10c3739c48de2eed8c53c32d703f198ec5fc4a752ce32a36de12c5964664d057ad04f81eeb6ce95b16bd4ae0236e4cd4f02d00c27327372a4479078b1c822e28
7
+ data.tar.gz: 109e27aa1526edff83bd67681f61aced077b2f55a23e13d3b3aaa8ec0962ccf61a8218e0f6f0bcd405cd4c3680e3e370e515ce46718b7d758f86f0322fc1e0bc
data/Changelog CHANGED
@@ -1,3 +1,16 @@
1
+ 2024-10-01 Jérémy Zurcher <jeremy@asynk.ch>
2
+ * release 0.1.7
3
+ * debug to stdout
4
+ * simplify static code path
5
+ * fix error404 msg
6
+ * use keyword arguments
7
+
8
+
9
+ 2024-08-20 Jérémy Zurcher <jeremy@asynk.ch>
10
+ * release 0.1.6
11
+ * fix specs
12
+ * fix Node#error404
13
+
1
14
  2024-08-14 Jérémy Zurcher <jeremy@asynk.ch>
2
15
  * release 0.1.5
3
16
  * fix Node#redirect
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zorglub (0.1.5)
4
+ zorglub (0.1.7)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/lib/zorglub/node.rb CHANGED
@@ -154,7 +154,7 @@ module Zorglub
154
154
  status = options[:status] || 302
155
155
  body = options[:body] || redirect_body(target)
156
156
  header = response.headers.merge('Location' => target.to_s)
157
- throw :stop_realize, Rack::Response.new(body, status, header, &block).finish
157
+ throw :stop_realize, Rack::Response.new(body, status, header, &block)
158
158
  end
159
159
 
160
160
  def redirect_body(target)
@@ -229,7 +229,7 @@ module Zorglub
229
229
  def call(env)
230
230
  meth, *args = env['PATH_INFO'].sub(%r{^/+}, '').split(%r{/})
231
231
  meth ||= 'index'
232
- $stderr << "=> #{meth}(#{args.join ','})\n" if app.opt :debug
232
+ $stdout << "=> #{meth}(#{args.join ','})\n" if app.opt :debug
233
233
  node = new(env, meth, args)
234
234
  return error404 node, meth unless node.respond_to? meth
235
235
 
@@ -237,26 +237,26 @@ module Zorglub
237
237
  end
238
238
 
239
239
  def partial(env, meth, *args)
240
- node = new env, meth.to_s, args, true
240
+ node = new(env, meth.to_s, args, partial: true)
241
241
  return error404 node, meth unless node.respond_to? meth
242
242
 
243
- node.feed! env[:no_hooks]
243
+ node.feed!(no_hooks: env[:no_hooks])
244
244
  node.content
245
245
  end
246
246
 
247
247
  def error404(node, meth)
248
- $stderr << " !! #{node.class.name}::#{meth} not found\n" if app.opt :debug
248
+ $stdout << " !! #{node.class.name}::#{meth} not found\n" if app.opt :debug
249
249
  resp = node.response
250
250
  resp.status = 404
251
251
  resp['content-type'] = 'text/plain'
252
- resp.write "%<node.class.name>s mapped at %<node.map>p can't respond to : %<node.meth>p"
253
- resp
252
+ resp.write "#{node.class.name} mapped at #{node.map} can't respond to : #{node.meth}"
253
+ resp.finish
254
254
  end
255
255
  end
256
256
 
257
257
  attr_reader :request, :response, :content, :mime, :state, :engine, :meth, :args
258
258
 
259
- def initialize(env, meth, args, partial = false)
259
+ def initialize(env, meth, args, partial: false)
260
260
  @meth = meth
261
261
  @args = args
262
262
  @partial = partial
@@ -277,20 +277,19 @@ module Zorglub
277
277
  feed!
278
278
  response.write @content
279
279
  response.headers['content-type'] ||= @mime || 'text/html'
280
- response.finish
281
- end
280
+ response
281
+ end.finish
282
282
  end
283
283
 
284
- def feed!(no_hooks = false)
284
+ def feed!(no_hooks: false)
285
285
  @state = :pre_cb
286
286
  self.class.call_before_hooks self unless no_hooks
287
287
  @state = :meth
288
288
  @content = send @meth, *@args
289
- static_path = static
290
- if static_path.nil?
291
- compile_page!
292
- else
289
+ if (static_path = static)
293
290
  static_page! static_path
291
+ else
292
+ compile_page!
294
293
  end
295
294
  @state = :post_cb
296
295
  self.class.call_after_hooks self unless no_hooks
@@ -301,7 +300,7 @@ module Zorglub
301
300
  def static_page!(path)
302
301
  if File.exist?(path) && (@cache_lifetime.nil? || @cache_lifetime.zero? ||
303
302
  (Time.now - File.stat(path).mtime) < @cache_lifetime)
304
- $stderr << " * use cache file : #{path}\n" if @debug
303
+ $stdout << " * use cache file : #{path}\n" if @debug
305
304
  content = File.read(path)
306
305
  @content = content.sub(/^@mime:(.*)\n/, '')
307
306
  @mime = ::Regexp.last_match(1)
@@ -309,7 +308,7 @@ module Zorglub
309
308
  compile_page!
310
309
  FileUtils.mkdir_p File.dirname(path)
311
310
  File.open(path, 'w') { |f| f.write("@mime:#{@mime}\n#{@content}") }
312
- $stderr << " * cache file created : #{path}\n" if @debug
311
+ $stdout << " * cache file created : #{path}\n" if @debug
313
312
  end
314
313
  end
315
314
 
@@ -318,9 +317,9 @@ module Zorglub
318
317
  v = view
319
318
  l = layout
320
319
  if @debug
321
- $stderr << " * #{e ? 'use engine' : 'no engine '} : #{e ? e.to_s : ''}\n"
322
- $stderr << " * #{l && File.exist?(l) ? 'use layout' : 'no layout '} : #{l || ''}\n"
323
- $stderr << " * #{v && File.exist?(v) ? 'use view ' : 'no view '} : #{v || ''}\n"
320
+ $stdout << " * #{e ? 'use engine' : 'no engine '} : #{e ? e.to_s : ''}\n"
321
+ $stdout << " * #{l && File.exist?(l) ? 'use layout' : 'no layout '} : #{l || ''}\n"
322
+ $stdout << " * #{v && File.exist?(v) ? 'use view ' : 'no view '} : #{v || ''}\n"
324
323
  end
325
324
  @state = @partial ? :partial : :view
326
325
  @content, mime = e.call(v, self) if e && v && File.exist?(v)
data/lib/zorglub.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
3
  module Zorglub
4
- VERSION = '0.1.5'.freeze
4
+ VERSION = '0.1.7'.freeze
5
5
  end
6
6
 
7
7
  require 'zorglub/node'
data/spec/node_spec.rb CHANGED
@@ -49,25 +49,26 @@ describe Zorglub do
49
49
 
50
50
  it 'instance level map should work' do
51
51
  r = Node0.my_call '/with_2args/1/2'
52
- h = YAML.load r.body[0]
52
+ h = YAML.load r[2][0]
53
53
  expect(h[:map]).to eq '/node0'
54
54
  end
55
55
 
56
56
  it 'should return err404 response when no method found' do
57
57
  expect(Node0.respond_to?('noresponse')).to be_falsey
58
58
  r = Node0.my_call '/noresponse'
59
- expect(r.status).to eq 404
59
+ expect(r[2][0]).to eq "Node0 mapped at /node0 can't respond to : noresponse"
60
+ expect(r[0]).to eq 404
60
61
  end
61
62
 
62
63
  it 'simple method should respond' do
63
64
  r = Node0.my_call '/hello'
64
- expect(r.status).to eq 200
65
- expect(r.body[0]).to eq 'world'
65
+ expect(r[0]).to eq 200
66
+ expect(r[2][0]).to eq 'world'
66
67
  end
67
68
 
68
69
  it 'instance level args should work' do
69
70
  r = Node0.my_call '/with_2args/1/2'
70
- h = YAML.load r.body[0]
71
+ h = YAML.load r[2][0]
71
72
  expect(h[:args][0]).to eq '1'
72
73
  expect(h[:args][1]).to eq '2'
73
74
  end
@@ -78,8 +79,8 @@ describe Zorglub do
78
79
 
79
80
  it 'layout proc, method level layout and engine definitions should work' do
80
81
  r = Node0.my_call '/index'
81
- expect(r.status).to eq 200
82
- h = YAML.load r.body[0]
82
+ expect(r[0]).to eq 200
83
+ h = YAML.load r[2][0]
83
84
  ly = File.join Node0.app.layout_base_path, Node0.layout
84
85
  vu = File.join Node0.app.view_base_path, Node0.r, 'index'
85
86
  expect(h[:path]).to eq ly
@@ -89,8 +90,8 @@ describe Zorglub do
89
90
 
90
91
  it 'layout proc, method level layout and engine definitions should work' do
91
92
  r = Node1.my_call '/index'
92
- expect(r.status).to eq 200
93
- h = YAML.load r.body[0]
93
+ expect(r[0]).to eq 200
94
+ h = YAML.load r[2][0]
94
95
  ly = File.join Node1.app.layout_base_path, 'main.spec'
95
96
  vu = File.join Node1.app.view_base_path, Node1.r, 'index.spec'
96
97
  expect(h[:path]).to eq ly
@@ -148,23 +149,23 @@ describe Zorglub do
148
149
 
149
150
  it 'should find view and layout and render them' do
150
151
  r = Node0.my_call '/do_render'
151
- expect(r.status).to eq 200
152
- expect(r.body[0]).to eq 'layout_start view_content layout_end'
152
+ expect(r[0]).to eq 200
153
+ expect(r[2][0]).to eq 'layout_start view_content layout_end'
153
154
  end
154
155
 
155
156
  it 'default mime-type should be text/html' do
156
157
  r = Node0.my_call '/index'
157
- expect(r.headers['Content-type']).to eq 'text/html'
158
+ expect(r[1]['Content-type']).to eq 'text/html'
158
159
  end
159
160
 
160
161
  it 'should be able to override mime-type' do
161
162
  r = Node0.my_call '/do_render'
162
- expect(r.headers['Content-type']).to eq 'text/view'
163
+ expect(r[1]['Content-type']).to eq 'text/view'
163
164
  end
164
165
 
165
166
  it 'should be able to override through rack response mime-type' do
166
167
  r = Node0.my_call '/do_content_type'
167
- expect(r.headers['Content-type']).to eq 'text/mine'
168
+ expect(r[1]['Content-type']).to eq 'text/mine'
168
169
  end
169
170
 
170
171
  it 'partial should render correctly' do
@@ -193,31 +194,31 @@ describe Zorglub do
193
194
 
194
195
  it 'static pages should be generated' do
195
196
  r = Node6.my_call '/do_static'
196
- expect(r.body[0]).to eq 'VAL 1'
197
- expect(r.headers['Content-type']).to eq 'text/static'
197
+ expect(r[2][0]).to eq 'VAL 1'
198
+ expect(r[1]['Content-type']).to eq 'text/static'
198
199
  r = Node6.my_call '/do_static'
199
- expect(r.body[0]).to eq 'VAL 1'
200
- expect(r.headers['Content-type']).to eq 'text/static'
200
+ expect(r[2][0]).to eq 'VAL 1'
201
+ expect(r[1]['Content-type']).to eq 'text/static'
201
202
  r = Node6.my_call '/do_static'
202
- expect(r.body[0]).to eq 'VAL 1'
203
- expect(r.headers['Content-type']).to eq 'text/static'
203
+ expect(r[2][0]).to eq 'VAL 1'
204
+ expect(r[1]['Content-type']).to eq 'text/static'
204
205
  r = Node6.my_call '/no_static'
205
- expect(r.body[0]).to eq 'VAL 4'
206
- expect(r.headers['Content-type']).to eq 'text/static'
206
+ expect(r[2][0]).to eq 'VAL 4'
207
+ expect(r[1]['Content-type']).to eq 'text/static'
207
208
  r = Node6.my_call '/do_static'
208
- expect(r.body[0]).to eq 'VAL 1'
209
- expect(r.headers['Content-type']).to eq 'text/static'
209
+ expect(r[2][0]).to eq 'VAL 1'
210
+ expect(r[1]['Content-type']).to eq 'text/static'
210
211
  Node6.static! true, 0.000001
211
212
  sleep 0.0001
212
213
  r = Node6.my_call '/do_static'
213
- expect(r.body[0]).to eq 'VAL 6'
214
- expect(r.headers['Content-type']).to eq 'text/static'
214
+ expect(r[2][0]).to eq 'VAL 6'
215
+ expect(r[1]['Content-type']).to eq 'text/static'
215
216
  end
216
217
 
217
218
  it 'redirect should work' do
218
219
  r = Node0.my_call '/do_redirect'
219
- expect(r.status).to eq 302
220
- expect(r.headers['location']).to eq Node0.r(:do_partial, 1, 2, 3)
220
+ expect(r[0]).to eq 302
221
+ expect(r[1]['location']).to eq Node0.r(:do_partial, 1, 2, 3)
221
222
  end
222
223
 
223
224
  it 'no_layout! should be inherited' do
@@ -226,84 +227,84 @@ describe Zorglub do
226
227
 
227
228
  it 'cli_vals should be inherited and extended' do
228
229
  r = Node5.my_call '/index'
229
- vars = YAML.load r.body[0]
230
+ vars = YAML.load r[2][0]
230
231
  expect(vars).to eq %w[js0 js1 js3 jsx css0 css1 css2]
231
232
  expect(vars[7]).to be_nil
232
233
  end
233
234
 
234
235
  it 'cli_vals should be extended at method level' do
235
236
  r = Node4.my_call '/more'
236
- vars = YAML.load r.body[0]
237
+ vars = YAML.load r[2][0]
237
238
  expect(vars).to eq %w[js0 js1 js2]
238
239
  expect(vars[3]).to be_nil
239
240
  end
240
241
 
241
242
  it 'cli_vals should be untouched' do
242
243
  r = Node4.my_call '/index'
243
- vars = YAML.load r.body[0]
244
+ vars = YAML.load r[2][0]
244
245
  expect(vars).to eq %w[js0 js1]
245
246
  expect(vars[2]).to be_nil
246
247
  r = Node5.my_call '/index'
247
- vars = YAML.load r.body[0]
248
+ vars = YAML.load r[2][0]
248
249
  expect(vars).to eq %w[js0 js1 js3 jsx css0 css1 css2]
249
250
  expect(vars[7]).to be_nil
250
251
  end
251
252
 
252
253
  it 'ext definition and file engine should work' do
253
254
  r = Node0.my_call '/xml_file'
254
- expect(r.body[0]).to eq "<xml>file<\/xml>\n"
255
- expect(r.headers['Content-type']).to eq 'application/xml'
255
+ expect(r[2][0]).to eq "<xml>file<\/xml>\n"
256
+ expect(r[1]['Content-type']).to eq 'application/xml'
256
257
  r = Node0.my_call '/plain_file'
257
- expect(r.body[0]).to eq "plain file\n"
258
- expect(r.headers['Content-type']).to eq 'text/plain'
258
+ expect(r[2][0]).to eq "plain file\n"
259
+ expect(r[1]['Content-type']).to eq 'text/plain'
259
260
  end
260
261
 
261
262
  it 'no view no layout should work as well' do
262
263
  r = Node0.my_call '/no_view_no_layout'
263
- expect(r.body[0]).to eq 'hello world'
264
+ expect(r[2][0]).to eq 'hello world'
264
265
  end
265
266
 
266
267
  it 'haml engine should work' do
267
268
  Node0.app.opt! :engines_cache_enabled, false
268
269
  r = Node0.my_call '/engines/haml'
269
- expect(r.body[0]).to eq "<h1>Hello <i>world</i></h1>\n"
270
+ expect(r[2][0]).to eq "<h1>Hello <i>world</i></h1>\n"
270
271
  Node0.app.opt! :engines_cache_enabled, true
271
272
  r = Node0.my_call '/engines/haml'
272
- expect(r.body[0]).to eq "<h1>Hello <i>world</i></h1>\n"
273
+ expect(r[2][0]).to eq "<h1>Hello <i>world</i></h1>\n"
273
274
  end
274
275
 
275
276
  it 'sass engine should work' do
276
277
  Node0.app.opt! :engines_cache_enabled, true
277
278
  r = Node0.my_call '/engines/sass'
278
- expect(r.body[0]).to eq "vbar{width:80%;height:23px}vbar ul{list-style-type:none}vbar li{float:left}vbar li a{font-weight:bold}\n"
279
+ expect(r[2][0]).to eq "vbar{width:80%;height:23px}vbar ul{list-style-type:none}vbar li{float:left}vbar li a{font-weight:bold}\n"
279
280
  Node0.app.opt! :engines_cache_enabled, false
280
281
  r = Node0.my_call '/engines/sass'
281
- expect(r.body[0]).to eq "vbar{width:80%;height:23px}vbar ul{list-style-type:none}vbar li{float:left}vbar li a{font-weight:bold}\n"
282
+ expect(r[2][0]).to eq "vbar{width:80%;height:23px}vbar ul{list-style-type:none}vbar li{float:left}vbar li a{font-weight:bold}\n"
282
283
  end
283
284
 
284
285
  it 'view_base_path! should work' do
285
286
  r = Node7.my_call '/view_path'
286
- h = YAML.load r.body[0]
287
+ h = YAML.load r[2][0]
287
288
  expect(h[:view]).to eq File.join(Node7.app.opt(:root), 'alt', 'do_render')
288
289
  end
289
290
 
290
291
  it 'layout_base_path! should work' do
291
292
  r = Node7.my_call '/view_path'
292
- h = YAML.load r.body[0]
293
+ h = YAML.load r[2][0]
293
294
  expect(h[:layout]).to eq File.join(Node7.app.opt(:root), 'alt', 'layout', 'default')
294
295
  end
295
296
 
296
297
  it 'debug out should work' do
297
- stderr0 = $stderr.dup
298
- stderrs = StringIO.new
299
- $stderr = stderrs
298
+ stdout0 = $stdout.dup
299
+ stdouts = StringIO.new
300
+ $stdout = stdouts
300
301
  begin
301
302
  APP.opt! :debug, true
302
303
  Node0.my_call '/hello'
303
304
  ensure
304
- $stderr = stderr0
305
+ $stdout = stdout0
305
306
  end
306
- expect(stderrs.string.include?('spec/data/view/node0/hello')).to be true
307
+ expect(stdouts.string.include?('spec/data/view/node0/hello')).to be true
307
308
  end
308
309
  end
309
310
  end
data/spec/spec_helper.rb CHANGED
@@ -46,7 +46,7 @@ class Zorglub::Node
46
46
  end
47
47
 
48
48
  def self.my_call_i(uri)
49
- call({ 'PATH_INFO' => uri }).body[0].to_i
49
+ call({ 'PATH_INFO' => uri })[2][0].to_i
50
50
  end
51
51
  end
52
52
 
data/zorglub.gemspec CHANGED
@@ -1,26 +1,23 @@
1
1
  #! /usr/bin/env ruby
2
- # -*- coding: UTF-8 -*-
3
2
 
4
- $:.push File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.push File.expand_path("../lib", __FILE__)
5
4
 
6
5
  begin
7
- require 'zorglub'
6
+ require 'zorglub'
8
7
  rescue LoadError
9
8
  end
10
9
 
11
10
  Gem::Specification.new do |s|
12
- s.name = "zorglub"
13
- s.version = Zorglub::VERSION
14
- s.authors = ["Jérémy Zurcher"]
15
- s.email = ["jeremy@asynk.ch"]
16
- s.homepage = "http://github.com/jeremyz/zorglub"
17
- s.summary = %q{a nano web application framework based on rack }
18
- s.description = %q{This is a very stripped down version of innate.}
11
+ s.name = 'zorglub'
12
+ s.version = Zorglub::VERSION
13
+ s.authors = ['Jérémy Zurcher']
14
+ s.email = ['jeremy@asynk.ch']
15
+ s.homepage = 'http://github.com/jeremyz/zorglub'
16
+ s.summary = %s(a rack based nano web application framework)
17
+ s.description = %s(A very stripped down version of innate.)
19
18
 
20
- s.files = `git ls-files`.split("\n")
21
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
- s.require_paths = ["lib"]
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
22
+ s.require_paths = ['lib']
24
23
  end
25
-
26
- # EOF
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zorglub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jérémy Zurcher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-14 00:00:00.000000000 Z
11
+ date: 2024-10-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: This is a very stripped down version of innate.
13
+ description: A very stripped down version of innate.
14
14
  email:
15
15
  - jeremy@asynk.ch
16
16
  executables: []
@@ -77,7 +77,7 @@ requirements: []
77
77
  rubygems_version: 3.4.19
78
78
  signing_key:
79
79
  specification_version: 4
80
- summary: a nano web application framework based on rack
80
+ summary: a rack based nano web application framework
81
81
  test_files:
82
82
  - spec/app_spec.rb
83
83
  - spec/data/alt/do_render