From: David ‘Bombe’ Roden Date: Sat, 9 Mar 2019 16:57:53 +0000 (+0100) Subject: ♻️ Create template context factory in render filter X-Git-Tag: v79^2~75 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=047787883cea2957540331b4720d9a20167eb042;p=Sone.git ♻️ Create template context factory in render filter --- 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`() {