diff options
author | René Kijewski <kijewski@library.vetmed.fu-berlin.de> | 2022-07-20 15:38:30 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2022-07-25 11:41:04 +0200 |
commit | 16a37f409776775341c5de8a8812eaeb8b1fe7f0 (patch) | |
tree | ea72b3a26ceb2c460742a251f4b92678fbc4f1e5 /testing/tests | |
parent | bd8d2f334ed2a9fd0fb1bb6f9d87b4ab45556918 (diff) | |
download | askama-16a37f409776775341c5de8a8812eaeb8b1fe7f0.tar.gz askama-16a37f409776775341c5de8a8812eaeb8b1fe7f0.tar.bz2 askama-16a37f409776775341c5de8a8812eaeb8b1fe7f0.zip |
Remove support for deprecated `_parent` field
The support for the magic `_parent` field is deprecated since v0.8.0
or issue #180. It's bothersome to keep this feature alive, when no-one
should be using it for 3 years.
Diffstat (limited to '')
-rw-r--r-- | testing/tests/inheritance.rs | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/testing/tests/inheritance.rs b/testing/tests/inheritance.rs index 2dac362..5d8aefb 100644 --- a/testing/tests/inheritance.rs +++ b/testing/tests/inheritance.rs @@ -1,3 +1,5 @@ +use std::ops::Deref; + use askama::Template; #[derive(Template)] @@ -9,7 +11,15 @@ struct BaseTemplate<'a> { #[derive(Template)] #[template(path = "child.html")] struct ChildTemplate<'a> { - _parent: BaseTemplate<'a>, + _parent: &'a BaseTemplate<'a>, +} + +impl<'a> Deref for ChildTemplate<'a> { + type Target = BaseTemplate<'a>; + + fn deref(&self) -> &Self::Target { + self._parent + } } #[test] @@ -21,7 +31,7 @@ fn test_use_base_directly() { #[test] fn test_simple_extends() { let t = ChildTemplate { - _parent: BaseTemplate { title: "Bar" }, + _parent: &BaseTemplate { title: "Bar" }, }; assert_eq!( t.render().unwrap(), @@ -43,6 +53,7 @@ fn test_empty_child() { pub mod parent { use askama::Template; + #[derive(Template)] #[template(path = "base.html")] pub struct BaseTemplate<'a> { @@ -53,17 +64,26 @@ pub mod parent { pub mod child { use super::parent::*; use askama::Template; + #[derive(Template)] #[template(path = "child.html")] pub struct ChildTemplate<'a> { - pub _parent: BaseTemplate<'a>, + pub _parent: &'a BaseTemplate<'a>, + } + + impl<'a> std::ops::Deref for ChildTemplate<'a> { + type Target = BaseTemplate<'a>; + + fn deref(&self) -> &Self::Target { + self._parent + } } } #[test] fn test_different_module() { let t = child::ChildTemplate { - _parent: parent::BaseTemplate { title: "a" }, + _parent: &parent::BaseTemplate { title: "a" }, }; assert_eq!( t.render().unwrap(), @@ -81,6 +101,14 @@ struct NestedChildTemplate { _parent: NestedBaseTemplate, } +impl Deref for NestedChildTemplate { + type Target = NestedBaseTemplate; + + fn deref(&self) -> &Self::Target { + &self._parent + } +} + #[test] fn test_nested_blocks() { let t = NestedChildTemplate { @@ -109,6 +137,14 @@ struct DeepKidTemplate { item: String, } +impl Deref for DeepKidTemplate { + type Target = DeepMidTemplate; + + fn deref(&self) -> &Self::Target { + &self._parent + } +} + #[test] fn test_deep() { let t = DeepKidTemplate { |