From: David ‘Bombe’ Roden Date: Tue, 22 Nov 2016 20:55:44 +0000 (+0100) Subject: Include templates for rendering linked elements X-Git-Tag: 0.9.7^2~402 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=2004b7e27c9ea1544f9413d18258569850135f04;p=Sone.git Include templates for rendering linked elements --- diff --git a/src/main/kotlin/net/pterodactylus/sone/template/LinkedElementRenderFilter.kt b/src/main/kotlin/net/pterodactylus/sone/template/LinkedElementRenderFilter.kt index 6644ad8..a356028 100644 --- a/src/main/kotlin/net/pterodactylus/sone/template/LinkedElementRenderFilter.kt +++ b/src/main/kotlin/net/pterodactylus/sone/template/LinkedElementRenderFilter.kt @@ -14,8 +14,8 @@ import java.io.StringWriter class LinkedElementRenderFilter(private val templateContextFactory: TemplateContextFactory) : Filter { companion object { - private val loadedImageTemplate = """""".parse() - private val notLoadedImageTemplate = """""".parse() + private val loadedImageTemplate = """<%include linked/image.html>""".parse() + private val notLoadedImageTemplate = """<%include linked/notLoaded.html>""".parse() private fun String.parse() = StringReader(this).use { TemplateParser.parse(it) } } diff --git a/src/main/resources/templates/linked/image.html b/src/main/resources/templates/linked/image.html new file mode 100644 index 0000000..17fa28a --- /dev/null +++ b/src/main/resources/templates/linked/image.html @@ -0,0 +1 @@ + diff --git a/src/main/resources/templates/linked/notLoaded.html b/src/main/resources/templates/linked/notLoaded.html new file mode 100644 index 0000000..87ee516 --- /dev/null +++ b/src/main/resources/templates/linked/notLoaded.html @@ -0,0 +1 @@ + diff --git a/src/test/kotlin/net/pterodactylus/sone/template/LinkedElementRenderFilterTest.kt b/src/test/kotlin/net/pterodactylus/sone/template/LinkedElementRenderFilterTest.kt index c0c83b3..9127f58 100644 --- a/src/test/kotlin/net/pterodactylus/sone/template/LinkedElementRenderFilterTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/template/LinkedElementRenderFilterTest.kt @@ -1,6 +1,7 @@ package net.pterodactylus.sone.template import net.pterodactylus.sone.core.LinkedElement +import net.pterodactylus.util.template.ClassPathTemplateProvider import net.pterodactylus.util.template.HtmlFilter import net.pterodactylus.util.template.TemplateContextFactory import org.hamcrest.MatcherAssert.assertThat @@ -18,6 +19,7 @@ class LinkedElementRenderFilterTest { init { templateContextFactory.addFilter("html", HtmlFilter()) + templateContextFactory.addProvider(ClassPathTemplateProvider(LinkedElementRenderFilter::class.java, "/templates/")) } private val filter = LinkedElementRenderFilter(templateContextFactory)