From 047787883cea2957540331b4720d9a20167eb042 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 9 Mar 2019 17:57:53 +0100 Subject: [PATCH] =?utf8?q?=E2=99=BB=EF=B8=8F=20Create=20template=20context?= =?utf8?q?=20factory=20in=20render=20filter?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../sone/template/LinkedElementRenderFilter.kt | 8 +++++-- .../sone/template/LinkedElementRenderFilterTest.kt | 28 +++++++--------------- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/main/kotlin/net/pterodactylus/sone/template/LinkedElementRenderFilter.kt b/src/main/kotlin/net/pterodactylus/sone/template/LinkedElementRenderFilter.kt index b11dc79..200bd83 100644 --- a/src/main/kotlin/net/pterodactylus/sone/template/LinkedElementRenderFilter.kt +++ b/src/main/kotlin/net/pterodactylus/sone/template/LinkedElementRenderFilter.kt @@ -4,12 +4,16 @@ import net.pterodactylus.sone.core.* import net.pterodactylus.sone.utils.* import net.pterodactylus.util.template.* import java.io.* -import javax.inject.* /** * Renders all kinds of [LinkedElement]s. */ -class LinkedElementRenderFilter @Inject constructor(private val templateContextFactory: TemplateContextFactory) : Filter { +class LinkedElementRenderFilter : Filter { + + private val templateContextFactory = TemplateContextFactory().apply { + addFilter("html", HtmlFilter()) + addProvider(ClassPathTemplateProvider(LinkedElementRenderFilter::class.java, "/templates/")) + } override fun format(templateContext: TemplateContext?, data: Any?, parameters: Map?) = when { diff --git a/src/test/kotlin/net/pterodactylus/sone/template/LinkedElementRenderFilterTest.kt b/src/test/kotlin/net/pterodactylus/sone/template/LinkedElementRenderFilterTest.kt index 8ea0fa3..8363f6b 100644 --- a/src/test/kotlin/net/pterodactylus/sone/template/LinkedElementRenderFilterTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/template/LinkedElementRenderFilterTest.kt @@ -1,31 +1,21 @@ package net.pterodactylus.sone.template -import com.google.inject.Guice -import net.pterodactylus.sone.core.LinkedElement -import net.pterodactylus.sone.test.getInstance -import net.pterodactylus.sone.test.isProvidedByMock -import net.pterodactylus.util.template.ClassPathTemplateProvider -import net.pterodactylus.util.template.HtmlFilter -import net.pterodactylus.util.template.TemplateContextFactory -import org.hamcrest.MatcherAssert.assertThat -import org.jsoup.Jsoup -import org.jsoup.nodes.Element -import org.junit.Test +import com.google.inject.* +import net.pterodactylus.sone.core.* +import net.pterodactylus.sone.test.* +import net.pterodactylus.util.template.* +import org.hamcrest.MatcherAssert.* import org.hamcrest.Matchers.* +import org.jsoup.* +import org.jsoup.nodes.* +import org.junit.* /** * Unit test for [LinkedElementRenderFilter]. */ class LinkedElementRenderFilterTest { - private val templateContextFactory = TemplateContextFactory() - - init { - templateContextFactory.addFilter("html", HtmlFilter()) - templateContextFactory.addProvider(ClassPathTemplateProvider(LinkedElementRenderFilter::class.java, "/templates/")) - } - - private val filter = LinkedElementRenderFilter(templateContextFactory) + private val filter = LinkedElementRenderFilter() @Test fun `filter returns null for objects that are not linked elements`() { -- 2.7.4