From c3395901432e123d050d1765b30e77f89d7d676b Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 1 Apr 2021 11:52:29 +0100 Subject: [PATCH] html: Move to otter-base No uses yet. Signed-off-by: Ian Jackson --- Cargo.lock | 2 +- Cargo.toml | 1 - base/Cargo.toml | 1 + {src => base}/html.rs | 0 base/imports.rs | 1 + base/lib.rs | 1 + base/prelude.rs | 7 +++++++ daemon/cmdlistener.rs | 2 +- src/global.rs | 8 +++++--- src/imports.rs | 1 - src/lib.rs | 1 - src/prelude.rs | 9 ++------- src/spec.rs | 2 +- 13 files changed, 20 insertions(+), 16 deletions(-) rename {src => base}/html.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 6f8af030..463209fa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2109,7 +2109,6 @@ dependencies = [ "flexi_logger", "fs2", "glob 0.3.0", - "htmlescape", "index_vec", "inventory", "lazy-init", @@ -2168,6 +2167,7 @@ dependencies = [ "derive_more", "extend", "fehler", + "htmlescape", "if_chain", "itertools", "num-derive", diff --git a/Cargo.toml b/Cargo.toml index 4b8fcf55..1958c634 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,6 @@ failure="0.1.8" fehler="1" fs2="0.4" glob="0.3" -htmlescape="0.3" inventory="0.1" lazy-init="0.5" lazy_static="1" diff --git a/base/Cargo.toml b/base/Cargo.toml index fc469fb8..61bb8532 100644 --- a/base/Cargo.toml +++ b/base/Cargo.toml @@ -16,6 +16,7 @@ path = "lib.rs" arrayvec = "0.5" derive_more = "0.99" extend="1" +htmlescape="0.3" if_chain = "1" itertools="0.10" num-derive="0.3" diff --git a/src/html.rs b/base/html.rs similarity index 100% rename from src/html.rs rename to base/html.rs diff --git a/base/imports.rs b/base/imports.rs index cc2bb839..b10733bd 100644 --- a/base/imports.rs +++ b/base/imports.rs @@ -5,6 +5,7 @@ pub use arrayvec; pub use derive_more; pub use extend; +pub use htmlescape; pub use if_chain; pub use itertools; pub use num_derive; diff --git a/base/lib.rs b/base/lib.rs index 9dcb9b9d..d4610694 100644 --- a/base/lib.rs +++ b/base/lib.rs @@ -6,5 +6,6 @@ pub mod imports; pub mod prelude; pub mod geometry; +pub mod html; pub mod zcoord; pub mod misc; diff --git a/base/prelude.rs b/base/prelude.rs index 30cfe48b..143677e2 100644 --- a/base/prelude.rs +++ b/base/prelude.rs @@ -2,17 +2,21 @@ // SPDX-License-Identifier: AGPL-3.0-or-later // There is NO WARRANTY. +pub use std::borrow::Borrow; pub use std::cmp::{max, Ordering}; pub use std::convert::{TryFrom, TryInto}; pub use std::fmt::{self, Debug, Display, Formatter}; pub use std::hash::{Hash, Hasher}; pub use std::iter; +pub use std::mem; pub use std::num::{TryFromIntError, Wrapping}; +pub use std::ops::{Deref, DerefMut, Index, IndexMut}; pub use std::str; pub use std::str::FromStr; pub use arrayvec::ArrayVec; pub use derive_more::*; +pub use extend::ext; pub use fehler::{throw, throws}; pub use if_chain::if_chain; pub use itertools::izip; @@ -22,6 +26,9 @@ pub use serde_with::SerializeDisplay; pub use thiserror::Error; pub use void::Void; +pub use crate::html::*; + pub use crate::geometry::{CoordinateOverflow, PosC}; +pub use crate::{hformat, hformat_as_display, hwrite}; pub use crate::misc::default; pub use crate::misc::display_as_debug; diff --git a/daemon/cmdlistener.rs b/daemon/cmdlistener.rs index 83829941..22f26468 100644 --- a/daemon/cmdlistener.rs +++ b/daemon/cmdlistener.rs @@ -541,7 +541,7 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>( update_links(cs,ag,ig, |ig_links|{ let mut new_links: LinksTable = (**ig_links).clone(); let url: Url = (&url).try_into()?; - let show: Html = (kind, url.as_str()).into(); + let show: Html = (kind, url.as_str()).to_html(); new_links[kind] = Some(url.into_string()); let new_links = Arc::new(new_links); *ig_links = new_links.clone(); diff --git a/src/global.rs b/src/global.rs index 7d363be5..7d0c74cc 100644 --- a/src/global.rs +++ b/src/global.rs @@ -523,8 +523,10 @@ impl Display for InstanceName { fn link_a_href(k: &HtmlStr, v: &str) -> Html { hformat!("{}", v, k) } -impl From<(LinkKind, &str)> for Html { - fn from((k, v): (LinkKind, &str)) -> Html { +#[ext(pub)] +impl (LinkKind, &str) { + fn to_html(self) -> Html { + let (k, v) = self; link_a_href(&k.to_html(), v) } } @@ -534,7 +536,7 @@ impl From<&LinksTable> for Html { let mut s = links.iter() .filter_map(|(k,v)| { let v = v.as_ref()?; - Some(Html::from((k, v.as_str()))) + Some((k, v.as_str()).to_html()) }) .chain(iter::once( link_a_href(Html::lit("Shapelib").into(), "/_/shapelib.html") diff --git a/src/imports.rs b/src/imports.rs index 0bd1ab06..ec6e02b7 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -17,7 +17,6 @@ pub use failure; pub use flexi_logger; pub use fs2; pub use glob; -pub use htmlescape; pub use index_vec; pub use lazy_init; pub use lazy_static; diff --git a/src/lib.rs b/src/lib.rs index a15a6b3c..5ddbdc10 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,7 +18,6 @@ pub mod debugreader; pub mod error; pub mod gamestate; pub mod global; -pub mod html; pub mod hand; pub mod hidden; pub mod keydata; diff --git a/src/prelude.rs b/src/prelude.rs index 0aed003e..c1ce3290 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -5,11 +5,11 @@ use crate::imports::*; pub use crate::imports::{flexi_logger, thiserror}; - pub use crate::imports::serde_json; +pub use otter_base::prelude::*; + pub use std::any::Any; -pub use std::borrow::Borrow; pub use std::borrow::Cow; pub use std::cmp::{self, max, min, Ordering}; pub use std::collections::VecDeque; @@ -33,9 +33,7 @@ pub use std::io::{Seek, SeekFrom}; pub use std::iter; pub use std::iter::repeat_with; pub use std::marker::PhantomData; -pub use std::mem; pub use std::num::{NonZeroUsize, TryFromIntError, Wrapping}; -pub use std::ops::{Deref, DerefMut, Index, IndexMut}; pub use std::os::linux::fs::MetadataExt; // todo why linux for st_mode?? pub use std::os::unix; pub use std::os::unix::ffi::OsStrExt; @@ -63,7 +61,6 @@ pub use downcast_rs::{impl_downcast, Downcast}; pub use either::{Either, Left, Right}; pub use enum_dispatch::enum_dispatch; pub use enum_map::{Enum, EnumMap}; -pub use extend::ext; pub use fehler::{throw, throws}; pub use flexi_logger::LogSpecification; pub use fs2::FileExt; @@ -114,7 +111,6 @@ pub use crate::dbgc; pub use crate::{deref_to_field, deref_to_field_mut}; pub use crate::ensure_eq; pub use crate::from_instance_lock_error; -pub use crate::{hformat, hformat_as_display, hwrite}; pub use crate::matches_doesnot; pub use crate::trace_dbg; @@ -133,7 +129,6 @@ pub use crate::fake_rng::*; pub use crate::gamestate::*; pub use crate::global::*; pub use crate::hidden::*; -pub use crate::html::*; pub use crate::keydata::*; pub use crate::mgmtchannel::*; pub use crate::nwtemplates; diff --git a/src/spec.rs b/src/spec.rs index 14fc298d..c547f785 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -21,12 +21,12 @@ use strum::{EnumString, Display}; use thiserror::Error; use otter_base::geometry::{Coord,Pos}; +use otter_base::hformat_as_display; use otter_base::misc::display_as_debug; use crate::accounts::AccountName; use crate::error::UnsupportedColourSpec; use crate::gamestate::PieceSpec; -use crate::hformat_as_display; use crate::prelude::default; pub use imp::PlayerAccessSpec; -- 2.30.2