9 ms·
Show HN: Askama – Type-safe, compiled Jinja-like templates for Rust
- vvanders 10y agoThis looks awesome, if I'm understanding this right there's type checking with the template at compile time(I.E. if "name" in the template isn't found in the Rust struct it's a compile failure).
- dochtman 10y agoYou understood it right.
- eptcyka 10y agoI just wish rocket and diesel got the new tokio goodness, then Rust will probably replace flask in my workflow.
- d--b 10y agowow, I must have missed a generation, I have literally no idea what you're talking about.
- deleted 10y ago[deleted]
- mej10 10y agothey are rust libraries. no reason to have heard of them if you aren't learning/using rust.
- steveklabnik 10y agohttp://tokio.rs/ http://tokio.rs/ : async io https://rocket.rs/ https://rocket.rs/ : a web framework http://diesel.rs/ http://diesel.rs/ : ORM/Querybuilder
- terhechte 10y agoIsn't Rocket using Hyper, and Hyper using Tokio? It may be that Rocket is still on a non-tokio Hyper, but that'd only be temporary then.
- steveklabnik 10y agoRocket is not really using hyper. It takes one or two of its types, but implements HTTP itself. There's an ongoing discussion between all involved about it.
- Entangled 10y agoDjango/Jinja/Stencil should be the de facto standard for all templating systems so developers can port their work to any platform without sweat. Kudos for porting Jinja to Rust.
- orf 10y agoJinja yes, django not so much.
- strig 10y agoIt's essentially the same syntax
- orf 10y agoKind of but not really, Jinja let's you do a lot more. {{(x or y)|filter(z)}} for example, or even just {{function(a, b, c)}}. Django is far more restrictive in what you can put between the braces. I think one of the design goals of it was that designers with little programming knowledge could write the templates, which is a noble idea but leads to frustration as anyone who has maintained a large django app will tell you.
- benwilber0 10y agoI think part of the motivation for the limitations was to stop people from putting too much business logic in their templates. You can of course implement any kind of tag or filter you want and just use that. Or indeed just use Jinja if you want. Django's templates are perfectly fine and I still prefer them over the similar alternatives.
- orf 10y agoYeah, I understand the motivation but it doesn't help when you just want to call a model method with just a single argument. They are also dog slow :(
- 10y ago
- Entangled 10y ago> Because Askama will generate Rust code from your template files, the crate will need to be recompiled when your templates change. Being Swift a compiled language just like Rust, why can we modify the templates (Stencil, Mustache) in Swift without recompiling the app but not in Rust?
- tyoverby 10y agoDoes Mustache compile into .swift files that need to be typechecked and linked into the binary?
- orf 10y agoIs the answer not in the section you quoted?
- zacmps 10y agoAre they dynamically linked?
- zacmps 10y agoAre they dynamically linked?
- detaro 10y agoStencil and Mustache do that because they don't compile to Swift, but load and parse templates dynamically. That kind of template language implementation of course exists for Rust as well. (And the other way round, you could have a system that's like this submission for Swift, if there isn't one already)
- bajsejohannes 10y agoThere's also Bart (https://github.com/maghoff/bart https://github.com/maghoff/bart), inspired by Mustache. Like Askama, it's typesafe and compile time generated.
- maggit 10y agoHi! I'm the author of Bart. AMA :) Askama and Bart seem to be pretty similar in use (compile time, based on a struct definition) except for the template languages. Askama is rich, while Bart, like Mustache, is deliberately more restricted. ("Logicless", they would call it. I don't know how to quantify that.)