Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Nov 29 00:58
    alakhpc closed #749
  • Nov 29 00:58
    alakhpc commented #749
  • Nov 28 22:45
    Ummon opened #752
  • Nov 28 09:03
    djc commented #749
  • Nov 28 08:21

    dependabot[bot] on cargo

    (compare)

  • Nov 28 08:21
    dependabot[bot] closed #751
  • Nov 28 08:21
    dependabot[bot] edited #751
  • Nov 28 08:21

    dependabot[bot] on cargo

    (compare)

  • Nov 28 08:21
    dependabot[bot] commented #751
  • Nov 28 08:21
    dependabot[bot] closed #750
  • Nov 28 08:21
    dependabot[bot] edited #750
  • Nov 28 08:21
    dependabot[bot] commented #750
  • Nov 28 08:21
    dependabot[bot] edited #751
  • Nov 28 08:21
    dependabot[bot] edited #750
  • Nov 28 08:21
    djc commented #716
  • Nov 28 08:21

    djc on main

    Upgrade axum-core to 0.3 (compare)

  • Nov 28 08:21
    djc closed #716
  • Nov 28 04:06
    dependabot[bot] labeled #751
  • Nov 28 04:06
    dependabot[bot] opened #751
  • Nov 28 04:06

    dependabot[bot] on cargo

    Update axum-core requirement fr… (compare)

Andrew Wheeler(Genusis)
@genusistimelord
{% match account_validated %}
{% when Some with (true) %}
<span>Votre compte est désormais actif ! Vous pouvez à présent vous connecter 🙂</span>
{% when None %}
<span class="text-danger">Veuillez activer votre compte</span>
{% endmatch %}
Rustre
@rustre-undefined
Thank you very much for you help 🙏
Andrew Wheeler(Genusis)
@genusistimelord
{% match account_validated %}
{% when Some with (true) %}
<span>Votre compte est désormais actif ! Vous pouvez à présent vous connecter 🙂</span>
{% when Some with (false) %}
<span class="text-danger">Veuillez activer votre compte</span>
{% when None %}
{% endmatch %}
sorry its more like this
since none implys no bool
Rustre
@rustre-undefined
Yes I have done the same things of your last purpose 😁
Again thank you 🙏
Andrew Wheeler(Genusis)
@genusistimelord
there are a lot of examples in https://github.com/djc/askama/tree/main/testing
Rustre
@rustre-undefined
The book isn't update? I referer to the book to see what I can do with the template engine
Andrew Wheeler(Genusis)
@genusistimelord
it doesn't contain everything possible.
like for example you can use public functions and closures within the templates
if you want more examples of things i have a few in my test repo
Rustre
@rustre-undefined
Okay I will see in future inside of these repository thank you :)
Have a good day!
Andrew Wheeler(Genusis)
@genusistimelord
you as well
simanacci
@simanacci
Is it possible to escape this :point_right: <a class="one-linesearch-result" onclick='getSelectedItem(null, "location", {{ result["name"] }});'>? VS highlight such as errors. I tried using \" but it turned to a string instead?
simanacci
@simanacci
mikoto
@mikoto:nltrix.net
[m]
      {% if input.name.len() == 0 %}
        {% input.name = "Anonymous" %}
      {% endif %}
      <input type="text" value="{{ input.name }}" name="name" size="24" maxlength="100"/>
is this valid? or do I need an else clause?
djc
@djc:mozilla.org
[m]
Should be valid
Although you should be using is_empty() instead of len() == 0, of course 😊
Ah sorry
You cannot assign to input.name
1 reply
mikoto
@mikoto:nltrix.net
[m]
do I create a new askama variable?
Marek Janda
@mjanda

Hello,
would someone be able to nudge me in the right direction? When upgrading to rocket 0.5-rc2, I ran into this issue. If I try to respond from one of my endpoints with rocket::Response, I get this error:

#[get("/test")]
pub fn test<'a>() -> Response<'a> {
    unimplemented!()
}
error: src/handlers/activity/handlers.rs:20: the trait bound `rocket::Response<'_>: askama_rocket::Responder<'_, '_>` is not satisfied
error: src/handlers/activity/handlers.rs:20: the trait `askama_rocket::Responder<'_, '_>` is not implemented for `rocket::Response<'_>`
help: src/handlers/activity/handlers.rs:20: the following other types implement trait `askama_rocket::Responder<'r, 'o>`:
  <&'o [u8] as askama_rocket::Responder<'r, 'o>>
  <&'o str as askama_rocket::Responder<'r, 'o>>
  <() as askama_rocket::Responder<'r, 'static>>
  <(rocket::http::ContentType, R) as askama_rocket::Responder<'r, 'o>>
  <(rocket::http::Status, R) as askama_rocket::Responder<'r, 'o>>
  <AuthTemplate<'a> as askama_rocket::Responder<'askama, 'askama>>
  <ByteStream<S> as askama_rocket::Responder<'r, 'r>>
  <Capped<T> as askama_rocket::Responder<'r, 'o>>
and 123 others

What I don't understand is why it's referring to askama_rocket::Responder when I'm not responding with askama::Template on this endpoint.

