Hyperscript.jl
Hyperscript.jl copied to clipboard
Feature request: do-block syntax
Hi @yurivish, how do you feel about adding a do-block syntax (similar to markaby)? That would allow one to write the following:
using Hyperscript
@tags div em a
# What I'm proposing:
div.header() do
a(href="https://github.com/yurivish/Hyperscript.jl") do
em("Hyperscript.jl")
end
end
instead of
# Current equivalent:
div.header(a(href="https://github.com/yurivish/Hyperscript.jl", em("Hyperscript.jl")))
or, equivalently,
# Indented current equivalent:
div.header(
a(href="https://github.com/yurivish/Hyperscript.jl",
em("Hyperscript.jl")
)
)
That could increase readability in general. Of course, nothing would break; it would only be an alternative way of writing things.
If you like it, I could make a PR 😀
EDIT: a single line is all that's required to make the example above work:
julia> (x::Hyperscript.Node)(f::Function, args...; props...) = x(args..., f(); props...)
julia> div.header() do
a(href="https://github.com/yurivish/Hyperscript.jl") do
em("Hyperscript.jl")
end
end
<div class="header"><a href="https://github.com/yurivish/Hyperscript.jl"><em>Hyperscript.jl</em></a></div>