-
-
Notifications
You must be signed in to change notification settings - Fork 223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: ability to render .html file updates without rebuilding? #425
Comments
There is currently not. Askama is really two things: a parser for a template language to an AST, and a code generator that transpiles the AST to Rust code. I'd be open to some other "backend" for the AST (maybe one that recasts the Askama AST as Tera AST, or some other dynamic template engine), but it's a relatively large undertaking which I probably won't prioritize in the near future unless someone wants to pay for the efforts. |
What's the use case, BTW? Just the compile time benefits, or actual "dynamic" usage, something else? Another approach could be to run the Askama-generated Rust code through a JIT compiler or interpreter at run-time, but I'm not aware of any efforts in this direction (other than Miri, but it has a very different use case). |
In short, I'm looking for a faster dev workflow, than "update .html file (askama template)", stop server, I absolutely love it that templates are compiled and you get the checks that come out of that (something that Go Templates do not have out of the box at least). But OTHO I'm seeking a more convenient way of doing Askama + Rust dev. (Context: I'm re-writing fluttercrashcourse.com, which is effectively a bespoke ecommerce application written in Vue/Nuxt + Go into Rust + actix-web + Askama. Going excellent thus far btw with Askama, and I'm even brand new to Rust). |
Fair enough. I'm not even sure the interpreting approach could work short of something that can interpret Rust -- I think it would require "flattening" context types into something easier to use dynamically. So this is definitely a bunch of work. Another approach that might work is to write templates that also work in Tera, I guess -- we would likely accept patches that would make this kind of thing easier. |
I'd definitely be up for an interpreter, to be able to dynamically render templates. However, I immediately see two issue.
So as long as a template doesn't use any Rust functions, Then it might be feasible to create interpreter. |
I don't think it makes much sense to have an interpreter if it can only handle a smallish subset of what the Askama compiler supports. |
Being able to avoid recompilation for changes only in static html content would be really nice. <div>
{% if flag %}
<div>Foobar</div>
{% endif %}
<div> to <div class="foobar">
<div>Foobar?</div>
{% if flag %}
<div class="foobarbaz">Foobar baz</div>
{% endif %}
<div> |
@seenickcode If faster development cycle is what you are after, this is how I've solved on my end:
The links to |
Wow. This is super helpful. Thank you!
…On Wed, Aug 4, 2021 at 2:31 AM Ciprian Dorin Craciun < ***@***.***> wrote:
In short, I'm looking for a faster dev workflow, than "update .html file
(askama template)", stop server, cargo build, cargo run.
@seenickcode <https://github.com/seenickcode> If faster development cycle
is what you are after, this is how I've solved on my end:
- (optional) I have a custom script (bash or whatever) that does the cargo
build and whatever is required to run the server (always exec
my-server-executable at the end to get rid of the bash process);
- I use watchexec (also available as a cargo plugin) so that when the
source code changes (not only templates) it restarts my server (by using
the previous mentioned script); (however you can use the cargo plugin
in a simple command);
- (optional) I use catflap to keep any pending HTTP requests (while
the code rebuilds and the server restarts) from erroring;
- I have a custom URL that returns a random token, one generated at
the start of the server;
- I have a custom JS snippet injected in my HTML (when in debug mode)
that checks the mentioned URL for a current token; if the observed token
changes, it reloads the current page; (the script is available at
https://github.com/console9/hyper-static-server/blob/master/sources/reload.js
)
- (optional) in order to improve build times, I keep the templates and
the logic in separate lib crates, and have a bin server crate that
just combines the two; (this should reduce the rebuild time somewhat;)
The links to watchexec and catflap:
- https://github.com/watchexec/watchexec
- https://github.com/passcod/catflap
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#425 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAASQOPSNX5AII4MGRYXRWDT3DNCNANCNFSM4VSCT66A>
.
|
See also the performance tips in the book: https://djc.github.io/askama/performance.html. Now that we've split the askama_parser crate out of askama_derive, you'd want to do the same thing for askama_parser. Note also that parsing should have gotten a bunch faster with the latest askama_derive 0.12.2 release (mainly from #833). |
Maybe this article could be helpful to get real hot reloading implemented (even without restart of the server): Edit: I'm not sure if it works when creating new templates, but it could work for editing templates. |
I understand that Askama uses compiled templates but maybe is there a way to have a debug mode that renders the template when the page is loaded?
The text was updated successfully, but these errors were encountered: