// func(S) -> S
static new ThreadLocal htmlTable_cellEncoder;
static S htmlTable(O data) {
ret htmlTable(data, true);
}
static S htmlTable(O data, boolean useHtmlEncode) {
ret htmlTable(data, useHtmlEncode, false);
}
static S htmlTable(O data, boolean useHtmlEncode, boolean useBr) {
// prepare table
new L> rows;
new L cols;
if (data instanceof L) {
for (O x : (L) data) pcall {
rows.add(dataToTable_makeRow(x, cols));
}
} else if (data instanceof Map) {
Map map = cast data;
for (O key : map.keySet()) {
O value = map.get(key);
rows.add(litlist(structureOrText(key), structureOrText(value)));
}
} else
print("Unknown data type: " + data);
// get table width
int w = 0;
for (L row : rows)
w = max(w, l(row));
// construct HTML for table
new StringBuilder buf;
buf.append("
\n");
// title
buf.append("
\n");
for (S cell : padList(cols, w, "?"))
buf.append("
\n");
ret buf.toString();
}
static S htmlTable_encodeCell(S cell, boolean useHtmlEncode, boolean useBr) {
if (htmlTable_cellEncoder! != null) ret (S) callF(htmlTable_cellEncoder!, cell);
if (useHtmlEncode) cell = htmlEncode(cell);
if (useBr) cell = nlToBr(cell);
ret cell;
}