From: Ian Jackson Date: Wed, 31 Mar 2021 11:00:51 +0000 (+0100) Subject: table size html attrs: Centralise html attr formatting X-Git-Tag: otter-0.5.0~354 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=3e6f5653e6d359160ac2828b4f3fbe410cabb1a2;p=otter.git table size html attrs: Centralise html attr formatting Signed-off-by: Ian Jackson --- diff --git a/daemon/session.rs b/daemon/session.rs index 68baa68d..4076a5be 100644 --- a/daemon/session.rs +++ b/daemon/session.rs @@ -13,8 +13,8 @@ struct SessionRenderContext { ctoken: RawToken, player: PlayerId, gen: Generation, - space_attrs: SvgAttrs, - rect_attrs: SvgAttrs, + space_attrs: Html, + rect_attrs: Html, uses: Vec, defs: Vec<(VisiblePieceId, Html)>, nick: String, @@ -71,6 +71,17 @@ fn session(form: Json, session_inner(form, layout.map(|pl| pl.0))? } +#[ext] +impl SvgAttrs { + fn to_html(&self) -> Html { + let mut o = String::new(); + for (k,v) in self { + write!(o, r##"{}="{}""##, k, v).unwrap(); + } + Html::from_html_string(o) + } +} + fn session_inner(form: Json, layout: Option) -> Result { @@ -213,8 +224,8 @@ fn session_inner(form: Json, player, defs: alldefs, uses, - space_attrs: space_table_attrs(table_size), - rect_attrs: space_table_attrs(table_size), + space_attrs: space_table_attrs(table_size).to_html(), + rect_attrs: space_table_attrs(table_size).to_html(), nick, sse_url_prefix, player_info_pane, diff --git a/templates/macros.tera b/templates/macros.tera index 7d32fada..20f3bef1 100644 --- a/templates/macros.tera +++ b/templates/macros.tera @@ -70,17 +70,9 @@ Hi {{nick | escape}} {% endmacro errors %} {% macro space() %} - - + + {%- for piece in uses %}