import org.asciidoctor.gradle.jvm.AsciidoctorTask import java.text.SimpleDateFormat plugins { id "org.asciidoctor.jvm.base" version "3.3.2" id "org.asciidoctor.jvm.convert" version "3.3.2" id "org.asciidoctor.jvm.pdf" version "3.3.2" } repositories { mavenCentral() } asciidoctorj { version = '2.5.3' } ext { today = new Date() versionDate = new SimpleDateFormat("yyyyMMdd").format(today) releaseVersion = System.getenv("RELEASE_VERSION") localVersion = "LocalBuild" project.version = releaseVersion == null ? localVersion : releaseVersion; validity = new Date(project.file("./document.validity").text.trim()) validityEnglish = "valid from " + new SimpleDateFormat("MMMM d, yyyy", Locale.US).format(validity) validityGerman = "Gültig ab " + new SimpleDateFormat("d. MMMM yyy", Locale.GERMANY).format(validity) curriculumFileName = "curriculum-foundation" addSuffixToCurriculum = { suffix -> for (extension in ["html", "pdf"]) { File source = new File("${buildDir}/${curriculumFileName}.${extension}") File target = new File("${buildDir}/${curriculumFileName}${suffix}.${extension}") source.renameTo(target) } } } class RenderCurriculumTask extends AsciidoctorTask { @Inject RenderCurriculumTask(WorkerExecutor we, String curriculumFileName, String versionDate, String validity, String language) { super(we) forkOptions { jvmArgs "--add-opens", "java.base/sun.nio.ch=ALL-UNNAMED", "--add-opens", "java.base/java.io=ALL-UNNAMED" } sourceDir = new File("./docs/") baseDir = new File("./docs/") sources { include "index.adoc" include "${curriculumFileName}.adoc" } outputDir = new File("./build/") outputOptions { separateOutputDirs = false backends 'pdf', 'html5' } def fileVersion = project.version.trim() + "-" + language attributes = [ 'icons' : 'font', 'version-label' : '', 'revnumber' : fileVersion, 'revdate' : versionDate, 'document-version' : fileVersion + "-" + versionDate + " (" + validity + ")", 'currentDate' : versionDate, 'language' : language, 'curriculumFileName': curriculumFileName, 'debug_adoc' : false, 'pdf-stylesdir' : '../pdf-theme/themes', 'pdf-fontsdir' : '../pdf-theme/fonts', 'pdf-style' : 'isaqb', 'stylesheet' : '../html-theme/adoc-github.css', 'stylesheet-dir' : '../html-theme', 'glossary_url' : 'https://public.isaqb.org/glossary/glossary-' + language.toLowerCase() + '.html#term-' ] } } task buildDocs { group 'Documentation' description 'Grouping task for generating all languages in several formats' dependsOn "includeLearningGoals", "renderDE", "renderEN" } task renderDE(type: RenderCurriculumTask, constructorArgs: [curriculumFileName, versionDate, validityGerman, "DE"]) { group 'Documentation' description 'Builds the German curriculum as PDF and HTML file.' doLast { addSuffixToCurriculum("-de") } } task renderEN(type: RenderCurriculumTask, constructorArgs: [curriculumFileName, versionDate, validityEnglish, "EN"]) { group 'Documentation' description 'Builds the English curriculum as PDF and HTML file.' doLast { addSuffixToCurriculum("-en") } } apply from: 'scripts/includeLearningGoals.gradle' defaultTasks "buildDocs"