A template engine


#1

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.

edit: now with conditionals!


#2

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?


#3

:laughing: 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! :slight_smile:


#4

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 :slight_smile:


#5

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 HashMaps for (what should be) mostly static maps, which seems unnecessary.
  • It’s Not Invented Here™.

Anyway, you should add it to all the lists! It needs to be more discoverable.