aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Yusuke Sasaki <yusuke.sasaki.nuem@gmail.com>2018-10-11 03:14:27 +0900
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2018-10-12 14:18:12 +0200
commit1f11e7133de188bc5a83ff4b8462c69cf1c19174 (patch)
treeea2638eb408ee3095d4639fedb15a561cbad32b9
parent2e0f7fb4978297a3e82b319ea9027cf65d1a7d49 (diff)
downloadaskama-1f11e7133de188bc5a83ff4b8462c69cf1c19174.tar.gz
askama-1f11e7133de188bc5a83ff4b8462c69cf1c19174.tar.bz2
askama-1f11e7133de188bc5a83ff4b8462c69cf1c19174.zip
make `Template::extension()` static
It is useful for calculating the media type without instantiating the context value.
Diffstat (limited to '')
-rw-r--r--askama/src/lib.rs9
-rw-r--r--askama_derive/src/generator.rs2
-rw-r--r--testing/tests/simple.rs2
3 files changed, 9 insertions, 4 deletions
diff --git a/askama/src/lib.rs b/askama/src/lib.rs
index 0c0ff83..187b571 100644
--- a/askama/src/lib.rs
+++ b/askama/src/lib.rs
@@ -395,8 +395,13 @@ pub trait Template {
}
/// Renders the template to the given `writer` buffer
fn render_into(&self, writer: &mut std::fmt::Write) -> Result<()>;
- /// Helper method to inspect the template's extension
- fn extension(&self) -> Option<&str>;
+ /// Helper function to inspect the template's extension
+ fn extension() -> Option<&'static str>
+ where
+ Self: Sized,
+ {
+ None
+ }
}
pub use askama_derive::*;
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs
index 2c9fddb..4f83b07 100644
--- a/askama_derive/src/generator.rs
+++ b/askama_derive/src/generator.rs
@@ -107,7 +107,7 @@ impl<'a> Generator<'a> {
buf.writeln("Ok(())");
buf.writeln("}");
- buf.writeln("fn extension(&self) -> Option<&str> {");
+ buf.writeln("fn extension() -> Option<&'static str> {");
buf.writeln(&format!(
"{:?}",
self.input.path.extension().map(|s| s.to_str().unwrap())
diff --git a/testing/tests/simple.rs b/testing/tests/simple.rs
index 9575daa..e19b32e 100644
--- a/testing/tests/simple.rs
+++ b/testing/tests/simple.rs
@@ -27,7 +27,7 @@ fn test_variables() {
Iñtërnâtiônàlizætiøn is important\n\
in vars too: Iñtërnâtiônàlizætiøn"
);
- assert_eq!(s.extension(), Some("html"));
+ assert_eq!(VariablesTemplate::extension(), Some("html"));
}
#[derive(Template)]