The (very WIP) home of the next versions of my web presences

lx: simplify View template lookup

Instead of having a `view::template_for(view: impl View)` with internal
type shenanigans to support it, just use `Self::template()` relying on
the types that are *necessarily* available to support that via a default
`impl` for `View::template`. Works much nicer.

+12 -26
+1 -1
lx/src/archive.rs
··· 51 51 if self.0.is_empty() { 52 52 Ok("".into()) 53 53 } else { 54 - env.get_template(&view::template_for(self))?.render(self) 54 + env.get_template(&Self::template())?.render(self) 55 55 } 56 56 } 57 57 }
+1 -1
lx/src/data/config.rs
··· 127 127 const VIEW_NAME: &'static str = "nav-item"; 128 128 129 129 fn view(&self, env: &Environment) -> Result<String, minijinja::Error> { 130 - env.get_template(&view::template_for(self))?.render(self) 130 + env.get_template(&Self::template())?.render(self) 131 131 } 132 132 } 133 133
+1 -1
lx/src/data/item/mod.rs
··· 237 237 const VIEW_NAME: &'static str = "qualifiers"; 238 238 239 239 fn view(&self, env: &Environment) -> Result<String, minijinja::Error> { 240 - env.get_template(&view::template_for(self))?.render(self) 240 + env.get_template(&Self::template())?.render(self) 241 241 } 242 242 } 243 243
+6 -7
lx/src/templates/functions.rs
··· 182 182 const VIEW_NAME: &'static str = "twitter-label"; 183 183 184 184 fn view(&self, env: &minijinja::Environment) -> Result<String, minijinja::Error> { 185 - env.get_template(&view::template_for(self))? 186 - .render(context! { 187 - label1 => self.label1(), 188 - label2 => self.label2(), 189 - data1 => self.data1(), 190 - data2 => self.data2(), 191 - }) 185 + env.get_template(&Self::template())?.render(context! { 186 + label1 => self.label1(), 187 + label2 => self.label2(), 188 + data1 => self.data1(), 189 + data2 => self.data2(), 190 + }) 192 191 } 193 192 } 194 193
+3 -16
lx/src/templates/view.rs
··· 5 5 const VIEW_NAME: &'static str; 6 6 7 7 fn view(&self, env: &Environment) -> Result<String, minijinja::Error> { 8 - env.get_template(&template_for(self))?.render(self) 8 + env.get_template(&Self::template())?.render(self) 9 9 } 10 - } 11 10 12 - // The slightly-quirky approach here is one I am experimenting with, not sure about. It 13 - // has the benefit/cost of not being able to do `template_for<SomeView>()` and requires 14 - // me to pass an actual `impl View` type instead. It has *worse* monomorphization 15 - // characteristics than just using an outer generic function! (This is sort of the 16 - // inverse of where you do the non-generic inner function.) But it also has the upside 17 - // of making it a bit more “normal” at the call side? 18 - /// Get the template name for a given View given the conventional layout of my projects. 19 - /// 20 - /// As of today, a template named `"foo"` will be resolved as `"view/foo.jinja"`. 21 - pub(crate) fn template_for(view: &impl View) -> String { 22 - fn helper<V: View>(_: &V) -> String { 23 - format!("views/{}.jinja", V::VIEW_NAME) 11 + fn template() -> String { 12 + format!("views/{}.jinja", Self::VIEW_NAME) 24 13 } 25 - 26 - helper(view) 27 14 }