the benefits:
- no allocations in the render function.
- you just pass in your own structs, instead of having to serialize it into a json-like datatype. this lets you do useful things like structural sharing.
- it's dynamic, so you can load user templates at runtime.
the drawbacks:
- i don't have any benchmarks or tests so it might actually be horribly slow, eat your laundry, or even slowly eat your laundry.
https://github.com/quadrupleslap/tenjin
edit: now with conditionals!
4 Likes
Nice work! Are there any other template engines that have been the inspiration for tenjin? At first glance, it looks a little like Django templates. Is that intentional?
Actually, I based it on Python's string formatting syntax, because it actually had a reasonable way to escape {
and }
, unlike every other syntax I could find.
Edit: I just realized that Rust's escaping and formatting syntax is pretty much the same! 
Have you looked at trimmer? It has pretty much the same goals on the rust side, but much different implementation. Also it already has conditionals 
I added conditionals yesterday! No, I didn't know about trimmer, but it looks really nice! Still, there's a couple of reasons I would've avoided it:
- It doesn't have a way to automatically escape HTML, and when injecting user content, escaping or sanitization make a lot more sense than validation.
- It still uses
HashMap
s for (what should be) mostly static maps, which seems unnecessary.
- It's Not Invented Here(TM).
Anyway, you should add it to all the lists! It needs to be more discoverable.