]> git.scottworley.com Git - tablify/blobdiff - src/lib.rs
Don't color the background of cells that contain only '×'s
[tablify] / src / lib.rs
index 84cb336301e83f47b6e13bf4b484c41dca1322b5..859b3c19157d11b1e003165bbc7a72249641fc62 100644 (file)
@@ -315,7 +315,14 @@ fn render_cell(col: &str, row: &mut Row) -> HTML {
     let row_label = HTML::escape(row.label.as_ref());
     let col_label = HTML::escape(col);
     let instances: Option<&Vec<Option<String>>> = row.entries.get(col);
-    let class = HTML::from(if instances.is_none() { "" } else { "yes" });
+    let is_empty = match instances {
+        None => true,
+        Some(is) => is.iter().all(|ins| match ins {
+            None => false,
+            Some(content) => content == "×",
+        }),
+    };
+    let class = HTML::from(if is_empty { "" } else { "yes" });
     let contents = match instances {
         None => HTML::from(""),
         Some(is) => render_instances(is),
@@ -756,6 +763,18 @@ mod tests {
                 r#"<td class="yes" onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')">5 𝍷</td>"#
             )
         );
+        assert_eq!(
+            render_cell(
+                "foo",
+                &mut Row {
+                    label: "nope".to_owned(),
+                    entries: HashMap::from([("foo".to_owned(), vec![Some("×".to_owned())])]),
+                }
+            ),
+            HTML::from(
+                r#"<td class="" onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')">×</td>"#
+            )
+        );
         assert_eq!(
             render_cell(
                 "heart",