Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Yield self on #to_s #91

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions spec/blueprint/html_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
<div class="flex flex-col gap-2 bg-white border shadow">
<div class="p-2 text-lg font-bold">Hello</div>
<div class="p-4">Blueprint</div>
</div>
HTML

actual_html.should eq expected_html
end
end
end
2 changes: 1 addition & 1 deletion src/blueprint/html.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading