use super::prelude::*;
use crate::tree::Table;
use std::num::NonZeroU32;
pub fn render_table(ctx: &mut HtmlContext, table: &Table) {
debug!("Rendering table");
let mut column_span_buf = String::new();
let value_one = NonZeroU32::new(1).unwrap();
ctx.html()
.table()
.attr(attr!(;; &table.attributes))
.inner(|ctx| {
ctx.html().tbody().inner(|ctx| {
for row in &table.rows {
ctx.html() .tr()
.attr(attr!(;; &row.attributes))
.inner(|ctx| {
for cell in &row.cells {
let elements: &[Element] = &cell.elements;
let align_class = match cell.align {
Some(align) => align.html_class(),
None => "",
};
if cell.column_span > value_one {
column_span_buf.clear();
str_write!(column_span_buf, "{}", cell.column_span);
}
ctx.html()
.table_cell(cell.header)
.attr(attr!(
"colspan" => &column_span_buf;
if cell.column_span > value_one,
"class" => align_class;
if cell.align.is_some();;
&cell.attributes,
))
.contents(elements);
}
});
}
});
});
}