public override TemplMatchTable Handler(DocX doc, object model, TemplMatchTable m)
{
var width = m.Table.Rows.First().Cells.Count;
var keys = TemplModelEntry.Get(model, m.Body).ToStringKeys();
var nrows = (int)Math.Ceiling(keys.Count() / (float)width);
m.Validate();
m.RemovePlaceholder();
for (int n = 0; n < width; n++)
{
if (n != m.CellIndex)
{
TemplDoc.CellCopyContents(m.Cell, m.Row.Cells[n]);
}
}
Row row = m.Row;
for (int keyIdx = 0; keyIdx < nrows * width; keyIdx++)
{
if (keyIdx % width == 0)
{
row = m.Table.InsertRow(m.Row, m.RowIndex + keyIdx / width + 1);
}
Cell cell = row.Cells[keyIdx % width];
if (keyIdx < keys.Count())
{
new TemplCollectionModule().BuildFromScope(doc, model, cell.Paragraphs, $"{m.Body}[{keys[keyIdx]}]");
}
else
{
TemplDoc.CellClear(cell);
}
}
m.Row.Remove();
m.Removed = true;
return(m);
}