Hyperscript.jl icon indicating copy to clipboard operation
Hyperscript.jl copied to clipboard

Feature request: do-block syntax

Open schneiderfelipe opened this issue 3 years ago • 0 comments

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>

schneiderfelipe avatar May 17 '21 15:05 schneiderfelipe