From 247b193d002de3ec0898088cd3e7b6ba679f0d9c Mon Sep 17 00:00:00 2001 From: hhaensel Date: Thu, 28 Mar 2024 20:23:51 +0100 Subject: [PATCH 1/2] add `@slot` macro --- src/Elements.jl | 61 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/src/Elements.jl b/src/Elements.jl index 2ae22c79..f3e79b62 100644 --- a/src/Elements.jl +++ b/src/Elements.jl @@ -11,7 +11,7 @@ using MacroTools import Genie.Renderer.Html: HTMLString, normal_element -export root, elem, vm, @if, @else, @elseif, @for, @text, @bind, @data, @on, @click, @showif +export root, elem, vm, @if, @else, @elseif, @for, @text, @bind, @data, @on, @click, @showif, @slot export stylesheet, kw_to_str # deprecated @@ -429,6 +429,65 @@ macro showif(expr) Expr(:kw, Symbol("v-show"), esc_expr(expr)) end + +""" + hyphenate(expr) + +Convert minus operations in expressions into join-operations with '-' + +### Example +```julia +julia> :(a-b-c) |> hyphenate +Symbol("a-b-c") +``` +""" +function hyphenate(@nospecialize expr) + if expr isa Expr && expr.head == :call && expr.args[1] == :- + x = expr.args[2] + Symbol(x isa Expr ? hyphenate(x) : x isa QuoteNode ? x.value : x, '-', join(expr.args[3:end], '-')) + else + expr + end +end + +hyphenate(expr...) = hyphenate.(expr) + +""" + @slot(slotname) + +Add a v-slot attribute to a template. + +### Example + +```julia +julia> template(@slot(:header), [cell("Header")]) +"" +``` +""" +macro slot(slotname) + slotname isa Expr && (slotname = hyphenate(slotname)) + slotname isa QuoteNode && (slotname = slotname.value) + Expr(:kw, Symbol("v-slot:$slotname"), "") |> esc +end + +""" + @slot(slotname, varname) + +Add a v-slot attribute with a variable name to a template. + +### Example + +```julia +julia> template(@slot(:body, :props), ["{{ props.value }}"]) +"" +``` +""" +macro slot(slotname, varname) + slotname isa Expr && (slotname = hyphenate(slotname)) + slotname isa QuoteNode && (slotname = slotname.value) + Expr(:kw, Symbol("v-slot:$slotname"), varname) |> esc +end + #===# """ From 2756697fc195d730107cf8186e41d1bb99978a17 Mon Sep 17 00:00:00 2001 From: hhaensel Date: Thu, 28 Mar 2024 20:24:41 +0100 Subject: [PATCH 2/2] set version v0.28.7 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 68773c49..8af5cc14 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Stipple" uuid = "4acbeb90-81a0-11ea-1966-bdaff8155998" authors = ["Adrian "] -version = "0.28.6" +version = "0.28.7" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"