Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
hhaensel committed Mar 29, 2024
2 parents b031276 + 2756697 commit a820ca8
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Stipple"
uuid = "4acbeb90-81a0-11ea-1966-bdaff8155998"
authors = ["Adrian <[email protected]>"]
version = "0.28.6"
version = "0.28.7"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
61 changes: 60 additions & 1 deletion src/Elements.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")])
"<template v-slot:header><div class=\"st-col col\">Header</div></template>"
```
"""
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 }}"])
"<template v-slot:body=\"props\">{{ props.value }}</template>"
```
"""
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

#===#

"""
Expand Down

2 comments on commit a820ca8

@hhaensel
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/104105

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.28.7 -m "<description of version>" a820ca85b79c75f6ac182c099e7818e07fb6e0da
git push origin v0.28.7

Please sign in to comment.