Skip to content

Commit

Permalink
feat: Allow passing comment via argument
Browse files Browse the repository at this point in the history
  • Loading branch information
stephannv committed Sep 9, 2024
1 parent 3cf6f16 commit 52d81a1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion spec/blueprint/html/utils_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ private class DummyPage
plain "User"

comment { "This is an html comment" }
comment "This is another html comment"
end
end

Expand All @@ -36,11 +37,17 @@ describe "Blueprint::HTML utils" do
end

describe "#comment" do
it "renders an html comment" do
it "renders an html comment passed via block" do
page = DummyPage.new

page.to_html.should contain("<!--This is an html comment-->")
end

it "renders an html comment passed via argument" do
page = DummyPage.new

page.to_html.should contain("<!--This is another html comment-->")
end
end

describe "#whitespace" do
Expand Down
6 changes: 6 additions & 0 deletions src/blueprint/html/utils.cr
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ module Blueprint::HTML
@buffer << "-->"
end

private def comment(content : String) : Nil
@buffer << "<!--"
::HTML.escape(content, @buffer)
@buffer << "-->"
end

private def whitespace : Nil
@buffer << " "
end
Expand Down

0 comments on commit 52d81a1

Please sign in to comment.