11import org.asciidoctor.gradle.jvm.AsciidoctorTask
22
3- buildscript {
4- repositories { mavenCentral() }
5- dependencies {
6- classpath(" io.pebbletemplates:pebble:3.2.3" )
7- }
8- }
9-
103@Suppress(" DSL_SCOPE_VIOLATION" )
114plugins {
125 alias(libs.plugins.asciidoctorj)
13- alias(libs.plugins.minigdx.developer )
6+ alias(libs.plugins.minigdx.jvm )
147}
158
169val asciidoctorResources by configurations.creating {
1710 isCanBeConsumed = false
1811 isCanBeResolved = true
1912}
2013
21- val asciidoctorDependencies by configurations.creating {
22- isCanBeConsumed = false
23- isCanBeResolved = true
24- }
25-
2614val jsonApiDependencies by configurations.creating {
2715 isCanBeConsumed = false
2816 isCanBeResolved = true
@@ -39,16 +27,6 @@ dependencies {
3927 ),
4028 )
4129
42- add(
43- asciidoctorDependencies.name,
44- project(
45- mapOf (
46- " path" to " :tiny-engine" ,
47- " configuration" to " tinyApiAsciidoctor" ,
48- ),
49- ),
50- )
51-
5230 add(
5331 jsonApiDependencies.name,
5432 project(
@@ -58,6 +36,9 @@ dependencies {
5836 ),
5937 ),
6038 )
39+
40+ implementation(libs.pebble)
41+ implementation(libs.kotlin.serialization.json)
6142}
6243
6344val unzipAsciidoctorResources =
@@ -68,13 +49,6 @@ val unzipAsciidoctorResources =
6849 cp.into(project.layout.buildDirectory.get().asFile.resolve(" docs/asciidoc" ))
6950 }
7051
71- val copyAsciidoctorDependencies =
72- tasks.maybeCreate(" copy-asciidoctorDependencies" , Copy ::class ).also { cp ->
73- // I'm bit lazy, I copy the result straight into the source directory :grimace:
74- cp.into(project.projectDir.resolve(" src/docs/asciidoc/dependencies" ))
75- cp.from(asciidoctorDependencies)
76- }
77-
7852val copySample =
7953 tasks.register(" copy-sample" , Copy ::class ) {
8054 from(project.projectDir.resolve(" src/docs/asciidoc/sample" ))
@@ -103,115 +77,47 @@ val copySeoFiles = tasks.register("copy-seoFiles", Copy::class) {
10377 include(" showcase.json" )
10478 include(" tutorials.json" )
10579 include(" document.json" )
106- include(" api.html" )
10780 }
10881 into(project.layout.buildDirectory.get().asFile.resolve(" docs/asciidoc" ))
10982}
11083
111- val renderPebbleTemplates = tasks.register(" renderPebbleTemplates" ) {
84+ val renderPebbleTemplates = tasks.register(" renderPebbleTemplates" , JavaExec :: class ) {
11285 val templateDir = project.projectDir.resolve(" src/docs/templates" )
11386 val dataDir = project.projectDir.resolve(" src/docs/asciidoc" )
11487 val outputDir = project.layout.buildDirectory.get().asFile.resolve(" docs/asciidoc" )
88+ val apiJsonFile = project.layout.buildDirectory.get().asFile.resolve(" docs/asciidoc/tiny-api.json" )
89+
90+ dependsOn(
91+ tasks.named(" classes" ),
92+ copyJsonApi,
93+ copySeoFiles,
94+ unzipAsciidoctorResources,
95+ copySample,
96+ copyResources,
97+ )
98+
99+ classpath = project.the<SourceSetContainer >().getByName(" main" ).runtimeClasspath
100+ mainClass.set(" com.github.minigdx.tiny.doc.PebbleRendererKt" )
101+ args = listOf (
102+ templateDir.absolutePath,
103+ dataDir.absolutePath,
104+ outputDir.absolutePath,
105+ apiJsonFile.absolutePath,
106+ )
115107
116108 inputs.dir(templateDir)
117109 inputs.files(
118110 dataDir.resolve(" showcase.json" ),
119111 dataDir.resolve(" tutorials.json" ),
120112 dataDir.resolve(" document.json" ),
121113 )
114+ inputs.files(apiJsonFile)
122115 outputs.files(
123116 outputDir.resolve(" index.html" ),
124117 outputDir.resolve(" showcase.html" ),
125118 outputDir.resolve(" documentation.html" ),
126119 outputDir.resolve(" api.html" ),
127120 )
128-
129- doLast {
130- val slurper = groovy.json.JsonSlurper ()
131-
132- @Suppress(" UNCHECKED_CAST" )
133- val games = slurper.parseText(dataDir.resolve(" showcase.json" ).readText()) as List <Map <String , Any >>
134- @Suppress(" UNCHECKED_CAST" )
135- val tutorials = slurper.parseText(dataDir.resolve(" tutorials.json" ).readText()) as List <Map <String , Any >>
136- @Suppress(" UNCHECKED_CAST" )
137- val functions = slurper.parseText(dataDir.resolve(" document.json" ).readText()) as List <Map <String , Any >>
138-
139- // Extract unique genres from showcase data
140- val genreSet = mutableSetOf<String >()
141- games.forEach { game ->
142- @Suppress(" UNCHECKED_CAST" )
143- val genres = game[" genres" ] as List <String >
144- genres.forEach { genreSet.add(it) }
145- }
146- val genres = genreSet.sorted()
147-
148- // Extract unique libraries from function data
149- val libSet = mutableSetOf<String >()
150- functions.forEach { fn ->
151- libSet.add(fn[" library" ] as String )
152- }
153- val libraries = libSet.sorted()
154-
155- // Raw JSON for embedding in documentation page
156- val functionsJson = dataDir.resolve(" document.json" ).readText()
157-
158- // Set up Pebble template engine
159- val loader = io.pebbletemplates.pebble.loader.FileLoader ()
160- loader.setPrefix(templateDir.absolutePath + " /" )
161- loader.setSuffix(" " )
162- val engine = io.pebbletemplates.pebble.PebbleEngine .Builder ()
163- .loader(loader)
164- .autoEscaping(true )
165- .build()
166-
167- outputDir.mkdirs()
168-
169- // Render index.html (no JSON data needed)
170- val indexTemplate = engine.getTemplate(" pages/index.peb" )
171- java.io.File (outputDir, " index.html" ).writer().use { writer ->
172- indexTemplate.evaluate(writer, mapOf<String , Any >())
173- }
174-
175- // Render showcase.html
176- val showcaseTemplate = engine.getTemplate(" pages/showcase.peb" )
177- java.io.File (outputDir, " showcase.html" ).writer().use { writer ->
178- showcaseTemplate.evaluate(
179- writer,
180- mapOf<String , Any >(
181- " games" to games,
182- " genres" to genres,
183- " initialCount" to 6 ,
184- ),
185- )
186- }
187-
188- // Render documentation.html
189- val docTemplate = engine.getTemplate(" pages/documentation.peb" )
190- java.io.File (outputDir, " documentation.html" ).writer().use { writer ->
191- docTemplate.evaluate(
192- writer,
193- mapOf<String , Any >(
194- " tutorials" to tutorials,
195- " functions" to functions,
196- " functionsJson" to functionsJson,
197- ),
198- )
199- }
200-
201- // Render api.html
202- val apiTemplate = engine.getTemplate(" pages/api.peb" )
203- java.io.File (outputDir, " api.html" ).writer().use { writer ->
204- apiTemplate.evaluate(
205- writer,
206- mapOf<String , Any >(
207- " functions" to functions,
208- " libraries" to libraries,
209- ),
210- )
211- }
212-
213- logger.lifecycle(" Rendered 4 Pebble templates to ${outputDir.absolutePath} " )
214- }
215121}
216122
217123tasks.withType(AsciidoctorTask ::class .java).configureEach {
@@ -220,7 +126,6 @@ tasks.withType(AsciidoctorTask::class.java).configureEach {
220126
221127 this .dependsOn(
222128 unzipAsciidoctorResources.dependsOn(" :tiny-web-editor:tinyWebEditor" ),
223- copyAsciidoctorDependencies,
224129 copyJsonApi,
225130 copySample,
226131 copyResources,
0 commit comments