
Maud: a fast, safe template engine for Rust - aethertap
http://lfairy.gitbooks.io/maud/content/
======
kibwen
It's interesting to see how Maud's approach uses syntax extensions, in
contrast to the less-powerful (but more stable) macro-based approach that
Horrorshow uses: [https://users.rust-lang.org/t/horrorshow-a-no-longer-poc-
htm...](https://users.rust-lang.org/t/horrorshow-a-no-longer-poc-html-
template-library/1603)

I also wonder if Maud could benefit from the Syntex library
([https://github.com/erickt/rust-syntex](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.

------
JoshTriplett
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.

Props for the name and documentation as well.

~~~
pc2g4d
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"!

~~~
JoshTriplett
It doesn't necessarily match the software, but if you read the documentation,
the source of the name (and many others) should quickly become evident.

------
Animats
Oh, an _HTML_ template engine, like PHP. Not a Rust code generator, like "go
generate". The HN article title should specify that.

------
allan_s
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

[https://github.com/allan-simon/rust-http-template](https://github.com/allan-
simon/rust-http-template)

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.

------
riquito
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).

------
ufo
I wonder if there is a way to write a macro library that can use regular `if`
and `for` instead of `$if` and `$for`.

~~~
allan_s
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)

~~~
nimrody
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.

------
tmaly
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?

~~~
allan_s
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.

~~~
NaNaN
Learning Rust is just fun. The Rust book teaches me thread safety in the first
place through the ownership and borrowing system.

And I am going to see more titles about Rust with "fast and safe". But it
doesn't mean the program is stable. :P

