/* * Available context bindings: * COLUMNS List * ROWS Iterable * OUT { append() } * FORMATTER { format(row, col); formatValue(Object, col) } * TRANSPOSED Boolean * plus ALL_COLUMNS, TABLE, DIALECT * * where: * DataRow { rowNumber(); first(); last(); data(): List; value(column): Object } * DataColumn { columnNumber(), name() } */ import static com.intellij.openapi.util.text.StringUtil.escapeXml NEWLINE = System.getProperty("line.separator") def printRow = { values, tag, valueToString -> OUT.append("$NEWLINE$NEWLINE") values.each { def str = valueToString(it) def escaped = escapeXml((str as String).replaceAll("\\t|\\b|\\f", "")).replaceAll("\\r|\\n|\\r\\n", "
") OUT.append(" <$tag>$escaped$NEWLINE") } OUT.append("") } OUT.append( """ """) if (!TRANSPOSED) { printRow(COLUMNS, "th") { it.name() } ROWS.each { row -> printRow(COLUMNS, "td") { FORMATTER.format(row, it) } } } else { def values = COLUMNS.collect { new ArrayList( [it.name()] ) } ROWS.each { row -> COLUMNS.eachWithIndex { col, i -> values[i].add(FORMATTER.format(row, col)) } } values.each { printRow(it, "td", { it }) } } OUT.append("""
""")