mirror of
https://github.com/askama-rs/askama.git
synced 2025-09-30 06:21:13 +00:00

This is relatively major change to the main trait's API. For context, I always started from the concept of monomorphized traits, but later several contributors asked about object safety. At that point I made `Template` object-safe, and then even later added a `SizedTemplate` to make some things easier for people who don't need object safety. However, having object-safety in the primary trait is bad for performance (a substantial number of calls into the virtual `Write` trait is relatively slow), and I don't think those who don't need object safety should pay for the cost of having it. Additionally, I feel using associated consts for the extension and size hint is more idiomatic than having accessor methods. I don't know why I didn't use these from the start -- maybe associated consts didn't exist yet, or I didn't yet know how/when to use them. Askama is pretty old at this point...
68 lines
1.6 KiB
Rust
68 lines
1.6 KiB
Rust
use askama::Template;
|
|
|
|
#[derive(Template)]
|
|
#[template(path = "foo.html")]
|
|
struct PathHtml;
|
|
|
|
#[test]
|
|
fn test_path_ext_html() {
|
|
let t = PathHtml;
|
|
assert_eq!(t.render().unwrap(), "foo.html");
|
|
assert_eq!(PathHtml::EXTENSION, Some("html"));
|
|
}
|
|
|
|
#[derive(Template)]
|
|
#[template(path = "foo.jinja")]
|
|
struct PathJinja;
|
|
|
|
#[test]
|
|
fn test_path_ext_jinja() {
|
|
let t = PathJinja;
|
|
assert_eq!(t.render().unwrap(), "foo.jinja");
|
|
assert_eq!(PathJinja::EXTENSION, Some("jinja"));
|
|
}
|
|
|
|
#[derive(Template)]
|
|
#[template(path = "foo.html.jinja")]
|
|
struct PathHtmlJinja;
|
|
|
|
#[test]
|
|
fn test_path_ext_html_jinja() {
|
|
let t = PathHtmlJinja;
|
|
assert_eq!(t.render().unwrap(), "foo.html.jinja");
|
|
assert_eq!(PathHtmlJinja::EXTENSION, Some("html"));
|
|
}
|
|
|
|
#[derive(Template)]
|
|
#[template(path = "foo.html", ext = "txt")]
|
|
struct PathHtmlAndExtTxt;
|
|
|
|
#[test]
|
|
fn test_path_ext_html_and_ext_txt() {
|
|
let t = PathHtmlAndExtTxt;
|
|
assert_eq!(t.render().unwrap(), "foo.html");
|
|
assert_eq!(PathHtmlAndExtTxt::EXTENSION, Some("txt"));
|
|
}
|
|
|
|
#[derive(Template)]
|
|
#[template(path = "foo.jinja", ext = "txt")]
|
|
struct PathJinjaAndExtTxt;
|
|
|
|
#[test]
|
|
fn test_path_ext_jinja_and_ext_txt() {
|
|
let t = PathJinjaAndExtTxt;
|
|
assert_eq!(t.render().unwrap(), "foo.jinja");
|
|
assert_eq!(PathJinjaAndExtTxt::EXTENSION, Some("txt"));
|
|
}
|
|
|
|
#[derive(Template)]
|
|
#[template(path = "foo.html.jinja", ext = "txt")]
|
|
struct PathHtmlJinjaAndExtTxt;
|
|
|
|
#[test]
|
|
fn test_path_ext_html_jinja_and_ext_txt() {
|
|
let t = PathHtmlJinjaAndExtTxt;
|
|
assert_eq!(t.render().unwrap(), "foo.html.jinja");
|
|
assert_eq!(PathHtmlJinjaAndExtTxt::EXTENSION, Some("txt"));
|
|
}
|