aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/renderers/html/innerTemplating/HtmlTemplater.kt
diff options
context:
space:
mode:
authorIgnat Beresnev <ignat.beresnev@jetbrains.com>2023-11-10 11:46:54 +0100
committerGitHub <noreply@github.com>2023-11-10 11:46:54 +0100
commit8e5c63d035ef44a269b8c43430f43f5c8eebfb63 (patch)
tree1b915207b2b9f61951ddbf0ff2e687efd053d555 /plugins/base/src/main/kotlin/renderers/html/innerTemplating/HtmlTemplater.kt
parenta44efd4ba0c2e4ab921ff75e0f53fc9335aa79db (diff)
downloaddokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.tar.gz
dokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.tar.bz2
dokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.zip
Restructure the project to utilize included builds (#3174)
* Refactor and simplify artifact publishing * Update Gradle to 8.4 * Refactor and simplify convention plugins and build scripts Fixes #3132 --------- Co-authored-by: Adam <897017+aSemy@users.noreply.github.com> Co-authored-by: Oleg Yukhnevich <whyoleg@gmail.com>
Diffstat (limited to 'plugins/base/src/main/kotlin/renderers/html/innerTemplating/HtmlTemplater.kt')
-rw-r--r--plugins/base/src/main/kotlin/renderers/html/innerTemplating/HtmlTemplater.kt82
1 files changed, 0 insertions, 82 deletions
diff --git a/plugins/base/src/main/kotlin/renderers/html/innerTemplating/HtmlTemplater.kt b/plugins/base/src/main/kotlin/renderers/html/innerTemplating/HtmlTemplater.kt
deleted file mode 100644
index 1638c9c0..00000000
--- a/plugins/base/src/main/kotlin/renderers/html/innerTemplating/HtmlTemplater.kt
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.base.renderers.html.innerTemplating
-
-import freemarker.cache.ClassTemplateLoader
-import freemarker.cache.FileTemplateLoader
-import freemarker.cache.MultiTemplateLoader
-import freemarker.log.Logger
-import freemarker.template.Configuration
-import freemarker.template.TemplateExceptionHandler
-import org.jetbrains.dokka.base.DokkaBase
-import org.jetbrains.dokka.base.DokkaBaseConfiguration
-import org.jetbrains.dokka.plugability.DokkaContext
-import org.jetbrains.dokka.plugability.configuration
-import java.io.StringWriter
-
-
-public enum class DokkaTemplateTypes(
- public val path: String
-) {
- BASE("base.ftl")
-}
-
-public typealias TemplateMap = Map<String, Any?>
-
-public class HtmlTemplater(
- context: DokkaContext
-) {
-
- init {
- // to disable logging, but it isn't reliable see [Logger.SYSTEM_PROPERTY_NAME_LOGGER_LIBRARY]
- // (use SLF4j further)
- System.setProperty(
- Logger.SYSTEM_PROPERTY_NAME_LOGGER_LIBRARY,
- System.getProperty(Logger.SYSTEM_PROPERTY_NAME_LOGGER_LIBRARY) ?: Logger.LIBRARY_NAME_NONE
- )
- }
-
- private val configuration = configuration<DokkaBase, DokkaBaseConfiguration>(context)
- private val templaterConfiguration =
- Configuration(Configuration.VERSION_2_3_31).apply { configureTemplateEngine() }
-
- private fun Configuration.configureTemplateEngine() {
- val loaderFromResources = ClassTemplateLoader(javaClass, "/dokka/templates")
- templateLoader = configuration?.templatesDir?.let {
- MultiTemplateLoader(
- arrayOf(
- FileTemplateLoader(it),
- loaderFromResources
- )
- )
- } ?: loaderFromResources
-
- unsetLocale()
- defaultEncoding = "UTF-8"
- templateExceptionHandler = TemplateExceptionHandler.RETHROW_HANDLER
- logTemplateExceptions = false
- wrapUncheckedExceptions = true
- fallbackOnNullLoopVariable = false
- templateUpdateDelayMilliseconds = Long.MAX_VALUE
- }
-
- public fun setupSharedModel(model: TemplateMap) {
- templaterConfiguration.setSharedVariables(model)
- }
-
- public fun renderFromTemplate(
- templateType: DokkaTemplateTypes,
- generateModel: () -> TemplateMap
- ): String {
- val out = StringWriter()
- // Freemarker has own thread-safe cache to keep templates
- val template = templaterConfiguration.getTemplate(templateType.path)
- val model = generateModel()
- template.process(model, out)
-
- return out.toString()
- }
-}
-