Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Oct 20 19:47
    vallentin commented #550
  • Oct 20 19:21
    couchand opened #550
  • Oct 18 22:31
    TedDriggs commented #544
  • Oct 17 13:32
    grv07 commented #544
  • Oct 17 13:32
    grv07 commented #544
  • Oct 17 13:18
    grv07 synchronize #539
  • Oct 17 13:17
    grv07 synchronize #539
  • Oct 13 15:02
    Kijewski synchronize #546
  • Oct 13 14:56
    Kijewski synchronize #541
  • Oct 13 14:47
    Kijewski closed #545
  • Oct 13 14:47
    Kijewski commented #545
  • Oct 13 14:41
    Kijewski synchronize #541
  • Oct 13 14:11
    Kijewski synchronize #541
  • Oct 13 14:09
    Kijewski synchronize #541
  • Oct 13 12:27
    djc synchronize #549
  • Oct 13 12:27

    djc on skip-non-template-attrs

    Don't parse non-template attrib… (compare)

  • Oct 13 11:59
    djc commented #548
  • Oct 13 11:59

    djc on main

    Fix support for raw method iden… Initial test work Make test name consistent with … (compare)

  • Oct 13 11:59
    djc closed #548
  • Oct 13 11:59
    djc closed #540
bbigras
@bbigras:matrix.org
[m]
It seems some whitespace bugs were fixed in the main branch. Will there be a new release soon?
rushsteve1
@rushsteve1:matrix.org
[m]
Hi, I seem to be having some trouble with the web framework integrations. For both Warp and Gotham the compiler complains that Template does not implement their respective response traits.
error[E0277]: the trait bound `templates::IndexTemplate: gotham::handler::IntoResponse` is not satisfied
  --> src/web/handlers.rs:11:24
   |
11 |         route.get("/").to(index);
   |                        ^^ the trait `gotham::handler::IntoResponse` is not implemented for `templates::IndexTemplate`
   |
   = note: required because of the requirements on the impl of `IntoHandlerFuture` for `(gotham::state::State, templates::IndexTemplate)`
   = note: required because of the requirements on the impl of `gotham::handler::Handler` for `fn(gotham::state::State) -> (gotham::state::State, templates::IndexTemplate) {handlers::index}`
rushsteve1
@rushsteve1:matrix.org
[m]
Relevant lines from my Cargo.toml
askama_gotham = "^0.11"
gotham = "^0.6.0"

[dependencies.askama]
version = "^0.10"
features = [ "with-gotham" ]
bbigras
@bbigras:matrix.org
[m]
Any way to use a trait in a template? Before switching to main I was using players: Vec<Box<dyn MyTrait + Send>>, but now I got:
move occurs because `things` has type `Vec<Box<dyn MyTrait + std::marker::Send>>`, which does not implement the `Copy` trait
rushsteve1
@rushsteve1:matrix.org
[m]
Ah, so I found out my issue: The released version of askama_gotham is on Gotham 0.5.0 not 0.6.0
Seems like this has already been fixed in the Git repo, so I'll just switch to that until it's released.
djc
@djc:mozilla.org
[m]
bbigras: can you file an issue with more context on that one, please?
2 replies
rushsteve1: feel free to create an issue to remind me to push out an askama_gotham release
1 reply
I think it’s definitely time to get a release out again
rushsteve1
@rushsteve1:matrix.org
[m]
The Warp integration was out of date too
Christian Vallentin
@vallentin
@djc:mozilla.org CI for beta channel seems to fail due to a change to either stringify! or $($tail:tt)* where given foo! then stringify!($($tail:tt)*) before would result in "foo!" and now "foo !"
Christian Vallentin
@vallentin
stringify!($($tail)*)*
Dirkjan Ochtman
@djc
thanks for looking into that!
I hadn't noticed it was the beta channel
@vallentin do you want to file a bug upstream?
Christian Vallentin
@vallentin
Sure someone else hasn't already submitted it, then yeah, I'll do it later
David Komer
@dakom

just getting started... trying to use Askama and Rocket together, I have a minimal example:

#[macro_use] extern crate rocket;

use askama::Template;
use rocket::http::{ContentType, Status};
use rocket::local::blocking::Client;

#[launch]
fn rocket() -> _ {

    let figment = rocket::Config::figment()
        .merge(("port", config::get_port()));

    rocket::custom(figment)
        .mount("/", routes![home])
}

#[derive(Template)]
#[template(path = "spa.html")]
struct SpaTemplate<'a> {
    app_js: &'a str,
}

#[get("/")]
fn home() -> SpaTemplate<'static> {
    SpaTemplate { app_js: "TODO" }
}

Which gives me this error:

error[E0277]: the trait bound `SpaTemplate<'_>: rocket::response::Responder<'_, '_>` is not satisfied
   --> crates\bin\pages\src\main.rs:26:14
    |
26  | fn home() -> SpaTemplate<'static> {
    |              ^^^^^^^^^^^^^^^^^^^^ the trait `rocket::response::Responder<'_, '_>` is not implemented for `SpaTemplate<'_>`
    |
note: required by `route::handler::<impl Outcome<rocket::Response<'o>, Status, rocket::Data<'o>>>::from`
   --> C:\Users\david\.cargo\registry\src\github.com-1ecc6299db9ec823\rocket-0.5.0-rc.1\src\route\handler.rs:188:5
    |
