Skip to content

Commit

Permalink
Export builder code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
maximehamm committed Mar 30, 2021
1 parent 530c68d commit 200d33c
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions plugin/src/main/kotlin/io/nimbly/tzatziki/pdf/PdfBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,32 +71,38 @@ class PdfBuilder(private val style: PdfStyle) {
}

fun generate(): String {
val sb = StringBuilder()

sb.append("\n<html>")
sb.append("\n<head>")
sb.append("\n<style>")
val sb = StringBuilder()
fun tag(tag: String, function: () -> Unit) {
sb.append("\n<$tag>")
function()
sb.append("\n</$tag>")
}

style.apply {
first?.apply {
sb.append("\n@page:first {")
sb.append('\n' + pagePdfStyle(orientation))
sb.append("}")
tag("html") {
tag("head") {
tag("style") {
style.apply {
first?.apply {
sb.append("\n@page:first {")
sb.append('\n' + pagePdfStyle(orientation))
sb.append("}")
}
sb.append("\n@page {")
sb.append('\n' + pagePdfStyle(orientation))
sb.append("}")
sb.append(standardPdfStyle())
sb.append(contentStyle)
}
}
}
tag("body") {
sb.append("\n")
insertSummaryNow()
sb.append(out)
}
sb.append("\n@page {")
sb.append('\n' + pagePdfStyle(orientation))
sb.append("}")
sb.append(standardPdfStyle())
sb.append(contentStyle)
}

sb.append("\n</style>")
sb.append("\n</head>")
sb.append("\n<body>\n")
insertSummaryNow()
sb.append(out)
sb.append("\n</body>")
sb.append("\n</html>")
return sb.toString()
}
}
Expand Down

0 comments on commit 200d33c

Please sign in to comment.