Comment by patrec 6 years ago How would you do attributes? 2 comments patrec Reply pb82 6 years ago You could use the builder pattern:Div { H1("Title") }.Attr("class", "footer") patrec 6 years ago Then you dont really end up with a DSL that looks just like the one in the article, though – this is noticeably less nice :)The best I could think off were designated initializers like: Div{{.class = "footer"}, B{"some text"}} But making tags, attributes and plain text work nearly as nicely as in the lua table example seems not super straightforward to me.
pb82 6 years ago You could use the builder pattern:Div { H1("Title") }.Attr("class", "footer") patrec 6 years ago Then you dont really end up with a DSL that looks just like the one in the article, though – this is noticeably less nice :)The best I could think off were designated initializers like: Div{{.class = "footer"}, B{"some text"}} But making tags, attributes and plain text work nearly as nicely as in the lua table example seems not super straightforward to me.
patrec 6 years ago Then you dont really end up with a DSL that looks just like the one in the article, though – this is noticeably less nice :)The best I could think off were designated initializers like: Div{{.class = "footer"}, B{"some text"}} But making tags, attributes and plain text work nearly as nicely as in the lua table example seems not super straightforward to me.
You could use the builder pattern:
Div { H1("Title") }.Attr("class", "footer")
Then you dont really end up with a DSL that looks just like the one in the article, though – this is noticeably less nice :)
The best I could think off were designated initializers like:
But making tags, attributes and plain text work nearly as nicely as in the lua table example seems not super straightforward to me.