JuliaWeb / Hyperscript.jl

Hyperscript: A lightweight DOM representation for Julia
Other
101 stars 11 forks source link

Broader use of :name => "something" #5

Closed tshort closed 6 years ago

tshort commented 6 years ago

This works:

m("input"; :type => "text")

This doesn't:

m("input", :type => "text")

In the last one, it's treating the Pair as content. It'd be nice to support the second one. If it's only allowed after a semicolon, then if you use it with a node with content, it's even clunkier because the optional arguments have to come at the end:

m("div", "My content"; :type => "something")

I think it's pretty safe to intercept Pair{Symbol, T} and treat it as an argument. I can't think of a use where someone wants to fill in content with that.

yurivish commented 6 years ago

I appreciate the sentiment, but I really like the fact that Hyperscript is such a consistent mapping of Julia syntax to HTML (positional arguments are content; keyword arguments are attributes) and think it is a valuable property worth preserving.

The problem is real, though. One angle of approach that I've been thinking about is to define a higher-level syntax for more concise HTML specification, similar to Jade. You could imagine a string macro with roughly this syntax mapping onto a Hyperscript DOM tree, which would give you a clean way to express all attributes without worrying about colliding with Julia keywords.

tshort commented 6 years ago

Understood. I really like the jade/haml idea. Writing a parser is no fun, though. Maybe YAML.jl is a good starting point.