From 062bbe8c4077604fe56f372b1f3226d7babe2746 Mon Sep 17 00:00:00 2001 From: Joel Drapper Date: Tue, 24 Sep 2024 02:38:00 +0100 Subject: [PATCH] Update sgml.rb --- lib/phlex/sgml.rb | 8 ++++++-- quickdraw/sgml/capture.test.rb | 6 ++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/phlex/sgml.rb b/lib/phlex/sgml.rb index 20f2baf6..de633b84 100644 --- a/lib/phlex/sgml.rb +++ b/lib/phlex/sgml.rb @@ -64,6 +64,10 @@ def to_proc proc { |c| c.render(self) } end + def yielder + yield(self) + end + def call(buffer = +"", context: Phlex::Context.new, view_context: nil, parent: nil, fragments: nil, &block) @_buffer = buffer @_context = context @@ -89,9 +93,9 @@ def call(buffer = +"", context: Phlex::Context.new, view_context: nil, parent: n @_context.around_render do around_template do if block - view_template do |*args| - content = (args.length == 0) ? capture(self, &block) : capture(*args, &block) + content = capture(self) { yielder(&block) } + view_template do context = @_context next if context.fragments && !context.in_target_fragment diff --git a/quickdraw/sgml/capture.test.rb b/quickdraw/sgml/capture.test.rb index ed4469a0..c1a9980b 100644 --- a/quickdraw/sgml/capture.test.rb +++ b/quickdraw/sgml/capture.test.rb @@ -1,8 +1,10 @@ # frozen_string_literal: true class ExampleCaptureWithArguments < Phlex::HTML - def view_template(&block) - h1 { capture("a", "b", "c", &block) } + def yielder = yield("a", "b", "c") + + def view_template(...) + h1(...) end end