From 2004b7e27c9ea1544f9413d18258569850135f04 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 22 Nov 2016 21:55:44 +0100 Subject: [PATCH] Include templates for rendering linked elements --- .../net/pterodactylus/sone/template/LinkedElementRenderFilter.kt | 4 ++-- src/main/resources/templates/linked/image.html | 1 + src/main/resources/templates/linked/notLoaded.html | 1 + .../net/pterodactylus/sone/template/LinkedElementRenderFilterTest.kt | 2 ++ 4 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 src/main/resources/templates/linked/image.html create mode 100644 src/main/resources/templates/linked/notLoaded.html 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) -- 2.7.4