From f1d1cba3151d2527f57851814c4f28b5332e360c Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 27 Mar 2022 23:54:10 +0100 Subject: [PATCH] Rocket cleanup: Call our tera tera Signed-off-by: Ian Jackson --- Cargo.toml | 3 +-- TODO | 1 - daemon/api.rs | 2 -- daemon/main.rs | 6 ++---- jstest/jstest.rs | 1 - src/bundles.rs | 2 +- src/error.rs | 1 - src/imports.rs | 2 +- src/nwtemplates.rs | 8 ++++---- src/prelude.rs | 1 + 10 files changed, 10 insertions(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b64d7234..ee340ada 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -73,6 +73,7 @@ structopt="0.3" sha2="0.10" subtle="2.4" tempfile="3" +tera="1.10" toml="0.5" typetag="0.1.6" uds="0.2" @@ -92,8 +93,6 @@ mio = { version="0.8", features=["os-ext", "os-poll" ] } serde = { version="1" , features=["derive", "rc"] } strum = { version="0.24" , features=["derive" ] } -tera_standalone = { version="1.10", package="tera" } - slotmap = { package="slotmap-fork-otter", version="1", git="https://github.com/ijackson/slotmap", branch="slotmap-fork-otter", features=["serde"] } #fin. diff --git a/TODO b/TODO index 2a3dce91..d41d9bec 100644 --- a/TODO +++ b/TODO @@ -4,4 +4,3 @@ content-type for download bundles http2 HEAD requests fix listen fix that /_/updates vs /_/ involves ordering -one tera version diff --git a/daemon/api.rs b/daemon/api.rs index 4ec910f6..dc6c3858 100644 --- a/daemon/api.rs +++ b/daemon/api.rs @@ -2,8 +2,6 @@ // SPDX-License-Identifier: AGPL-3.0-or-later // There is NO WARRANTY. -use crate::imports::*; - pub use super::*; #[derive(Clone,Debug)] diff --git a/daemon/main.rs b/daemon/main.rs index 4812fdb5..63e93402 100644 --- a/daemon/main.rs +++ b/daemon/main.rs @@ -5,7 +5,7 @@ #![feature(lint_reasons)] #![feature(proc_macro_hygiene, decl_macro)] -use otter::imports::thiserror; +use otter::imports::*; pub mod imports; @@ -37,8 +37,6 @@ use actix_files::NamedFile; use actix_cors::Cors; use otter::prelude::*; -use otter::imports::tera_standalone as tera; -use tera::Tera; const CT_JAVASCRIPT: mime::Mime = mime::APPLICATION_JAVASCRIPT_UTF_8; const CT_TEXT: mime::Mime = mime::TEXT_PLAIN_UTF_8; @@ -65,7 +63,7 @@ struct FrontPageRenderContext { pub type Template = HttpResponse; pub struct Templates { - tera: tera::Tera, + tera: Tera, } impl Templates { diff --git a/jstest/jstest.rs b/jstest/jstest.rs index 1e17353c..fdc46010 100644 --- a/jstest/jstest.rs +++ b/jstest/jstest.rs @@ -6,7 +6,6 @@ pub use otter::imports::*; pub use otter::prelude::*; pub use otter_api_tests::Explode; -pub use otter::imports::tera_standalone as tera; pub use indexmap::IndexMap; pub use indexmap::IndexSet; diff --git a/src/bundles.rs b/src/bundles.rs index 2dc4b715..7b412dd6 100644 --- a/src/bundles.rs +++ b/src/bundles.rs @@ -922,7 +922,7 @@ pub fn spec_macroexpand( for (nomfile, data) in &templates { report(nomfile, data)?; } - let mut tera = tera_standalone::Tera::default(); + let mut tera = Tera::default(); tera.add_raw_templates(templates).context("load")?; let mut out: Vec = vec![]; tera.render_to("spec", &default(), &mut out).context("render")?; diff --git a/src/error.rs b/src/error.rs index 7b4a79ac..72049834 100644 --- a/src/error.rs +++ b/src/error.rs @@ -3,7 +3,6 @@ // There is NO WARRANTY. use crate::prelude::*; -use tera_standalone as tera; #[derive(Error,Debug)] pub enum Fatal { // Includes _bogus_ client updates, see PROTOCOL.md diff --git a/src/imports.rs b/src/imports.rs index 88937c97..28580f2b 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -35,7 +35,7 @@ pub use regex; pub use rmp_serde; pub use sha2; pub use slotmap; -pub use tera_standalone; +pub use tera; pub use toml; pub use uds; pub use unicode_width; diff --git a/src/nwtemplates.rs b/src/nwtemplates.rs index 42cf490b..b49062e4 100644 --- a/src/nwtemplates.rs +++ b/src/nwtemplates.rs @@ -10,7 +10,7 @@ use parking_lot::{const_rwlock, RwLock, RwLockReadGuard}; static STATE: RwLock> = const_rwlock(None); struct State { - tera: tera_standalone::Tera, + tera: Tera, } #[throws(StartupError)] @@ -20,7 +20,7 @@ pub fn init() { let config = config(); let nwtemplate_dir = &config.nwtemplate_dir; let glob = format!("{}/*.tera", nwtemplate_dir); - let tera = tera_standalone::Tera::new(&glob) + let tera = Tera::new(&glob) .map_err(|e| anyhow!("{}", e)) .context("load tamplates") .with_context(|| nwtemplate_dir.to_string())?; @@ -34,11 +34,11 @@ pub fn init() { pub fn render(template_name: &str, data: &D) -> String where D: Serialize + Debug { - fn get_tera() -> MappedRwLockReadGuard<'static, tera_standalone::Tera> { + fn get_tera() -> MappedRwLockReadGuard<'static, Tera> { let g = STATE.read(); RwLockReadGuard::map(g, |g| &g.as_ref().unwrap().tera) } - let context = tera_standalone::Context::from_serialize(data) + let context = tera::Context::from_serialize(data) .with_context( || format!("failed make context from serializable {:?}", data) ) diff --git a/src/prelude.rs b/src/prelude.rs index 06b91eea..0a8db361 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -101,6 +101,7 @@ pub use strum::{EnumString, EnumIter, EnumMessage, EnumProperty}; pub use strum::{IntoEnumIterator, IntoStaticStr}; pub use subtle::ConstantTimeEq; pub use tempfile::{self, NamedTempFile}; +pub use tera::Tera; pub use thiserror::Error; pub use unicase::UniCase; pub use url::Url; -- 2.30.2