-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
V0.2.2: Add pdf rendering with playwright (alfa)
- Loading branch information
Showing
13 changed files
with
234 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,11 +15,31 @@ Run server with presentation: | |
jbang [email protected] run ./MyAwesomePresentation.reveal.kts | ||
``` | ||
|
||
Render presentation to static html site: | ||
Bundle presentation to static html site: | ||
```bash | ||
jbang [email protected] render ./MyAwesomePresentation.reveal.kts | ||
jbang [email protected] bundle ./MyAwesomePresentation.reveal.kts | ||
``` | ||
|
||
Render presentation to pdf via playwright: | ||
```bash | ||
jbang [email protected] pdf ./MyAwesomePresentation.reveal.kts -o myPresentation.pdf | ||
``` | ||
|
||
[!CAUTION] | ||
For now playwright requires to download chromium at first run via npm | ||
|
||
Playwright documentation: https://playwright.dev/java/docs/browsers | ||
|
||
```bash | ||
jbang [email protected] pdf install-chrome | ||
``` | ||
|
||
Uninstall chrome | ||
```bash | ||
jbang [email protected] pdf uninstall-chrome | ||
``` | ||
|
||
|
||
Create new presentation from template | ||
```bash | ||
jbang [email protected] init my-awesome-presentation | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,22 @@ | ||
[versions] | ||
|
||
kotlin = "1.9.0" | ||
serialization = "1.4.1" | ||
serialization = "1.6.3" | ||
ktor = "2.1.3" | ||
kxhtml = "0.9.1" | ||
kxhtml = "0.11.0" | ||
|
||
[libraries] | ||
slf4j = { module = "org.slf4j:slf4j-api", version = "2.0.7" } | ||
logback = { module = "ch.qos.logback:logback-classic", version = "1.4.14"} | ||
clikt = { module = "com.github.ajalt.clikt:clikt", version = "4.2.1" } | ||
logback = { module = "ch.qos.logback:logback-classic", version = "1.5.0"} | ||
clikt = { module = "com.github.ajalt.clikt:clikt", version = "4.2.2" } | ||
kxhtml-jvm = { module = "org.jetbrains.kotlinx:kotlinx-html-jvm", version.ref = "kxhtml" } | ||
kxhtml = { module = "org.jetbrains.kotlinx:kotlinx-html", version.ref = "kxhtml" } | ||
uuid = { module = "com.benasher44:uuid", version = "0.8.2" } | ||
qrcode = { module = "io.github.g0dkar:qrcode-kotlin", version = "4.1.1" } | ||
playwright = { module = "com.microsoft.playwright:playwright", version = "1.41.2" } | ||
|
||
[plugins] | ||
|
||
versions = { id = "com.github.ben-manes.versions", version = "0.50.0" } | ||
versions = { id = "com.github.ben-manes.versions", version = "0.51.0" } | ||
dokka = { id = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "kotlin" } | ||
build-config = { id = "dev.limebeck.build-time-config", version = "2.2.0"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,28 @@ | ||
package dev.limebeck.application | ||
|
||
import com.github.ajalt.clikt.completion.completionOption | ||
import com.github.ajalt.clikt.core.CliktCommand | ||
import com.github.ajalt.clikt.core.subcommands | ||
import dev.limebeck.application.commands.* | ||
import dev.limebeck.revealkt.RevealkConfig | ||
|
||
fun main(args: Array<String>) = RevealKtApplication() | ||
.subcommands(RunServer(), InitTemplate(), RenderToFile()) | ||
fun main(args: Array<String>) = RevealKtCliApplication() | ||
.subcommands( | ||
RunServer(), | ||
InitTemplate(), | ||
BundleToStatic(), | ||
RenderPdf().subcommands(InstallChrome(), UninstallChrome()) | ||
) | ||
.completionOption() | ||
.main(args) | ||
|
||
class RevealKtCliApplication : CliktCommand( | ||
printHelpOnEmptyArgs = true, | ||
help = """ | ||
RevealKt CLI | ||
Application version ${RevealkConfig.version} | ||
""".trimIndent() | ||
) { | ||
override fun run() = Unit | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package dev.limebeck.application.commands | ||
|
||
import com.github.ajalt.clikt.core.CliktCommand | ||
import com.github.ajalt.clikt.parameters.arguments.argument | ||
import com.github.ajalt.clikt.parameters.options.default | ||
import com.github.ajalt.clikt.parameters.options.option | ||
import com.github.ajalt.clikt.parameters.types.path | ||
import dev.limebeck.application.templates.generatePresentationTemplate | ||
import java.nio.file.Path | ||
import kotlin.io.path.div | ||
|
||
class InitTemplate : CliktCommand(name = "init", help = "Create new presentation from template") { | ||
val name: String by argument(help = "Presentation name") | ||
val basePath: Path by option(help = "Template dir") | ||
.path(canBeDir = true, canBeFile = false) | ||
.default(Path.of(".")) | ||
val dirname: String? by option() | ||
|
||
override fun run() { | ||
generatePresentationTemplate(name, basePath / (dirname ?: name)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package dev.limebeck.application.commands | ||
|
||
import com.github.ajalt.clikt.core.CliktCommand | ||
import com.github.ajalt.clikt.core.context | ||
import com.github.ajalt.clikt.output.MordantHelpFormatter | ||
import com.github.ajalt.clikt.parameters.arguments.argument | ||
import com.github.ajalt.clikt.parameters.options.default | ||
import com.github.ajalt.clikt.parameters.options.defaultLazy | ||
import com.github.ajalt.clikt.parameters.options.option | ||
import com.github.ajalt.clikt.parameters.types.file | ||
import com.github.ajalt.clikt.parameters.types.int | ||
import com.github.ajalt.clikt.parameters.types.path | ||
import com.microsoft.playwright.CLI | ||
import dev.limebeck.application.pdf.PdfRenderer | ||
import dev.limebeck.application.server.Config | ||
import dev.limebeck.application.server.ServerConfig | ||
import dev.limebeck.application.server.runServer | ||
import kotlinx.coroutines.runBlocking | ||
import java.io.File | ||
import java.nio.file.Path | ||
import kotlin.concurrent.thread | ||
import kotlin.io.path.pathString | ||
|
||
class RenderPdf : CliktCommand(name = "pdf", help = "Render pdf from presentation") { | ||
val port: Int by option("-p", "--port", help = "Port").int().default(8080) | ||
val host: String by option("-h", "--host", help = "Host").default("0.0.0.0") | ||
val basePath: Path? by option("-b", help = "Script dir").path() | ||
val script: File by argument(help = "Script file").file(canBeDir = false, mustBeReadable = true) | ||
val output: File by option("-o", "--output", help = "Output file") | ||
.file(canBeDir = false, mustBeWritable = true) | ||
.defaultLazy { File("./output.pdf") } | ||
|
||
init { | ||
context { | ||
helpFormatter = { | ||
MordantHelpFormatter( | ||
showDefaultValues = true, | ||
context = it | ||
) | ||
} | ||
} | ||
} | ||
|
||
val renderer = PdfRenderer() | ||
|
||
override fun run() { | ||
runServer( | ||
Config( | ||
server = ServerConfig(host, port), | ||
basePath = basePath?.pathString ?: script.parent, | ||
script = script | ||
), | ||
background = false | ||
) | ||
runBlocking { | ||
val outputData = renderer.render("http://$host:$port/?print-pdf") | ||
output.writeBytes(outputData) | ||
} | ||
} | ||
} | ||
|
||
class InstallChrome : CliktCommand(name = "install-chrome", help = "Install chrome") { | ||
override fun run() { | ||
CLI.main(arrayOf("install", "chromium")) | ||
} | ||
} | ||
|
||
class UninstallChrome : CliktCommand(name = "uninstall-chrome", help = "Uninstall chrome") { | ||
override fun run() { | ||
CLI.main(arrayOf("uninstall")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package dev.limebeck.application.commands | ||
|
||
import com.github.ajalt.clikt.core.CliktCommand | ||
import com.github.ajalt.clikt.core.context | ||
import com.github.ajalt.clikt.output.MordantHelpFormatter | ||
import com.github.ajalt.clikt.parameters.arguments.argument | ||
import com.github.ajalt.clikt.parameters.options.default | ||
import com.github.ajalt.clikt.parameters.options.option | ||
import com.github.ajalt.clikt.parameters.types.file | ||
import com.github.ajalt.clikt.parameters.types.int | ||
import com.github.ajalt.clikt.parameters.types.path | ||
import dev.limebeck.application.server.Config | ||
import dev.limebeck.application.server.ServerConfig | ||
import dev.limebeck.application.server.runServer | ||
import java.io.File | ||
import java.nio.file.Path | ||
import kotlin.io.path.pathString | ||
|
||
class RunServer : CliktCommand(name = "run", help = "Serve presentation with live-reload") { | ||
val port: Int by option(help = "Port").int().default(8080) | ||
val host: String by option(help = "Host").default("0.0.0.0") | ||
val basePath: Path? by option(help = "Script dir").path() | ||
val script: File by argument(help = "Script file").file(canBeDir = false, mustBeReadable = true) | ||
|
||
init { | ||
context { | ||
helpFormatter = { | ||
MordantHelpFormatter( | ||
showDefaultValues = true, | ||
context = it | ||
) | ||
} | ||
} | ||
} | ||
|
||
override fun run() { | ||
runServer( | ||
Config( | ||
server = ServerConfig(host, port), | ||
basePath = basePath?.pathString ?: script.parent, | ||
script = script | ||
) | ||
) | ||
} | ||
} |
Oops, something went wrong.