From ef9165f6d87f86a4467780aa430dfb4e4d6a86a6 Mon Sep 17 00:00:00 2001 From: stephann <3025661+stephannv@users.noreply.github.com> Date: Sun, 20 Oct 2024 17:19:42 -0300 Subject: [PATCH] fix: Yield self on #to_s --- spec/blueprint/html_spec.cr | 15 +++++++++++++++ src/blueprint/html.cr | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/spec/blueprint/html_spec.cr b/spec/blueprint/html_spec.cr index fdfaa82..3192402 100644 --- a/spec/blueprint/html_spec.cr +++ b/spec/blueprint/html_spec.cr @@ -127,5 +127,20 @@ describe Blueprint::HTML do html.should eq expected_html end + + it "yields self" do + actual_html = ArticleComponent.new("Hello").to_s do |article| + article.body { "Blueprint" } + end + + expected_html = normalize_html <<-HTML +
+
Hello
+
Blueprint
+
+ HTML + + actual_html.should eq expected_html + end end end diff --git a/src/blueprint/html.cr b/src/blueprint/html.cr index 12dd753..7485764 100644 --- a/src/blueprint/html.cr +++ b/src/blueprint/html.cr @@ -29,7 +29,7 @@ module Blueprint::HTML end def to_s(&) : String - to_s(@buffer) { yield } + to_s(@buffer) { yield self } @buffer.to_s end