Skip to content

Commit

Permalink
feat: Improve #tokens method (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephannv authored Sep 12, 2024
1 parent 0f9a705 commit eff2d9b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion spec/blueprint/html/helpers_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ private class ExamplePage
include Blueprint::HTML

private def blueprint
div("Tokens", class: ["a", "b", tokens({->c? => "c", ->d? => "d", ->e? => "e"})])
div("Tokens", class: ["a", "b", tokens(c?: "c", d?: "d", e?: "e")])
end

private def c?
Expand Down
10 changes: 5 additions & 5 deletions src/blueprint/html/helpers.cr
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module Blueprint::HTML::Helpers
def tokens(conditions : Hash(Proc(Bool), String)) : String
macro tokens(**conditions)
String.build do |io|
conditions.each do |proc, classes|
if proc.call
{% for key, value in conditions %}
if {{key.id}}
io << " " unless io.empty?
io << classes
io << {{value}}
end
end
{% end %}
end
end
end

0 comments on commit eff2d9b

Please sign in to comment.