-
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.
Added freemarker for inkscape images
- Loading branch information
piotr.suwala
committed
May 1, 2024
1 parent
b75fcff
commit fd1ab84
Showing
7 changed files
with
246 additions
and
25 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
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
22 changes: 22 additions & 0 deletions
22
src/main/kotlin/sh/hsp/techtree/freemarker/FreemarkerFactory.kt
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 sh.hsp.techtree.freemarker | ||
|
||
import freemarker.template.Configuration | ||
import sh.hsp.techtree.TreeNode | ||
import java.io.File | ||
import java.nio.file.Files | ||
import kotlin.io.path.writer | ||
|
||
class FreemarkerFactory(val configuration: Configuration = create()) { | ||
fun elementSvg(treeNode: TreeNode): File = | ||
configuration.getTemplate("element.svg").let { template -> | ||
Files.createTempFile("element", ".svg").also { tempFile -> | ||
template.process(treeNode, tempFile.writer()) | ||
}.toFile() | ||
} | ||
|
||
companion object { | ||
fun create() = Configuration(Configuration.VERSION_2_3_32).apply { | ||
setClassForTemplateLoading(FreemarkerFactory::class.java, "/templates") | ||
} | ||
} | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
18 changes: 18 additions & 0 deletions
18
src/test/kotlin/sh/hsp/techtree/freemarker/FreemarkerFactoryTest.kt
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,18 @@ | ||
package sh.hsp.techtree.freemarker | ||
|
||
import org.junit.jupiter.api.Test | ||
import sh.hsp.techtree.TreeNode | ||
|
||
|
||
class FreemarkerFactoryTest { | ||
val treeNode = TreeNode( | ||
title = "Hello", | ||
requires = null, | ||
link = "https://hsp.sh/" | ||
) | ||
|
||
@Test | ||
fun readsTemplate() { | ||
FreemarkerFactory().elementSvg(treeNode) | ||
} | ||
} |