diff --git a/spec/blueprint/html/utils_spec.cr b/spec/blueprint/html/utils_spec.cr index d5315ff..fbde51c 100644 --- a/spec/blueprint/html/utils_spec.cr +++ b/spec/blueprint/html/utils_spec.cr @@ -1,5 +1,13 @@ require "../../spec_helper" +private class MarkdownLink + def initialize(@text : String, @href : String); end + + def to_s + "[#{@text}](#{@href})" + end +end + private class ExamplePage include Blueprint::HTML @@ -10,11 +18,14 @@ private class ExamplePage b "World" end + plain MarkdownLink.new("Blueprint", "blueprint.example.com") + i "Hi" whitespace plain "User" comment "This is an html comment" + comment MarkdownLink.new("Comment", "comment.example.com") div do raw safe("<script>Dangerous script</script>") @@ -29,6 +40,12 @@ describe "utils" do page.to_s.should contain("<div>Hello<b>World</b></div>") end + + it "accepts any objects that respond `#to_s`" do + page = ExamplePage.new + + page.to_s.should contain("[Blueprint](blueprint.example.com)") + end end describe "#doctype" do @@ -45,6 +62,12 @@ describe "utils" do page.to_s.should contain("<!--This is an html comment-->") end + + it "accepts any objects that respond `#to_s`" do + page = ExamplePage.new + + page.to_s.should contain("<!--[Comment](comment.example.com)-->") + end end describe "#whitespace" do diff --git a/src/blueprint/html/utils.cr b/src/blueprint/html/utils.cr index 4407019..f2eeb0c 100644 --- a/src/blueprint/html/utils.cr +++ b/src/blueprint/html/utils.cr @@ -1,5 +1,5 @@ module Blueprint::HTML::Utils - private def plain(content : String) : Nil + private def plain(content) : Nil append_to_buffer(content) end @@ -7,9 +7,9 @@ module Blueprint::HTML::Utils @buffer << "<!DOCTYPE html>" end - private def comment(content : String) : Nil + private def comment(content) : Nil @buffer << "<!--" - ::HTML.escape(content, @buffer) + append_to_buffer(content) @buffer << "-->" end