I'm using askama 5cdffd6e0e9eb0a408cec6e5a143231e139970fe

Marek Janda
@mjanda
Ok, I solved my problem by implementing askama_rocket::Responder on my wrapper type over rocket::Response and it works...but I still don't understand why this happens.
Dirkjan Ochtman
@djc
sorry, this is not enough information for me to see why that happens
I would guess a version mismatch somewhere?
or type inference getting confused
ScratchX
@scratch_x:matrix.org
[m]
So this is less of an askama question but more of a general webdev one, so say I'm using my askama html template files, and I have almost all my logic in the back-end. However what if I need just a little bit of interactivity on my front-end? say making a light/dark mode or popup or something like that: this means having to use at least a bit of JS or wasm, how do you manage this? So I guess you could just have some script tags and have a little vanilla JS logic but what if I want to use a framework to make things easier? You can't use something like Vue or React because they have their own structure incompatible with askama templates right? Is using a small framework like AlpineJS and importing it everywhere in script tags the way to go? Is there also a rust/wasm solution out there to not have to touch JS?
I know there are some tools to integrate big backend frameworks with big frontend frameworks like inertia but is there no other way?
2 replies
djc
@djc:mozilla.org
[m]
I’m not that familiar with the modern frontend frameworks
It has always been a goal to have Askama eventually be able to generate some kind of virtual DOM that you can interact with in a functional-reactive kind of way, but I haven’t gotten there
mismo
@mismo:matrix.org
[m]
Yeah sorry, I just noticed I didn't read your message to the end.
There are definitely frameworks in rust that support client side rendering, for example https://yew.rs/
ScratchX
@scratch_x:matrix.org
[m]
Yeah I need server side rendering (currently using rocket) and something minimal for that little bit of necessary front-end logic
mismo
@mismo:matrix.org
[m]

If we're talking about a production use case more than a research project I'd go with a js-based solution. There's lots of them besides alpine, e.G. stencil and svelte which can both compile to web components which is great for interop or preact for low network overhead. react is probably kinda heavy for this use case.

The problem with rust is that it's kinda hard to get small binary sizes out of it, I guess (no expert though) that that's why there's so little progress being made in the field. There are also very little options for code splitting with wasm and web-sys and js-sys are kind of painful to use :)

2 replies
ScratchX
@scratch_x:matrix.org
[m]
ty for sharing
ScratchX
@scratch_x:matrix.org
[m]
Either way this is really interesting, seems like there is a niche that could be filled. An AlpineJS-like rust/wasm library. So basically not a full on framework like yew but not just js functions either, something to make adding interactivity to single html pages easier.
Dirkjan Ochtman
@djc
I think performance will become more interesting when WASM can refer to DOM types directly instead of going through JS
mismo
@mismo:matrix.org
[m]
stdweb is deprecated and unmaintained as far as I know, web-sys is the current standard. as djc says js will probably be faster for almost any use case when doing dom manipulation.
now I'm actually here with a question 😁
I've got this
use askama_rocket::Template;

#[derive(Template)]
#[template(path = "routes/auth/sign_in/index.html")]
struct PageTemplate;

#[get("/auth/sign-in")]
pub(crate) fn page() -> PageTemplate {
    PageTemplate
}
And I get this error: error[E0277]: the trait boundPageTemplate: rocket::response::Responder<', '>is not satisfied

dependencies are

askama_rocket = { version = "0.11" }
askama = { version = "0.11", features = ["with-rocket"] }

where am I going wrong? as far as I understand this askama_rocket::Template should automatically implement Responder, right?

mismo
@mismo:matrix.org
[m]
I've tried various permutations of the dependency-versions, importing Template from askama or askama_rocket etc
Dirkjan Ochtman
@djc
you shouldn't be depending on askama at all
4 replies
are you sure you're using the same version of Rocket as the askama_rocket version you're pulling in?
1 reply
Stanislav Leonchik
@stanislavleonchik

Hello there.
The system at the input has a file with the layout of the document in latex format with additional syntax of the template engine, a file with data in json format.
The template engine processes the template file, enriches it with data from the json file and outputs a clean, correct file in latex format.

#[derive(Template)] 
#[template(path = "template.tex")]
struct HelloTemplate<'a> {
    name: &'a str, 
}
let mut stream = File::open(fn_json).unwrap();
    let mut data = String::new();
    stream.read_to_string(&mut data).unwrap();
    let data: serde_json::Value =
        serde_json::from_str(&*data).expect("JSON was not well-formatted");
    println!("{}", data);

    let hello = HelloTemplate { name: "world" };
    println!("{}", hello.render().unwrap());
error: length of delimiters must be two
  --> src/main.rs:17:10
   |
17 | #[derive(Template)] // this will generate the code...
   |          ^^^^^^^^
   |
   = note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info)

And i tried to edit askama-derive
But got the same error

1 reply
djc
@djc:mozilla.org
[m]
I couldn’t extract an actual question from this
zachel
@zachel:fairydust.space
[m]
What's the correct usage for the filter linebreaksbr?
Just putting {{ val|linebreaksbr }} inside <p> gives me filtered result wrapped in string, instead of the html element.