This time I started to do it for real and I restarted from scratch the Rust rewrite of my website (as a "real" Rust beginner project) and this time I'm using Askama for the templating stuff.

(And It's new repo is right here: https://codeberg.org/Breadly/blair )

#Rust #Askama

Rust バックエンドで htmx を使ってみた - Qiita

htmx とは htmx は「HTML中心で動くフロントエンド」を実現するための軽量な JavaScript ライブラリです。 React / Vue などのフロントエンドフレームワークとは異なり、 バックエンドからは JSON ではなく HTML を受け取り、DO...

Qiita

Since we're talking about responses let’s address the elephant in the room: HTML.

In Ruby pretty much every framework support some form of templating. Even barebones Sinatra gives you ERB out of the box and pretty much any other template engine is only one line in the gemfile away.

Axum doesn't provide any templating. You’ll have to bring your own.

I picked #Askama as it was the first templating engine on Are We Web Yet.

It's a dialect of Jinja. But maybe not 100% compatible. No matter.

One thing you learn fast is that in Rust everything is a type. So your template has to have an actual template and a struct that provides data for the template. You can't just put random code in your templates. On one hand it’s great as you can't by accident have n+1 queries in your template. On the other, to change something on the page you might to edit three files: the actual template, the struct for the template, and the handler to populate the struct.

There's no support for layouts. Well, there's kinda. Through template inheritance. It’s where you extend your layout by overriding some blocks in it. It's much more awkward than in Ruby. In Ruby layouts are conceptually separate. In Askama your template struct has to provide all the data for the template and all its parent templates. I don't even know if it's possible to render the same template in different layouts. The thing that is extremely easy in Ruby.

There's also no support for partials. At best you can insert renders of other templates. But that's awkward for many of the same reasons (mostly around providing data for the templates).

One major downside is that Askama uses proc macro to compile the templates to Rust. It makes it extremely fast but debugging templates is a nightmare. It gives you an error that something is missing or has a wrong type but doesn't tell you what it is or where in the template it is. Even with enabled proc macro backtraces it gives you a snippet of generated Rust code and not the template. Even the barebones ERB will give you the exact position in the template in case of an error.

So yeah, lots of frustration.

#Axum #Ruby #RubyOnRails #Rust

yay i finished rewriting my website from #sveltekit to #Rust with #askama

 live on https://vavakado.xyz!!!! 

old ​version available on: https://old.vavakado.xyz  if anyone wants to test perf or smth (don't DDOS me pls)

#programming #webdev

vavakado's home

I'm trying to write a not so complicated form with #rustlang #askama and #htmx and I'm having a brain fart: at this point I don't even know if I'm fighting askama or htmx 😂 and I don't know where I can ask a question at the intersection of these two kinda "fringe" technologies... 😬 (nothing wrong with either of them, it's a me problem)
Switched all my templates to Askama tonight because I made this stupid mistake on my résumé where I wasn't including the company name or educational institution — job history and education use the same underlying struct. I had renamed the field but not in the template. Anyhow I won't make that mistake again. And bonus, my compile times seem to be faster and my docker image smaller. #rustlang #askama
@mo8it especially, compile time checks of variables used in the #html templates. #askama #rust
@mo8it @khalidabuhakmeh@mastodon. Just tinkered with #askama, #axum and #htmx while being sick at home. On the first impression askama works well for me.

I have two askama templates one is main another is a partial of main.

html in main = own html + include partial.

Currently I have two structs each for main and partial.

When page is displayed it uses main and on ajax updates it uses partial.

Both structs being identical with fields how can I remove duplication?

#rust #rustlang #axum #askama

@daubers Perhaps #Askama may be what you're looking for https://github.com/djc/askama
GitHub - djc/askama: Type-safe, compiled Jinja-like templates for Rust

Type-safe, compiled Jinja-like templates for Rust. Contribute to djc/askama development by creating an account on GitHub.

GitHub