X-Git-Url: http://git.scottworley.com/tablify/blobdiff_plain/28cf4fa29f4e47d8b78894fbe86b175e0ab292be..36bc3a39ef440cc1af77d7d88844cacbe6b4387d:/src/lib.rs?ds=sidebyside
diff --git a/src/lib.rs b/src/lib.rs
index 3e0efd0..cbe9ae9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -4,13 +4,15 @@ use std::fmt::Write;
use std::io::BufRead;
use std::iter::Iterator;
-pub struct Config {}
+pub struct Config {
+ pub column_threshold: usize,
+}
-const HEADER: &str = "
+const HEADER: &str = r#"
-
-
+
+
@@ -35,7 +38,7 @@ const HEADER: &str = "
-";
+"#;
const FOOTER: &str = "
@@ -180,66 +183,96 @@ fn column_counts(rows: &[Row]) -> Vec<(usize, String)> {
counts.sort_unstable_by(|(an, acol), (bn, bcol)| bn.cmp(an).then(acol.cmp(bcol)));
counts
}
-fn column_order(rows: &[Row]) -> Vec {
+fn column_order(config: &Config, rows: &[Row]) -> Vec {
column_counts(rows)
.into_iter()
- .map(|(_, col)| col)
+ .filter_map(|(n, col)| (n >= config.column_threshold).then_some(col))
.collect()
}
-fn render_instance(instance: &Option) -> HTML {
+fn render_one_instance(instance: &Option) -> HTML {
match instance {
None => HTML::from("â"),
Some(instance) => HTML::escape(instance.as_ref()),
}
}
-fn render_cell(col: &str, row: &Row) -> HTML {
- let row_label = HTML::escape(row.label.as_ref());
- let col_label = HTML::escape(col);
- let instances: Option<&Vec