chiark / gitweb /
table size html attrs: Centralise html attr formatting
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 31 Mar 2021 11:00:51 +0000 (12:00 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 1 Apr 2021 10:31:37 +0000 (11:31 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/session.rs
templates/macros.tera

index 68baa68dc76f0af040ed83d65680698210a61943..4076a5bebcc3718161b5622b916b4cc5f9e9693c 100644 (file)
@@ -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<SessionPieceContext>,
   defs: Vec<(VisiblePieceId, Html)>,
   nick: String,
@@ -71,6 +71,17 @@ fn session(form: Json<SessionForm>,
   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<SessionForm>,
                  layout: Option<PresentationLayout>)
                  -> Result<Template,OE> {
@@ -213,8 +224,8 @@ fn session_inner(form: Json<SessionForm>,
       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,
index 7d32fadaf3c9b60f713a107016d1b1126e5a520e..20f3bef11e2704446ec94aecaa99c0aed8704b93 100644 (file)
@@ -70,17 +70,9 @@ Hi {{nick | escape}}
 {% endmacro errors %}
 
 {% macro space() %}
-    <svg id="space"
-        xmlns="http://www.w3.org/2000/svg"
-{%- for attr in space_attrs %}
-         {{ attr.0 }}="{{ attr.1 }}"
-{%- endfor %}
-        >
-      <rect fill="{{ table_colour }}" x="0" y="0"
-{%- for attr in rect_attrs %}
-         {{ attr.0 }}="{{ attr.1 }}"
-{%- endfor %}
-           />
+    <svg xmlns="http://www.w3.org/2000/svg"
+         id="space" {{ space_attrs }} >
+      <rect fill="{{ table_colour }}" x="0" y="0" {{ rect_attrs }} />
       <g id="pieces_marker"></g>
 {%- for piece in uses %}
       <use id="use{{ piece.id }}" href="#piece{{ piece.id }}"