Skip to content

Feature request: do-block syntax #32

@schneiderfelipe

Description

@schneiderfelipe

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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions