From ea82b989c806204edc78ac2e842ca988699699f7 Mon Sep 17 00:00:00 2001 From: stephann <3025661+stephannv@users.noreply.github.com> Date: Fri, 13 Sep 2024 18:31:29 -0300 Subject: [PATCH] fix: Remove some utils methods (plain(&), comment(&), unsafe_raw(&) (#69) --- spec/blueprint/html/safety_spec.cr | 16 +++----------- spec/blueprint/html/utils_spec.cr | 34 ++++++------------------------ src/blueprint/html/utils.cr | 18 +++------------- 3 files changed, 13 insertions(+), 55 deletions(-) diff --git a/spec/blueprint/html/safety_spec.cr b/spec/blueprint/html/safety_spec.cr index 32f0372..1542772 100644 --- a/spec/blueprint/html/safety_spec.cr +++ b/spec/blueprint/html/safety_spec.cr @@ -11,8 +11,7 @@ private class Example plain "" render(ExampleComponent.new) { "" } div(class: "some-class\" onblur=\"alert('Attribute')") - comment { "--> - HTML - - page.to_s.should contain(expected_html) - end - - it "escapes comment content passed via argument" do - page = Example.new - expected_html = normalize_html <<-HTML - + HTML page.to_s.should contain(expected_html) diff --git a/spec/blueprint/html/utils_spec.cr b/spec/blueprint/html/utils_spec.cr index 0bdb675..910b2b2 100644 --- a/spec/blueprint/html/utils_spec.cr +++ b/spec/blueprint/html/utils_spec.cr @@ -10,33 +10,25 @@ private class ExamplePage b "World" end - span { plain { "Plain!" } } - i "Hi" whitespace plain "User" - comment { "This is an html comment" } - comment "This is another html comment" + comment "This is an html comment" - unsafe_raw "" - div { unsafe_raw { "" } } + div do + unsafe_raw "" + end end end describe "utils" do describe "#plain" do - it "renders plain text passed via argument" do + it "renders plain text" do page = ExamplePage.new page.to_s.should contain("
HelloWorld
") end - - it "renders plain text passed via block" do - page = ExamplePage.new - - page.to_s.should contain("Plain!") - end end describe "#doctype" do @@ -48,17 +40,11 @@ describe "utils" do end describe "#comment" do - it "renders an html comment passed via block" do + it "renders an html comment" do page = ExamplePage.new page.to_s.should contain("") end - - it "renders an html comment passed via argument" do - page = ExamplePage.new - - page.to_s.should contain("") - end end describe "#whitespace" do @@ -70,16 +56,10 @@ describe "utils" do end describe "#unsafe_raw" do - it "renders content passed via argument without escaping" do + it "renders content without escaping" do page = ExamplePage.new page.to_s.should contain("") end - - it "renders content passed via block without escaping" do - page = ExamplePage.new - - page.to_s.should contain("
") - end end end diff --git a/src/blueprint/html/utils.cr b/src/blueprint/html/utils.cr index 6f68ad8..ec23863 100644 --- a/src/blueprint/html/utils.cr +++ b/src/blueprint/html/utils.cr @@ -1,10 +1,6 @@ module Blueprint::HTML::Utils private def plain(content : String) : Nil - plain { content } - end - - private def plain(&) : Nil - ::HTML.escape(yield, @buffer) + ::HTML.escape(content, @buffer) end private def doctype : Nil @@ -12,12 +8,8 @@ module Blueprint::HTML::Utils end private def comment(content : String) : Nil - comment { content } - end - - private def comment(&) : Nil @buffer << "" end @@ -26,10 +18,6 @@ module Blueprint::HTML::Utils end def unsafe_raw(content : String) : Nil - unsafe_raw { content } - end - - def unsafe_raw(&) : Nil - @buffer << yield + @buffer << content end end