From 215d38d5b5ca4c77bc517c75fc93498a1d20b24b Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Wed, 2 Oct 2024 22:00:39 -0700 Subject: [PATCH] Plumb config around --- src/lib.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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(), -- 2.44.1