diff --git a/spec/blueprint/html/helpers_spec.cr b/spec/blueprint/html/helpers_spec.cr index 6df5fde..b1221ec 100644 --- a/spec/blueprint/html/helpers_spec.cr +++ b/spec/blueprint/html/helpers_spec.cr @@ -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? diff --git a/src/blueprint/html/helpers.cr b/src/blueprint/html/helpers.cr index d3096c7..b06085f 100644 --- a/src/blueprint/html/helpers.cr +++ b/src/blueprint/html/helpers.cr @@ -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