188 |     pub fn from<R: Responder<'r, 'o>>(req: &'r Request<'_>, responder: R) -> Outcome<'r> {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
my Cargo.toml includes:
askama = { version = "0.10.5", default-features = false, features = ["with-rocket", "mime", "mime_guess"] }
askama_rocket = "0.10.0"
any help is appreciated, thanks!
David Komer
@dakom
(I also tried leaving default-features = false out)
David Komer
@dakom
ended up just calling .to_string() and wrapping in Html() for now..
djc
@djc:mozilla.org
[m]
What versions of Askama and Rocket are you using? If it’s Rocket 0.5, askama_rocket 0.10 doesn’t work with that
David Komer
@dakom
yeah, rocket 0.5
djc
@djc:mozilla.org
[m]
You’ll need the askama_rocket pre-release
restioson
@restioson:breadpirates.chat
[m]

is this a bug with askama main branch latest rev?

{%- match previous_success -%}
{%- when Some with (true) -%}
     True!
{%- when other -%}
    It is other!
{%- endmatch -%}

is emitting

        match &self.previous_success {
            Some(r#true,) => {
                writer.write_str("True!")?;
            }
            other => {
                writer.write_str("It is other!")?;
            }
        }

instead ofSome(true) (which it used to emit on 0.10.5), it's got Some(r#true)

which is of course problematic since it isn't actually matching against Some(true) anymore, but any Some(_) option
restioson
@restioson:breadpirates.chat
[m]
Bisection: as of djc/askama@1622df7 it still emits Some(true), but as of djc/askama@268d825 (the very next commit) it emits r#true
apologies if this already a known issue
restioson
@restioson:breadpirates.chat
[m]
test case that I can PR if wanted Restioson/askama@02b16ac
djc
@djc:mozilla.org
[m]
yes, please
can you cc the PR author?
nice find!
restioson
@restioson:breadpirates.chat
[m]
Sure
djc/askama#531 is this alright? anything I should add/edit?
restioson
@restioson:breadpirates.chat
[m]
is there a way to display one str or item as unescaped, where everything else is escaped by default?
restioson
@restioson:breadpirates.chat
[m]
I see there is safe. Next question is whether it's possible to make a custom filter that returns unescaped text?
restioson
@restioson:breadpirates.chat
[m]

for reference i am trying

pub fn html<'a, T: DisplayHtml + 'a>(v: T) -> askama::Result<MarkupDisplay<Html, DisplayHtmlWrapper<'a, T>>> {
    let w = DisplayHtmlWrapper {
        val: OwnedOrBorrowed::Owned(v),
        plain_text: false
    };

    Ok(MarkupDisplay::new_safe(w, Html))
}

which seems should work given the definition of safe:

pub fn safe<E, T>(e: E, v: T) -> Result<MarkupDisplay<E, T>>
where
    E: Escaper,
    T: fmt::Display,
{
    Ok(MarkupDisplay::new_safe(v, e))
}

but it doesn't work, and instead escapes the content. however if i first construct the DisplayHtmlWrapper type with this method

fn to_html(&self) -> DisplayHtmlWrapper<Self>
where
    Self: Sized,
{
    DisplayHtmlWrapper {
        val: OwnedOrBorrowed::Borrowed(self),
        plain_text: false,
    }
}

(which is equivalent)
and then do {{ val.to_html()|safe }} in the template instead of {{ val|html }}, it is unescaped correctly

djc
@djc:mozilla.org
[m]
Please a file a bug with a full reproducer
restioson
@restioson:breadpirates.chat
[m]
okay, i will do so when i have a chance. i was unsure whether this was intended behaviour or not
simanacci
@simanacci
#[derive(Template)]
#[template(path = "control/language.html")]
pub struct LanguageTemplate<'a> {
    pub signup: &'a str,
    pub errors: &'a HashMap<&'a str, Option<String>>,
}

let body = LanguageTemplate { signup: "Sign Up", errors: &errors }.render().unwrap();
11 | #[derive(Template)]
   |          ^^^^^^^^ `HashMap<&str, std::option::Option<std::string::String>>` cannot be formatted with the default formatter
   | 
  ::: /home/roy/.cargo/registry/src/github.com-1ecc6299db9ec823/askama_escape-0.10.1/src/lib.rs:7:8
   |
7  |     T: Display,
   |        ------- required by this bound in `MarkupDisplay`
Hi, How can I pass a HashMap to the template?
I want to render form errors from the errors HashMap.
Christian Vallentin
@vallentin
@simanacci can you share your template code? The issue sounds more like a problem in relation to how you're attempting to use errors
simanacci
@simanacci
{% if errors.contains_key("name") and errors["name"].is_some() %}
    <span>{{ errors["name"].as_ref().unwrap() }}</span>
{% endif%}
simanacci
@simanacci
@vallentin I've switched to this.
#[derive(Template)]
#[template(path = "control/language.html")]
pub struct LanguageTemplate<'a> {
    pub signup: &'a str,
    pub name_error: Option<String>,

let body = LanguageTemplate { signup: "Sign Up", name_error: name_error.clone() }.render().unwrap();
}
I keep getting stuck with ownership errors when trying to use a HashMap.
Alice Carroll
@iamalicecarroll
how would i use askama with actix 4.0.0-beta.9?
Dirkjan Ochtman
@djc
start here: djc/askama#485