X-Git-Url: http://git.scottworley.com/tablify/blobdiff_plain/e44de444711dd8dc9d79f4fd6ab86c2d0fd26862..215d38d5b5ca4c77bc517c75fc93498a1d20b24b:/src/lib.rs?ds=sidebyside
diff --git a/src/lib.rs b/src/lib.rs
index b52806a..acf5383 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -293,7 +293,7 @@ fn render_all_leftovers(row: &Row) -> HTML {
)
}
-fn render_row(columns: &[String], rowlike: &mut Rowlike) -> HTML {
+fn render_row(config: &Config, columns: &[String], rowlike: &mut Rowlike) -> HTML {
match rowlike {
Rowlike::Spacer => HTML::from("
|
\n"),
Rowlike::Row(row) => {
@@ -310,7 +310,7 @@ fn render_row(columns: &[String], rowlike: &mut Rowlike) -> HTML {
}
}
-fn render_column_headers(columns: &[String]) -> HTML {
+fn render_column_headers(config: &Config, columns: &[String]) -> HTML {
HTML(
String::from(r#" | "#)
+ &columns.iter().fold(String::new(), |mut acc, col| {
@@ -337,9 +337,9 @@ pub fn tablify(input: impl std::io::Read) -> Result {
let columns = column_order(&config, &rows);
Ok(HTML(format!(
"{HEADER}{}{}{FOOTER}",
- render_column_headers(&columns),
+ render_column_headers(&config, &columns),
rows.into_iter()
- .map(|mut r| render_row(&columns, &mut r))
+ .map(|mut r| render_row(&config, &columns, &mut r))
.collect::()
)))
}
@@ -489,10 +489,10 @@ mod tests {
#[test]
fn test_read_config() {
assert_eq!(
- read_config(&b"!col_threshold 10"[..]).unwrap(),
- Config {
- column_threshold: 10
- }
+ read_config(&b"!col_threshold 10"[..])
+ .unwrap()
+ .column_threshold,
+ 10
);
let bad_num = read_config(&b"!col_threshold foo"[..]);
@@ -674,6 +674,9 @@ mod tests {
fn test_render_row() {
assert_eq!(
render_row(
+ &Config {
+ column_threshold: 0,
+ },
&["foo".to_owned()],
&mut Rowlike::Row(Row {
label: "nope".to_owned(),
---|