Skip to content

Commit

Permalink
feat: Remove #tokens helper
Browse files Browse the repository at this point in the history
  • Loading branch information
stephannv committed Oct 19, 2024
1 parent 83d4c90 commit efd8e89
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 49 deletions.
44 changes: 7 additions & 37 deletions spec/blueprint/html/helpers_spec.cr
Original file line number Diff line number Diff line change
@@ -1,44 +1,14 @@
require "../../spec_helper"

private class ExamplePage
include Blueprint::HTML

private def blueprint
div("Tokens", class: ["a", "b", tokens(c?: "c", d?: "d", e?: "e")])

div(onclick: safe("<script>Attribute script</script>")) { safe("<script>Good Script</script>") }

span safe("<script>Another Good Script</script>")
end

private def c?
true
end

private def d?
false
end

private def e?
true
end
end

describe "helpers" do
describe "#tokens" do
it "returns conditional classes" do
page = ExamplePage.new
expected_html = normalize_html <<-HTML
<div class="a b c e">Tokens</div>
HTML

page.to_s.should contain expected_html
end
end

describe "#safe" do
it "returns an object that Blueprint will understand as safe to render without escaping" do
page = ExamplePage.new
actual_html = Blueprint::HTML.build do
div(onclick: safe("<script>Attribute script</script>")) { safe("<script>Good Script</script>") }

span safe("<script>Another Good Script</script>")
end

expected_html = normalize_html <<-HTML
<div onclick="<script>Attribute script</script>">
<script>Good Script</script>
Expand All @@ -49,7 +19,7 @@ describe "helpers" do
</span>
HTML

page.to_s.should contain expected_html
actual_html.should eq expected_html
end
end

Expand Down
12 changes: 0 additions & 12 deletions src/blueprint/html/helpers.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,4 @@ module Blueprint::HTML::Helpers
private def escape_once(value) : SafeValue
escape_once(value.to_s)
end

@[Experimental]
macro tokens(**conditions)
String.build do |io|
{% for key, value in conditions %}
if {{key.id}}
io << " " unless io.empty?
io << {{value}}
end
{% end %}
end
end
end

0 comments on commit efd8e89

Please sign in to comment.