I also wonder if Maud could benefit from the Syntex library (https://github.com/erickt/rust-syntex) which uses a fork of Rust's (currently unstable) parsing library to enable syntax extensions to work on the stable Rust release via code generation.
Very glad to see this. I've used type-safe templates in Haskell, and I've been hoping to see something similar in Rust. It looks like Maud has good defaults as well, such as escaping HTML by default.
I wonder if it would make sense to have splicing of previously created Maud values not escape them. That seems like the most common case where you'd end up using $$ otherwise: piecemeal generation of HTML fragments. Since Maud has a special type to represent the result of a template, it could recognize that type in a splice.
Also, the need to handle control structures inline (such as $if and $for) seems like it could be replaced with a mechanism to splice in arbitrary Rust code of the appropriate type. Because otherwise, Maud would need to handle things like $match.
In what way is the "Maud" name appropriate? I mean, I like it, but your comment makes me wonder if there's more to it. All I can think of is that Tennyson poem... I guess it's been described as "ironic"!
I started (and put aside) quite some times ago something with the similar approach, i.e using syntax extension but to actually write "real" html, in a template-language flavor
I first wanted it to be used with Iron, but unfortunately I lost motivation when I saw that syntax extension will not be part of 1.0 . if people are interested I can revive it.
In "basic syntax" I suggest you to move the doc about "Splices" after "Elements", since the latter it's used in the former example (or even later since it's more complex than other things).
This is a syntax extension, so it's consuming the tokens directly. It could in fact do that if it wanted to. But it appears that the grammar of the template engine treats bare identifiers as tag names, which is why it uses the nonterminal tokens $if, etc for keywords.
if you write a syntax extension, you can use if and any other rust keywords / operator / token (see the template language i started which use if directly)
The one thing I like about React's JSX "html in javascript", is that it lets you reuse all of the host language (javascript in React's case) control structures.
Otherwise Maud has to re-implement if/then/else, iterator methods, etc. But perhaps you could use 'if/then' and other structures inside a $() block.
sorry to high jack the topic, whats the big deal with Rust? I have heard it has memory safety, but are the language syntax and standard library stable?
> but are the language syntax and standard library stable?
We had a 1.0 release two weeks ago, so the syntax and almost all of the standard library is. The things that aren't are clearly marked, and aren't able to be used from a release build, so you aren't affected by their instability.
just my opinion, but at first I was mostly a C/C++ developer, I like the idea of controlling everything and not wasting memory, and the idea of being really fast as well as the idea of compile time type checking . But for a living I have to write websites/webservices etc. so most I have to use PHP etc.
So Rust is hype (let's admit it, new is always better, like your new toy for christmas) and its standard library come with enough webservices-friendly things to make it sexy to develop small webservices with it. Also it introduces a lot of interesting features (functionnal programming, immutability by default, primitives to write parallel code) in a C-syntax language that was before in some more exotic language.
I also wonder if Maud could benefit from the Syntex library (https://github.com/erickt/rust-syntex) which uses a fork of Rust's (currently unstable) parsing library to enable syntax extensions to work on the stable Rust release via code generation.