homura-runtime 0.2.17 → 0.2.18
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/exe/compile-erb +65 -0
- data/lib/cloudflare_workers/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1bd6f3a366405aeb0ba2673c4827c7d34d8bef757d9194c64e71ca881bfe821f
|
|
4
|
+
data.tar.gz: 1ccc18ce83b42969bac914ecda37c21cdbfe79fd86971a1de1df1b25c3014302
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 777ce1497af06f6a5168bef5e195576fcdbd216a7da25b5d0eda657fea4757f074fb48f873f28eb3f6c5854c5ce98bf1f01dfa870b31a067eab93ef7dd8b9dce
|
|
7
|
+
data.tar.gz: 6a9e88cbfea6b27e46dc35c1bdb24bc02cdba8899839066d9d547057e18d9d67a319fdabed88a4ad36f852af49fd97bf41ef3aad964b720333bdd29c5c1438f6
|
data/exe/compile-erb
CHANGED
|
@@ -287,11 +287,21 @@ def emit_header(io, namespace)
|
|
|
287
287
|
body = @templates[name.to_sym]
|
|
288
288
|
raise "#{namespace}: no template registered for \#{name.inspect}" unless body
|
|
289
289
|
previous_block = instance.instance_variable_get(:@__homura_template_block__)
|
|
290
|
+
previous_locals = instance.instance_variable_get(:@__homura_template_locals__)
|
|
290
291
|
begin
|
|
291
292
|
instance.instance_variable_set(:@__homura_template_block__, block)
|
|
293
|
+
# Stack locals so nested `erb :_partial, locals: {...}` calls
|
|
294
|
+
# restore the outer scope on the way out — Sinatra's standard
|
|
295
|
+
# `locals[:t]` -> bare `t` lookup is implemented via
|
|
296
|
+
# method_missing on the Sinatra instance (see Sinatra::Base
|
|
297
|
+
# patch installed by emit_sinatra_patch).
|
|
298
|
+
stack = previous_locals.is_a?(::Array) ? previous_locals.dup : []
|
|
299
|
+
stack.push(locals || {})
|
|
300
|
+
instance.instance_variable_set(:@__homura_template_locals__, stack)
|
|
292
301
|
instance.instance_exec(locals, &body)
|
|
293
302
|
ensure
|
|
294
303
|
instance.instance_variable_set(:@__homura_template_block__, previous_block)
|
|
304
|
+
instance.instance_variable_set(:@__homura_template_locals__, previous_locals)
|
|
295
305
|
end
|
|
296
306
|
end
|
|
297
307
|
|
|
@@ -341,6 +351,61 @@ def emit_sinatra_patch(io, namespace)
|
|
|
341
351
|
block.call
|
|
342
352
|
end
|
|
343
353
|
|
|
354
|
+
# Resolve a Sinatra-style local variable reference.
|
|
355
|
+
# `erb :_partial, locals: { t: row }` causes the precompiled body
|
|
356
|
+
# to reference a bare `t`. Stock Sinatra uses Ruby's `binding`
|
|
357
|
+
# eval to install locals into the template's scope; we don't have
|
|
358
|
+
# `binding` under Opal/Workers, so we hand-roll the lookup
|
|
359
|
+
# through method_missing against the locals stack maintained by
|
|
360
|
+
# the renderer.
|
|
361
|
+
def __homura_template_local__(name)
|
|
362
|
+
stack = @__homura_template_locals__
|
|
363
|
+
return nil unless stack.is_a?(::Array)
|
|
364
|
+
key = name.to_sym
|
|
365
|
+
stack.reverse_each do |frame|
|
|
366
|
+
next unless frame.is_a?(::Hash)
|
|
367
|
+
return frame[key] if frame.key?(key)
|
|
368
|
+
sk = name.to_s
|
|
369
|
+
return frame[sk] if frame.key?(sk)
|
|
370
|
+
end
|
|
371
|
+
nil
|
|
372
|
+
end
|
|
373
|
+
|
|
374
|
+
def __homura_template_local_defined?(name)
|
|
375
|
+
stack = @__homura_template_locals__
|
|
376
|
+
return false unless stack.is_a?(::Array)
|
|
377
|
+
key = name.to_sym
|
|
378
|
+
sk = name.to_s
|
|
379
|
+
stack.reverse_each do |frame|
|
|
380
|
+
next unless frame.is_a?(::Hash)
|
|
381
|
+
return true if frame.key?(key) || frame.key?(sk)
|
|
382
|
+
end
|
|
383
|
+
false
|
|
384
|
+
end
|
|
385
|
+
end
|
|
386
|
+
end
|
|
387
|
+
|
|
388
|
+
# Method-missing fallback that surfaces template locals as bare names.
|
|
389
|
+
# Installed on Sinatra::Base so `<%= t['title'] %>` inside a
|
|
390
|
+
# precompiled partial Just Works without the user having to write
|
|
391
|
+
# `<%= locals[:t]['title'] %>`.
|
|
392
|
+
class ::Sinatra::Base
|
|
393
|
+
def method_missing(name, *args, &block)
|
|
394
|
+
if args.empty? && block.nil? && __homura_template_local_defined?(name)
|
|
395
|
+
return __homura_template_local__(name)
|
|
396
|
+
end
|
|
397
|
+
super
|
|
398
|
+
end
|
|
399
|
+
|
|
400
|
+
def respond_to_missing?(name, include_private = false)
|
|
401
|
+
return true if __homura_template_local_defined?(name)
|
|
402
|
+
super
|
|
403
|
+
end
|
|
404
|
+
end
|
|
405
|
+
|
|
406
|
+
module ::Sinatra
|
|
407
|
+
module Templates
|
|
408
|
+
|
|
344
409
|
def __homura_default_template_block_for__(template)
|
|
345
410
|
case template.to_sym
|
|
346
411
|
when :layout
|