X-Git-Url: http://git.scottworley.com/tablify/blobdiff_plain/fa8b547998d23b948cadde2c9e8f35b9055f9189..215d38d5b5ca4c77bc517c75fc93498a1d20b24b:/src/lib.rs?ds=sidebyside diff --git a/src/lib.rs b/src/lib.rs index d55aa53..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::() ))) } @@ -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(),