]> git.scottworley.com Git - tablify/blobdiff - src/lib.rs
Start on 0.6.0
[tablify] / src / lib.rs
index 70dfb5286fc628819c9315618d655040b67221e1..c1a47617c701a4e018890b6106f6142733f271cd 100644 (file)
@@ -313,7 +313,12 @@ fn render_instances(instances: &[Option<String>]) -> HTML {
 
 fn render_cell(config: &Config, col: &str, row: &mut Row) -> HTML {
     let row_label = HTML::escape(row.label.as_ref());
 
 fn render_cell(config: &Config, col: &str, row: &mut Row) -> HTML {
     let row_label = HTML::escape(row.label.as_ref());
-    let col_label = HTML::escape(col);
+    let col_label = HTML::escape(
+        config
+            .substitute_labels
+            .get(col)
+            .map_or(col, std::string::String::as_str),
+    );
     let instances: Option<&Vec<Option<String>>> = row.entries.get(col);
     let is_empty = match instances {
         None => true,
     let instances: Option<&Vec<Option<String>>> = row.entries.get(col);
     let is_empty = match instances {
         None => true,
@@ -975,6 +980,25 @@ mod tests {
             ),
             HTML::from(
                 r#"<tr><th id="nope">nope</th><td class="leftover" onmouseover="highlight('nope')" onmouseout="clear_highlight('nope')"></td></tr>
             ),
             HTML::from(
                 r#"<tr><th id="nope">nope</th><td class="leftover" onmouseover="highlight('nope')" onmouseout="clear_highlight('nope')"></td></tr>
+"#
+            )
+        );
+        assert_eq!(
+            render_row(
+                &Config {
+                    column_threshold: 0,
+                    static_columns: vec![],
+                    hidden_columns: HashSet::new(),
+                    substitute_labels: HashMap::from([("foo".to_owned(), "bar".to_owned())]),
+                },
+                &["foo".to_owned()],
+                &mut Rowlike::Row(Row {
+                    label: "nope".to_owned(),
+                    entries: HashMap::from([("foo".to_owned(), vec![None])]),
+                })
+            ),
+            HTML::from(
+                r#"<tr><th id="nope">nope</th><td class="yes" onmouseover="h2('nope','bar')" onmouseout="ch2('nope','bar')">𝍷</td><td class="leftover" onmouseover="highlight('nope')" onmouseout="clear_highlight('nope')"></td></tr>
 "#
             )
         );
 "#
             )
         );