Skip to content

Commit

Permalink
feat: added hooks to html
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmednfwela committed Aug 6, 2023
1 parent ce86b25 commit 2c738d1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/reporter_html/lib/src/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ typedef ElementProcessor = void Function(Element element);
class ReporterHtmlConfig {
final Node Function(ReportCalculatedRange range)? createElementFromValue;

///td or th
final void Function(Element th, ReportCalculatedRange range)? postProcessCell;
//tr
final void Function(Element th, List<ReportCalculatedRange> cells)?
postProcessRow;

const ReporterHtmlConfig({
this.createElementFromValue,
this.postProcessCell,
this.postProcessRow,
});
}
4 changes: 4 additions & 0 deletions packages/reporter_html/lib/src/reporter_html_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class TabularReporterHtml {
row.groupListsBy((element) => element.range.columnIndex);
final minColKey = colGroups.keys.min;
final tr = _registerElement('tr', parent: res);

for (var colIndex = minColKey; colIndex <= maxColIndex; colIndex++) {
final cells = colGroups[colIndex];
if (cells == null) {
Expand All @@ -48,6 +49,7 @@ class TabularReporterHtml {
}
final cellElement = _registerElement(cellElementTag, parent: tr);
final cell = cells.first;

cellElement.attributes['rowspan'] = cell.range.rowSpan.toString();
cellElement.attributes['colspan'] = cell.range.colSpan.toString();
final valueNode = config.createElementFromValue?.call(cell);
Expand All @@ -56,7 +58,9 @@ class TabularReporterHtml {
} else {
cellElement.text = cell.value.toString();
}
config.postProcessCell?.call(cellElement, cell);
}
config.postProcessRow?.call(tr, cells);
}
return res;
}
Expand Down

0 comments on commit 2c738d1

Please sign in to comment.