Skip to content

Commit

Permalink
feat: Loose #plain/#comment argument type
Browse files Browse the repository at this point in the history
  • Loading branch information
stephannv committed Oct 11, 2024
1 parent 3cbbb17 commit 84f7f86
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
23 changes: 23 additions & 0 deletions spec/blueprint/html/utils_spec.cr
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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>")
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/blueprint/html/utils.cr
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module Blueprint::HTML::Utils
private def plain(content : String) : Nil
private def plain(content) : Nil
append_to_buffer(content)
end

private def doctype : Nil
@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

Expand Down

0 comments on commit 84f7f86

Please sign in to comment.