✨ Use new template renderer
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 17 May 2019 19:16:42 +0000 (21:16 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 17 May 2019 19:16:42 +0000 (21:16 +0200)
52 files changed:
src/main/java/net/pterodactylus/sone/web/WebInterface.java
src/main/kotlin/net/pterodactylus/sone/web/page/FreenetTemplatePage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/AboutPage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/BookmarkPage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/BookmarksPage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/CreateAlbumPage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/CreatePostPage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/CreateReplyPage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/CreateSonePage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteAlbumPage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteImagePage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/DeletePostPage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteProfileFieldPage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteReplyPage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteSonePage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/DismissNotificationPage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/DistrustPage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/EditAlbumPage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/EditImagePage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/EditProfileFieldPage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/EditProfilePage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/FollowSonePage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/IndexPage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/KnownSonesPage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/LikePage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/LockSonePage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/LoggedInPage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/LoginPage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/LogoutPage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/MarkAsKnownPage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/NewPage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/OptionsPage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/RescuePage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/SearchPage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/SoneTemplatePage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/TrustPage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/UnbookmarkPage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/UnfollowSonePage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/UnlikePage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/UnlockSonePage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/UntrustPage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/UploadImagePage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/ViewPostPage.kt
src/main/kotlin/net/pterodactylus/sone/web/pages/ViewSonePage.kt
src/test/java/net/pterodactylus/sone/web/AllPagesTest.kt
src/test/kotlin/net/pterodactylus/sone/web/page/FreenetTemplatePageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/pages/AboutPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/pages/IndexPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/pages/SearchPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/pages/SoneTemplatePageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest.kt

index d4f3f55..efc4291 100644 (file)
@@ -112,6 +112,7 @@ import net.pterodactylus.sone.web.ajax.UnlikeAjaxPage;
 import net.pterodactylus.sone.web.ajax.UnlockSoneAjaxPage;
 import net.pterodactylus.sone.web.ajax.UntrustAjaxPage;
 import net.pterodactylus.sone.web.page.FreenetRequest;
+import net.pterodactylus.sone.web.page.TemplateRenderer;
 import net.pterodactylus.sone.web.pages.AboutPage;
 import net.pterodactylus.sone.web.pages.BookmarkPage;
 import net.pterodactylus.sone.web.pages.BookmarksPage;
@@ -197,6 +198,7 @@ public class WebInterface implements SessionProvider {
 
        /** The template context factory. */
        private final TemplateContextFactory templateContextFactory;
+       private final TemplateRenderer templateRenderer;
 
        /** The Sone text parser. */
        private final SoneTextParser soneTextParser;
@@ -263,6 +265,7 @@ public class WebInterface implements SessionProvider {
        public WebInterface(SonePlugin sonePlugin, Loaders loaders, ListNotificationFilter listNotificationFilter,
                        PostVisibilityFilter postVisibilityFilter, ReplyVisibilityFilter replyVisibilityFilter,
                        ElementLoader elementLoader, TemplateContextFactory templateContextFactory,
+                       TemplateRenderer templateRenderer,
                        ParserFilter parserFilter, ShortenFilter shortenFilter,
                        RenderFilter renderFilter,
                        LinkedElementRenderFilter linkedElementRenderFilter,
@@ -273,6 +276,7 @@ public class WebInterface implements SessionProvider {
                this.postVisibilityFilter = postVisibilityFilter;
                this.replyVisibilityFilter = replyVisibilityFilter;
                this.elementLoader = elementLoader;
+               this.templateRenderer = templateRenderer;
                this.parserFilter = parserFilter;
                this.shortenFilter = shortenFilter;
                this.renderFilter = renderFilter;
@@ -635,51 +639,51 @@ public class WebInterface implements SessionProvider {
                Template openSearchTemplate = loaders.loadTemplate("/templates/xml/OpenSearch.xml");
 
                pageToadletRegistry.addPage(new RedirectPage<FreenetRequest>("", "index.html"));
-               pageToadletRegistry.addPage(new IndexPage(indexTemplate, this, loaders, postVisibilityFilter));
-               pageToadletRegistry.addPage(new NewPage(newTemplate, this, loaders));
-               pageToadletRegistry.addPage(new CreateSonePage(createSoneTemplate, this, loaders));
-               pageToadletRegistry.addPage(new KnownSonesPage(knownSonesTemplate, this, loaders));
-               pageToadletRegistry.addPage(new EditProfilePage(editProfileTemplate, this, loaders));
-               pageToadletRegistry.addPage(new EditProfileFieldPage(editProfileFieldTemplate, this, loaders));
-               pageToadletRegistry.addPage(new DeleteProfileFieldPage(deleteProfileFieldTemplate, this, loaders));
-               pageToadletRegistry.addPage(new CreatePostPage(createPostTemplate, this, loaders));
-               pageToadletRegistry.addPage(new CreateReplyPage(createReplyTemplate, this, loaders));
-               pageToadletRegistry.addPage(new ViewSonePage(viewSoneTemplate, this, loaders));
-               pageToadletRegistry.addPage(new ViewPostPage(viewPostTemplate, this, loaders));
-               pageToadletRegistry.addPage(new LikePage(emptyTemplate, this, loaders));
-               pageToadletRegistry.addPage(new UnlikePage(emptyTemplate, this, loaders));
-               pageToadletRegistry.addPage(new DeletePostPage(deletePostTemplate, this, loaders));
-               pageToadletRegistry.addPage(new DeleteReplyPage(deleteReplyTemplate, this, loaders));
-               pageToadletRegistry.addPage(new LockSonePage(emptyTemplate, this, loaders));
-               pageToadletRegistry.addPage(new UnlockSonePage(emptyTemplate, this, loaders));
-               pageToadletRegistry.addPage(new FollowSonePage(emptyTemplate, this, loaders));
-               pageToadletRegistry.addPage(new UnfollowSonePage(emptyTemplate, this, loaders));
-               pageToadletRegistry.addPage(new ImageBrowserPage(imageBrowserTemplate, this, loaders));
-               pageToadletRegistry.addPage(new CreateAlbumPage(createAlbumTemplate, this, loaders));
-               pageToadletRegistry.addPage(new EditAlbumPage(emptyTemplate, this, loaders));
-               pageToadletRegistry.addPage(new DeleteAlbumPage(deleteAlbumTemplate, this, loaders));
-               pageToadletRegistry.addPage(new UploadImagePage(invalidTemplate, this, loaders));
-               pageToadletRegistry.addPage(new EditImagePage(emptyTemplate, this, loaders));
-               pageToadletRegistry.addPage(new DeleteImagePage(deleteImageTemplate, this, loaders));
-               pageToadletRegistry.addPage(new TrustPage(emptyTemplate, this, loaders));
-               pageToadletRegistry.addPage(new DistrustPage(emptyTemplate, this, loaders));
-               pageToadletRegistry.addPage(new UntrustPage(emptyTemplate, this, loaders));
-               pageToadletRegistry.addPage(new MarkAsKnownPage(emptyTemplate, this, loaders));
-               pageToadletRegistry.addPage(new BookmarkPage(emptyTemplate, this, loaders));
-               pageToadletRegistry.addPage(new UnbookmarkPage(emptyTemplate, this, loaders));
-               pageToadletRegistry.addPage(new BookmarksPage(bookmarksTemplate, this, loaders));
-               pageToadletRegistry.addPage(new SearchPage(searchTemplate, this, loaders));
-               pageToadletRegistry.addPage(new DeleteSonePage(deleteSoneTemplate, this, loaders));
-               pageToadletRegistry.addPage(new LoginPage(loginTemplate, this, loaders));
-               pageToadletRegistry.addPage(new LogoutPage(emptyTemplate, this, loaders));
-               pageToadletRegistry.addPage(new OptionsPage(optionsTemplate, this, loaders));
-               pageToadletRegistry.addPage(new RescuePage(rescueTemplate, this, loaders));
-               pageToadletRegistry.addPage(new AboutPage(aboutTemplate, this, loaders, new PluginVersion(SonePlugin.getPluginVersion()), new PluginYear(sonePlugin.getYear()), new PluginHomepage(sonePlugin.getHomepage())));
-               pageToadletRegistry.addPage(new SoneTemplatePage("noPermission.html", this, loaders, noPermissionTemplate, "Page.NoPermission.Title"));
-               pageToadletRegistry.addPage(new SoneTemplatePage("emptyImageTitle.html", this, loaders, emptyImageTitleTemplate, "Page.EmptyImageTitle.Title"));
-               pageToadletRegistry.addPage(new SoneTemplatePage("emptyAlbumTitle.html", this, loaders, emptyAlbumTitleTemplate, "Page.EmptyAlbumTitle.Title"));
-               pageToadletRegistry.addPage(new DismissNotificationPage(emptyTemplate, this, loaders));
-               pageToadletRegistry.addPage(new SoneTemplatePage("invalid.html", this, loaders, invalidTemplate, "Page.Invalid.Title"));
+               pageToadletRegistry.addPage(new IndexPage(indexTemplate, this, loaders, templateRenderer, postVisibilityFilter));
+               pageToadletRegistry.addPage(new NewPage(newTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new CreateSonePage(createSoneTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new KnownSonesPage(knownSonesTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new EditProfilePage(editProfileTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new EditProfileFieldPage(editProfileFieldTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new DeleteProfileFieldPage(deleteProfileFieldTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new CreatePostPage(createPostTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new CreateReplyPage(createReplyTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new ViewSonePage(viewSoneTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new ViewPostPage(viewPostTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new LikePage(emptyTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new UnlikePage(emptyTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new DeletePostPage(deletePostTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new DeleteReplyPage(deleteReplyTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new LockSonePage(emptyTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new UnlockSonePage(emptyTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new FollowSonePage(emptyTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new UnfollowSonePage(emptyTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new ImageBrowserPage(imageBrowserTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new CreateAlbumPage(createAlbumTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new EditAlbumPage(emptyTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new DeleteAlbumPage(deleteAlbumTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new UploadImagePage(invalidTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new EditImagePage(emptyTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new DeleteImagePage(deleteImageTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new TrustPage(emptyTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new DistrustPage(emptyTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new UntrustPage(emptyTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new MarkAsKnownPage(emptyTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new BookmarkPage(emptyTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new UnbookmarkPage(emptyTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new BookmarksPage(bookmarksTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new SearchPage(searchTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new DeleteSonePage(deleteSoneTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new LoginPage(loginTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new LogoutPage(emptyTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new OptionsPage(optionsTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new RescuePage(rescueTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new AboutPage(aboutTemplate, this, loaders, templateRenderer, new PluginVersion(SonePlugin.getPluginVersion()), new PluginYear(sonePlugin.getYear()), new PluginHomepage(sonePlugin.getHomepage())));
+               pageToadletRegistry.addPage(new SoneTemplatePage("noPermission.html", this, loaders, noPermissionTemplate, templateRenderer, "Page.NoPermission.Title"));
+               pageToadletRegistry.addPage(new SoneTemplatePage("emptyImageTitle.html", this, loaders, emptyImageTitleTemplate, templateRenderer, "Page.EmptyImageTitle.Title"));
+               pageToadletRegistry.addPage(new SoneTemplatePage("emptyAlbumTitle.html", this, loaders, emptyAlbumTitleTemplate, templateRenderer, "Page.EmptyAlbumTitle.Title"));
+               pageToadletRegistry.addPage(new DismissNotificationPage(emptyTemplate, this, loaders, templateRenderer));
+               pageToadletRegistry.addPage(new SoneTemplatePage("invalid.html", this, loaders, invalidTemplate, templateRenderer, "Page.Invalid.Title"));
                pageToadletRegistry.addPage(loaders.<FreenetRequest>loadStaticPage("css/", "/static/css/", "text/css"));
                pageToadletRegistry.addPage(loaders.<FreenetRequest>loadStaticPage("javascript/", "/static/javascript/", "text/javascript"));
                pageToadletRegistry.addPage(loaders.<FreenetRequest>loadStaticPage("images/", "/static/images/", "image/png"));
index 792c0ba..c9ec173 100644 (file)
@@ -21,7 +21,6 @@ import freenet.clients.http.*
 import net.pterodactylus.sone.main.*
 import net.pterodactylus.util.template.*
 import net.pterodactylus.util.web.*
-import java.io.*
 import java.lang.String.*
 import java.net.*
 import java.util.logging.*
@@ -33,7 +32,7 @@ import java.util.logging.Logger.*
  */
 open class FreenetTemplatePage(
                private val path: String,
-               private val templateContextFactory: TemplateContextFactory,
+               private val templateRenderer: TemplateRenderer,
                loaders: Loaders,
                template: Template,
                private val invalidFormPasswordRedirectTarget: String
@@ -84,20 +83,19 @@ open class FreenetTemplatePage(
                                }
                shortcutIcon?.let { pageNode.addForwardLink("icon", it) }
 
-               val templateContext = templateContextFactory.createTemplateContext()
-               templateContext.mergeContext(template.initialContext)
-               try {
+               val output = try {
                        val start = System.nanoTime()
-                       processTemplate(request, templateContext)
-                       val finish = System.nanoTime()
-                       logger.log(Level.FINEST, format("Template was rendered in %.2fms.", (finish - start) / 1000000.0))
+                       templateRenderer.render(template) { templateContext ->
+                               processTemplate(request, templateContext)
+                       }.also {
+                               val finish = System.nanoTime()
+                               logger.log(Level.FINEST, format("Template was rendered in %.2fms.", (finish - start) / 1000000.0))
+                       }
                } catch (re1: RedirectException) {
                        return RedirectResponse(re1.target ?: "")
                }
 
-               val stringWriter = StringWriter()
-               template.render(templateContext, stringWriter)
-               pageNode.content.addChild("%", stringWriter.toString())
+               pageNode.content.addChild("%", output)
 
                return response.setStatusCode(200).setStatusText("OK").setContentType("text/html").write(pageNode.outer.generate())
        }
index 26a1769..3e2820e 100644 (file)
@@ -11,10 +11,10 @@ import javax.inject.Inject
  * A [SoneTemplatePage] that stores information about Sone in the [TemplateContext].
  */
 @MenuName("About")
-class AboutPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders,
+class AboutPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer,
                private val pluginVersion: PluginVersion,
                private val pluginYear: PluginYear,
-               private val pluginHomepage: PluginHomepage): SoneTemplatePage("about.html", webInterface, loaders, template = template, pageTitleKey = "Page.About.Title") {
+               private val pluginHomepage: PluginHomepage): SoneTemplatePage("about.html", webInterface, loaders, template, templateRenderer, pageTitleKey = "Page.About.Title") {
 
        override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
                templateContext["version"] = pluginVersion.version
index c1415b0..c85c3ba 100644 (file)
@@ -11,8 +11,8 @@ import javax.inject.Inject
 /**
  * Page that lets the user bookmark a post.
  */
-class BookmarkPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders)
-       : SoneTemplatePage("bookmark.html", webInterface, loaders, template = template, pageTitleKey = "Page.Bookmark.Title") {
+class BookmarkPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer)
+       : SoneTemplatePage("bookmark.html", webInterface, loaders, template, templateRenderer, pageTitleKey = "Page.Bookmark.Title") {
 
        override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
                if (soneRequest.isPOST) {
index f178e61..c021d0a 100644 (file)
@@ -13,8 +13,8 @@ import javax.inject.Inject
  * Page that lets the user browse all his bookmarked posts.
  */
 @MenuName("Bookmarks")
-class BookmarksPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders) :
-               SoneTemplatePage("bookmarks.html", webInterface, loaders, template = template, pageTitleKey = "Page.Bookmarks.Title") {
+class BookmarksPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) :
+               SoneTemplatePage("bookmarks.html", webInterface, loaders, template, templateRenderer, pageTitleKey = "Page.Bookmarks.Title") {
 
        override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
                soneRequest.core.bookmarkedPosts.let { posts ->
index 452d5a4..3ffd622 100644 (file)
@@ -14,8 +14,8 @@ import javax.inject.Inject
 /**
  * Page that lets the user create a new album.
  */
-class CreateAlbumPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders):
-               LoggedInPage("createAlbum.html", template, "Page.CreateAlbum.Title", webInterface, loaders) {
+class CreateAlbumPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
+               LoggedInPage("createAlbum.html", template, "Page.CreateAlbum.Title", webInterface, loaders, templateRenderer) {
 
        override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
                if (soneRequest.isPOST) {
index 37568f2..9f57ef5 100644 (file)
@@ -14,8 +14,8 @@ import javax.inject.Inject
 /**
  * This page lets the user create a new [Post].
  */
-class CreatePostPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders):
-               LoggedInPage("createPost.html", template, "Page.CreatePost.Title", webInterface, loaders) {
+class CreatePostPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
+               LoggedInPage("createPost.html", template, "Page.CreatePost.Title", webInterface, loaders, templateRenderer) {
 
        override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
                val returnPage = soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)
index 599a9ec..3e8bc72 100644 (file)
@@ -13,8 +13,8 @@ import javax.inject.Inject
 /**
  * This page lets the user post a reply to a post.
  */
-class CreateReplyPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders):
-               LoggedInPage("createReply.html", template, "Page.CreateReply.Title", webInterface, loaders) {
+class CreateReplyPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
+               LoggedInPage("createReply.html", template, "Page.CreateReply.Title", webInterface, loaders, templateRenderer) {
 
        override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
                val postId = soneRequest.httpRequest.getPartAsStringFailsafe("post", 36).apply { templateContext["postId"] = this }
index cb4822b..0acc0bd 100644 (file)
@@ -16,8 +16,8 @@ import javax.inject.Inject
  * The “create Sone” page lets the user create a new Sone.
  */
 @MenuName("CreateSone")
-class CreateSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders):
-               SoneTemplatePage("createSone.html", webInterface, loaders, template = template, pageTitleKey = "Page.CreateSone.Title") {
+class CreateSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
+               SoneTemplatePage("createSone.html", webInterface, loaders, template, templateRenderer, pageTitleKey = "Page.CreateSone.Title") {
 
        private val logger = Logger.getLogger(CreateSonePage::class.java.name)
 
index 4c1b28b..b1969cc 100644 (file)
@@ -12,8 +12,8 @@ import javax.inject.Inject
 /**
  * Page that lets the user delete an {@link Album}.
  */
-class DeleteAlbumPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders):
-               LoggedInPage("deleteAlbum.html", template, "Page.DeleteAlbum.Title", webInterface, loaders) {
+class DeleteAlbumPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
+               LoggedInPage("deleteAlbum.html", template, "Page.DeleteAlbum.Title", webInterface, loaders, templateRenderer) {
 
        override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
                if (soneRequest.isPOST) {
index 11efd94..755cfaa 100644 (file)
@@ -12,8 +12,8 @@ import javax.inject.Inject
 /**
  * Page that lets the user delete an {@link Image}.
  */
-class DeleteImagePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders):
-               LoggedInPage("deleteImage.html", template, "Page.DeleteImage.Title", webInterface, loaders) {
+class DeleteImagePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
+               LoggedInPage("deleteImage.html", template, "Page.DeleteImage.Title", webInterface, loaders, templateRenderer) {
 
        override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
                if (soneRequest.isPOST) {
index b03d768..f9daed5 100644 (file)
@@ -12,8 +12,8 @@ import javax.inject.Inject
 /**
  * Lets the user delete a post they made.
  */
-class DeletePostPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders):
-               LoggedInPage("deletePost.html", template, "Page.DeletePost.Title", webInterface, loaders) {
+class DeletePostPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
+               LoggedInPage("deletePost.html", template, "Page.DeletePost.Title", webInterface, loaders, templateRenderer) {
 
        override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
                if (soneRequest.isPOST) {
index 5f57bea..49cdbdf 100644 (file)
@@ -12,8 +12,8 @@ import javax.inject.Inject
 /**
  * Page that lets the user confirm the deletion of a profile field.
  */
-class DeleteProfileFieldPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders):
-               LoggedInPage("deleteProfileField.html", template, "Page.DeleteProfileField.Title", webInterface, loaders) {
+class DeleteProfileFieldPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
+               LoggedInPage("deleteProfileField.html", template, "Page.DeleteProfileField.Title", webInterface, loaders, templateRenderer) {
 
        override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
                if (soneRequest.isPOST) {
index af62489..85f1f21 100644 (file)
@@ -12,8 +12,8 @@ import javax.inject.Inject
 /**
  * This page lets the user delete a reply.
  */
-class DeleteReplyPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders):
-               LoggedInPage("deleteReply.html", template, "Page.DeleteReply.Title", webInterface, loaders) {
+class DeleteReplyPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
+               LoggedInPage("deleteReply.html", template, "Page.DeleteReply.Title", webInterface, loaders, templateRenderer) {
 
        override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
                if (soneRequest.isPOST) {
index c301869..ceaa1e2 100644 (file)
@@ -15,8 +15,8 @@ import javax.inject.Inject
  * installation.
  */
 @MenuName("DeleteSone")
-class DeleteSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders):
-               LoggedInPage("deleteSone.html", template, "Page.DeleteSone.Title", webInterface, loaders) {
+class DeleteSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
+               LoggedInPage("deleteSone.html", template, "Page.DeleteSone.Title", webInterface, loaders, templateRenderer) {
 
        override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
                if (soneRequest.isPOST) {
index c7880bc..f240665 100644 (file)
@@ -10,8 +10,8 @@ import javax.inject.Inject
 /**
  * Page that lets the user dismiss a notification.
  */
-class DismissNotificationPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders):
-               SoneTemplatePage("dismissNotification.html", webInterface, loaders, template = template, pageTitleKey = "Page.DismissNotification.Title") {
+class DismissNotificationPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
+               SoneTemplatePage("dismissNotification.html", webInterface, loaders, template, templateRenderer, pageTitleKey = "Page.DismissNotification.Title") {
 
        override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
                val returnPage = soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)
index 1fee1e8..051ac38 100644 (file)
@@ -15,8 +15,8 @@ import javax.inject.Inject
  *
  * @see net.pterodactylus.sone.core.Core#distrustSone(Sone, Sone)
  */
-class DistrustPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders):
-               LoggedInPage("distrust.html", template, "Page.Distrust.Title", webInterface, loaders) {
+class DistrustPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
+               LoggedInPage("distrust.html", template, "Page.Distrust.Title", webInterface, loaders, templateRenderer) {
 
        override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
                if (soneRequest.isPOST) {
index 58bbb67..668f6eb 100644 (file)
@@ -13,8 +13,8 @@ import javax.inject.Inject
 /**
  * Page that lets the user edit the name and description of an album.
  */
-class EditAlbumPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders):
-               LoggedInPage("editAlbum.html", template, "Page.EditAlbum.Title", webInterface, loaders) {
+class EditAlbumPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
+               LoggedInPage("editAlbum.html", template, "Page.EditAlbum.Title", webInterface, loaders, templateRenderer) {
 
        override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
                if (soneRequest.isPOST) {
index c6c6acb..d55a7be 100644 (file)
@@ -14,8 +14,8 @@ import javax.inject.Inject
 /**
  * Page that lets the user edit title and description of an {@link Image}.
  */
-class EditImagePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders):
-               LoggedInPage("editImage.html", template, "Page.EditImage.Title", webInterface, loaders) {
+class EditImagePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
+               LoggedInPage("editImage.html", template, "Page.EditImage.Title", webInterface, loaders, templateRenderer) {
 
        override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
                if (soneRequest.isPOST) {
index 580ee72..0ea1fb7 100644 (file)
@@ -12,8 +12,8 @@ import javax.inject.Inject
 /**
  * Page that lets the user edit the name of a profile field.
  */
-class EditProfileFieldPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders) :
-               LoggedInPage("editProfileField.html", template, "Page.EditProfileField.Title", webInterface, loaders) {
+class EditProfileFieldPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) :
+               LoggedInPage("editProfileField.html", template, "Page.EditProfileField.Title", webInterface, loaders, templateRenderer) {
 
        override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
                currentSone.profile.let { profile ->
index f25b5b3..b7524d0 100644 (file)
@@ -15,8 +15,8 @@ import javax.inject.Inject
  * This page lets the user edit her profile.
  */
 @MenuName("EditProfile")
-class EditProfilePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders) :
-               LoggedInPage("editProfile.html", template, "Page.EditProfile.Title", webInterface, loaders) {
+class EditProfilePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) :
+               LoggedInPage("editProfile.html", template, "Page.EditProfile.Title", webInterface, loaders, templateRenderer) {
 
        override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
                currentSone.profile.let { profile ->
index f4aa2e0..4747715 100644 (file)
@@ -12,8 +12,8 @@ import javax.inject.Inject
 /**
  * This page lets the user follow another Sone.
  */
-class FollowSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders):
-               LoggedInPage("followSone.html", template, "Page.FollowSone.Title", webInterface, loaders) {
+class FollowSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
+               LoggedInPage("followSone.html", template, "Page.FollowSone.Title", webInterface, loaders, templateRenderer) {
 
        override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
                if (soneRequest.isPOST) {
index e2b2ec2..5a5959e 100644 (file)
@@ -16,8 +16,8 @@ import javax.inject.Inject
  * The image browser page is the entry page for the image management.
  */
 @MenuName("ImageBrowser")
-class ImageBrowserPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders):
-               LoggedInPage("imageBrowser.html", template, "Page.ImageBrowser.Title", webInterface, loaders) {
+class ImageBrowserPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
+               LoggedInPage("imageBrowser.html", template, "Page.ImageBrowser.Title", webInterface, loaders, templateRenderer) {
 
        override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
                if ("album" in soneRequest.parameters) {
index aefef39..a6a5683 100644 (file)
@@ -16,8 +16,8 @@ import javax.inject.Inject
  * of all friends of the current user.
  */
 @MenuName("Index")
-class IndexPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, private val postVisibilityFilter: PostVisibilityFilter) :
-               LoggedInPage("index.html", template, "Page.Index.Title", webInterface, loaders) {
+class IndexPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer, private val postVisibilityFilter: PostVisibilityFilter) :
+               LoggedInPage("index.html", template, "Page.Index.Title", webInterface, loaders, templateRenderer) {
 
        override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
                (currentSone.posts +
index 65f4853..0e890cc 100644 (file)
@@ -14,8 +14,8 @@ import javax.inject.Inject
  * This page shows all known Sones.
  */
 @MenuName("KnownSones")
-class KnownSonesPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders):
-               SoneTemplatePage("knownSones.html", webInterface, loaders, template = template, pageTitleKey = "Page.KnownSones.Title") {
+class KnownSonesPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
+               SoneTemplatePage("knownSones.html", webInterface, loaders, template, templateRenderer, pageTitleKey = "Page.KnownSones.Title") {
 
        override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
                getCurrentSone(soneRequest.toadletContext).let { currentSone ->
index 3b0d0c5..4db5099 100644 (file)
@@ -13,8 +13,8 @@ import javax.inject.Inject
 /**
  * Page that lets the user like [net.pterodactylus.sone.data.Post]s and [net.pterodactylus.sone.data.Reply]s.
  */
-class LikePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders) :
-               LoggedInPage("like.html", template, "Page.Like.Title", webInterface, loaders) {
+class LikePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) :
+               LoggedInPage("like.html", template, "Page.Like.Title", webInterface, loaders, templateRenderer) {
 
        override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
                if (soneRequest.isPOST) {
index 2d14ff3..1c7faa9 100644 (file)
@@ -11,8 +11,8 @@ import javax.inject.Inject
 /**
  * This page lets the user lock a [net.pterodactylus.sone.data.Sone] to prevent it from being inserted.
  */
-class LockSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders):
-               SoneTemplatePage("lockSone.html", webInterface, loaders, template = template, pageTitleKey = "Page.LockSone.Title") {
+class LockSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
+               SoneTemplatePage("lockSone.html", webInterface, loaders, template, templateRenderer, pageTitleKey = "Page.LockSone.Title") {
 
        override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
                soneRequest.parameters["returnPage", 256]!!.let { returnPage ->
index 72b5822..3e3ad4a 100644 (file)
@@ -10,8 +10,8 @@ import net.pterodactylus.util.template.TemplateContext
 /**
  * Base class for [SoneTemplatePage] implementations that require a logged in user.
  */
-abstract class LoggedInPage(path: String, template: Template, pageTitleKey: String, webInterface: WebInterface, loaders: Loaders) :
-               SoneTemplatePage(path, webInterface, loaders, template = template, pageTitleKey = pageTitleKey, requiresLogin = true) {
+abstract class LoggedInPage(path: String, template: Template, pageTitleKey: String, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) :
+               SoneTemplatePage(path, webInterface, loaders, template, templateRenderer, pageTitleKey = pageTitleKey, requiresLogin = true) {
 
        final override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
                handleRequest(soneRequest, getCurrentSone(soneRequest.toadletContext, false)!!, templateContext)
index 70b96fc..8f65b33 100644 (file)
@@ -15,8 +15,8 @@ import javax.inject.Inject
  * The login page lets the user log in.
  */
 @MenuName("Login")
-class LoginPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders):
-               SoneTemplatePage("login.html", webInterface, loaders, template = template, pageTitleKey = "Page.Login.Title") {
+class LoginPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
+               SoneTemplatePage("login.html", webInterface, loaders, template, templateRenderer, pageTitleKey = "Page.Login.Title") {
 
        override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
                if (soneRequest.isPOST) {
index bfab7c8..38ce74f 100644 (file)
@@ -13,8 +13,8 @@ import javax.inject.Inject
  * Logs a user out.
  */
 @MenuName("Logout")
-class LogoutPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders):
-               LoggedInPage("logout.html", template, "Page.Logout.Title", webInterface, loaders) {
+class LogoutPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
+               LoggedInPage("logout.html", template, "Page.Logout.Title", webInterface, loaders, templateRenderer) {
 
        override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
                setCurrentSone(soneRequest.toadletContext, null)
index 22f21d8..17fe0cf 100644 (file)
@@ -12,8 +12,8 @@ import javax.inject.*
  * Page that lets the user mark a number of [net.pterodactylus.sone.data.Sone]s, [Post]s, or
  * [Replie][net.pterodactylus.sone.data.Reply]s as known.
  */
-class MarkAsKnownPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders):
-               SoneTemplatePage("markAsKnown.html", webInterface, loaders, template = template, pageTitleKey = "Page.MarkAsKnown.Title") {
+class MarkAsKnownPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
+               SoneTemplatePage("markAsKnown.html", webInterface, loaders, template, templateRenderer, pageTitleKey = "Page.MarkAsKnown.Title") {
 
        override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
                val ids = soneRequest.parameters["id", 65536]!!.split(" ")
index d464db7..874c157 100644 (file)
@@ -15,8 +15,8 @@ import javax.inject.Inject
  * [PostVisibilityFilter.isPostVisible(Sone, Post)] and sorted by time.
  */
 @MenuName("New")
-class NewPage @Inject constructor(  template: Template, webInterface: WebInterface, loaders: Loaders):
-               SoneTemplatePage("new.html", webInterface, loaders, template = template, pageTitleKey = "Page.New.Title") {
+class NewPage @Inject constructor(  template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
+               SoneTemplatePage("new.html", webInterface, loaders, template, templateRenderer, pageTitleKey = "Page.New.Title") {
 
        override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) =
                        getCurrentSone(soneRequest.toadletContext).let { currentSone ->
index f8049a3..708b918 100644 (file)
@@ -17,8 +17,8 @@ import javax.inject.Inject
  * This page lets the user edit the options of the Sone plugin.
  */
 @MenuName("Options")
-class OptionsPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders):
-               SoneTemplatePage("options.html", webInterface, loaders, template = template, pageTitleKey = "Page.Options.Title") {
+class OptionsPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
+               SoneTemplatePage("options.html", webInterface, loaders, template, templateRenderer, pageTitleKey = "Page.Options.Title") {
 
        override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
                if (soneRequest.isPOST) {
index ce25b7d..6546bdc 100644 (file)
@@ -14,8 +14,8 @@ import javax.inject.Inject
  * Page that lets the user control the rescue mode for a Sone.
  */
 @MenuName("Rescue")
-class RescuePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders):
-               LoggedInPage("rescue.html", template, "Page.Rescue.Title", webInterface, loaders) {
+class RescuePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
+               LoggedInPage("rescue.html", template, "Page.Rescue.Title", webInterface, loaders, templateRenderer) {
 
        override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
                val soneRescuer = soneRequest.core.getSoneRescuer(currentSone)
index d980072..b44a94e 100644 (file)
@@ -29,11 +29,11 @@ import javax.inject.Inject
  * This page lets the user search for posts and replies that contain certain
  * words.
  */
-class SearchPage(template: Template, webInterface: WebInterface, loaders: Loaders, ticker: Ticker = Ticker.systemTicker()) :
-               SoneTemplatePage("search.html", webInterface, loaders, template = template, pageTitleKey = "Page.Search.Title") {
+class SearchPage(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer, ticker: Ticker = Ticker.systemTicker()) :
+               SoneTemplatePage("search.html", webInterface, loaders, template, templateRenderer, pageTitleKey = "Page.Search.Title") {
 
-       @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders) :
-                       this(template, webInterface, loaders, Ticker.systemTicker())
+       @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) :
+                       this(template, webInterface, loaders, templateRenderer, Ticker.systemTicker())
 
        private val cache: Cache<Iterable<Phrase>, Pagination<Post>> = CacheBuilder.newBuilder().ticker(ticker).expireAfterAccess(5, MINUTES).build()
 
index 1d1ccf1..3c3e98a 100644 (file)
@@ -21,10 +21,11 @@ open class SoneTemplatePage @JvmOverloads constructor(
                private val webInterface: WebInterface,
                loaders: Loaders,
                template: Template,
+               templateRenderer: TemplateRenderer,
                private val pageTitleKey: String? = null,
                private val requiresLogin: Boolean = false,
                private val pageTitle: (FreenetRequest) -> String = { pageTitleKey?.let(webInterface.l10n::getString) ?: "" }
-) : FreenetTemplatePage(path, webInterface.templateContextFactory, loaders, template, "noPermission.html") {
+) : FreenetTemplatePage(path, templateRenderer, loaders, template, "noPermission.html") {
 
        private val core = webInterface.core
        private val sessionProvider: SessionProvider = webInterface
index 93ccad0..5d6abf3 100644 (file)
@@ -14,8 +14,8 @@ import javax.inject.Inject
  * Page that lets the user trust another Sone. This will assign a configurable
  * amount of trust to an identity.
  */
-class TrustPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders) :
-               LoggedInPage("trust.html", template, "Page.Trust.Title", webInterface, loaders) {
+class TrustPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) :
+               LoggedInPage("trust.html", template, "Page.Trust.Title", webInterface, loaders, templateRenderer) {
 
        override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
                if (soneRequest.isPOST) {
index 804390e..aed315f 100644 (file)
@@ -11,8 +11,8 @@ import javax.inject.*
 /**
  * Page that lets the user unbookmark a post.
  */
-class UnbookmarkPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders):
-               SoneTemplatePage("unbookmark.html", webInterface, loaders, template = template, pageTitleKey = "Page.Unbookmark.Title") {
+class UnbookmarkPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
+               SoneTemplatePage("unbookmark.html", webInterface, loaders, template, templateRenderer, pageTitleKey = "Page.Unbookmark.Title") {
 
        override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
                when {
index 39b9749..20cb2b2 100644 (file)
@@ -13,8 +13,8 @@ import javax.inject.Inject
 /**
  * This page lets the user unfollow another Sone.
  */
-class UnfollowSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders) :
-               LoggedInPage("unfollowSone.html", template, "Page.UnfollowSone.Title", webInterface, loaders) {
+class UnfollowSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) :
+               LoggedInPage("unfollowSone.html", template, "Page.UnfollowSone.Title", webInterface, loaders, templateRenderer) {
 
        override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
                if (soneRequest.isPOST) {
index cfb072e..7737638 100644 (file)
@@ -13,8 +13,8 @@ import javax.inject.Inject
 /**
  * Page that lets the user unlike a [net.pterodactylus.sone.data.Post] or [net.pterodactylus.sone.data.Reply].
  */
-class UnlikePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders):
-               LoggedInPage("unlike.html", template, "Page.Unlike.Title", webInterface, loaders) {
+class UnlikePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
+               LoggedInPage("unlike.html", template, "Page.Unlike.Title", webInterface, loaders, templateRenderer) {
 
        override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
                if (soneRequest.isPOST) {
index b39c9da..0c44b3b 100644 (file)
@@ -12,8 +12,8 @@ import javax.inject.Inject
 /**
  * This page lets the user unlock a [net.pterodactylus.sone.data.Sone] to allow its insertion.
  */
-class UnlockSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders):
-               SoneTemplatePage("unlockSone.html", webInterface, loaders, template = template, pageTitleKey = "Page.UnlockSone.Title") {
+class UnlockSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
+               SoneTemplatePage("unlockSone.html", webInterface, loaders, template, templateRenderer, pageTitleKey = "Page.UnlockSone.Title") {
 
        override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
                if (soneRequest.isPOST) {
index b9ed794..ffc066d 100644 (file)
@@ -14,8 +14,8 @@ import javax.inject.Inject
  * Page that lets the user untrust another Sone. This will remove all trust
  * assignments for an identity.
  */
-class UntrustPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders) :
-               LoggedInPage("untrust.html", template, "Page.Untrust.Title", webInterface, loaders) {
+class UntrustPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) :
+               LoggedInPage("untrust.html", template, "Page.Untrust.Title", webInterface, loaders, templateRenderer) {
 
        override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
                if (soneRequest.isPOST) {
index fcc1a0a..0a31e4f 100644 (file)
@@ -22,8 +22,8 @@ import javax.inject.Inject
 /**
  * Page implementation that lets the user upload an image.
  */
-class UploadImagePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders):
-               LoggedInPage("uploadImage.html", template, "Page.UploadImage.Title", webInterface, loaders) {
+class UploadImagePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
+               LoggedInPage("uploadImage.html", template, "Page.UploadImage.Title", webInterface, loaders, templateRenderer) {
 
        override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
                if (soneRequest.isPOST) {
index f3a5dd1..1067698 100644 (file)
@@ -12,8 +12,8 @@ import javax.inject.*
 /**
  * This page lets the user view a post and all its replies.
  */
-class ViewPostPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders):
-               SoneTemplatePage("viewPost.html", webInterface, loaders, template = template, pageTitleKey = "Page.ViewPost.Title") {
+class ViewPostPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
+               SoneTemplatePage("viewPost.html", webInterface, loaders, template, templateRenderer, pageTitleKey = "Page.ViewPost.Title") {
 
        override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
                templateContext["post"] = soneRequest.parameters["post"]?.let(soneRequest.core::getPost)
index 6f9f743..38868e2 100644 (file)
@@ -17,8 +17,8 @@ import javax.inject.Inject
 /**
  * Lets the user browser another Sone.
  */
-class ViewSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders):
-               SoneTemplatePage("viewSone.html", webInterface, loaders, template = template) {
+class ViewSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
+               SoneTemplatePage("viewSone.html", webInterface, loaders, template, templateRenderer) {
 
        override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
                templateContext["soneId"] = soneRequest.parameters["sone"]
index 30286a3..cf6ab15 100644 (file)
@@ -7,6 +7,7 @@ import net.pterodactylus.sone.main.PluginHomepage
 import net.pterodactylus.sone.main.PluginVersion
 import net.pterodactylus.sone.main.PluginYear
 import net.pterodactylus.sone.test.*
+import net.pterodactylus.sone.web.page.*
 import net.pterodactylus.sone.web.pages.*
 import net.pterodactylus.util.template.Template
 import org.hamcrest.Matcher
@@ -246,6 +247,7 @@ val baseInjector by lazy {
                        Core::class.isProvidedByMock(),
                        FreenetInterface::class.isProvidedByMock(),
                        Template::class.isProvidedByMock(),
-                       WebInterface::class.isProvidedByDeepMock()
+                       WebInterface::class.isProvidedByDeepMock(),
+                       TemplateRenderer::class.isProvidedByMock()
        )!!
 }
index def7410..b48ba1f 100644 (file)
@@ -13,9 +13,10 @@ import org.mockito.Mockito.*
 class FreenetTemplatePageTest {
 
        private val templateContextFactory = deepMock<TemplateContextFactory>()
+       private val templateRenderer = deepMock<TemplateRenderer>()
        private val loaders = mock<Loaders>()
        private val template = mock<Template>()
-       private val page = FreenetTemplatePage("/test/path", templateContextFactory, loaders, template, "invalid-form-password")
+       private val page = FreenetTemplatePage("/test/path", templateRenderer, loaders, template, "invalid-form-password")
 
        @Test
        fun `path is exposed correctly`() {
@@ -69,7 +70,7 @@ class FreenetTemplatePageTest {
 
        @Test
        fun `isEnabled() returns false if full access only is true`() {
-               val page = object : FreenetTemplatePage("/test/path", templateContextFactory, loaders, template, "invalid-form-password") {
+               val page = object : FreenetTemplatePage("/test/path", templateRenderer, loaders, template, "invalid-form-password") {
                        override val isFullAccessOnly = true
                }
                assertThat(page.isEnabled(mock()), equalTo(false))
@@ -77,7 +78,7 @@ class FreenetTemplatePageTest {
 
        @Test
        fun `page with redirect target throws redirect exception on handleRequest`() {
-               val page = object : FreenetTemplatePage("/test/path", templateContextFactory, loaders, template, "invalid-form-password") {
+               val page = object : FreenetTemplatePage("/test/path", templateRenderer, loaders, template, "invalid-form-password") {
                        override fun getRedirectTarget(request: FreenetRequest) = "foo"
                }
                val request = mock<FreenetRequest>()
@@ -89,7 +90,7 @@ class FreenetTemplatePageTest {
 
        @Test
        fun `page with full access only returns unauthorized on handleRequest with non-full access request`() {
-               val page = object : FreenetTemplatePage("/test/path", templateContextFactory, loaders, template, "invalid-form-password") {
+               val page = object : FreenetTemplatePage("/test/path", templateRenderer, loaders, template, "invalid-form-password") {
                        override val isFullAccessOnly = true
                }
                val request = deepMock<FreenetRequest>()
@@ -126,12 +127,12 @@ class FreenetTemplatePageTest {
        fun `template from annotation is loaded`() {
                val template = deepMock<Template>()
                whenever(loaders.loadTemplate("template-path")).thenReturn(template)
-               TestPage(templateContextFactory, loaders)
+               TestPage(templateRenderer, loaders)
                verify(loaders).loadTemplate("template-path")
        }
 
        @TemplatePath("template-path")
-       private class TestPage(templateContextFactory: TemplateContextFactory, loaders: Loaders) : FreenetTemplatePage("/", templateContextFactory, loaders, Template(), "") {
+       private class TestPage(templateRenderer: TemplateRenderer, loaders: Loaders) : FreenetTemplatePage("/", templateRenderer, loaders, Template(), "") {
                override fun getPath() = ""
                override fun isPrefixPage() = false
                override fun handleRequest(request: FreenetRequest, response: Response) = response
index 8866a46..947262a 100644 (file)
@@ -13,7 +13,7 @@ import org.junit.Test
 /**
  * Unit test for [AboutPage].
  */
-class AboutPageTest : WebPageTest({ template, webInterface, loaders -> AboutPage(template, webInterface, loaders, PluginVersion(version), PluginYear(year), PluginHomepage(homepage)) }) {
+class AboutPageTest : WebPageTest({ template, webInterface, loaders, templateRenderer -> AboutPage(template, webInterface, loaders, templateRenderer, PluginVersion(version), PluginYear(year), PluginHomepage(homepage)) }) {
 
        companion object {
                private const val version = "0.1.2"
index e52accb..9a55a00 100644 (file)
@@ -23,7 +23,7 @@ import org.mockito.ArgumentMatchers
 /**
  * Unit test for [IndexPage].
  */
-class IndexPageTest: WebPageTest({ template, webInterface, loaders -> IndexPage(template, webInterface, loaders, postVisibilityFilter) }) {
+class IndexPageTest: WebPageTest({ template, webInterface, loaders, templateRenderer -> IndexPage(template, webInterface, loaders, templateRenderer, postVisibilityFilter) }) {
 
        companion object {
                private val postVisibilityFilter = mock<PostVisibilityFilter>()
index 440fe1d..89c3dda 100644 (file)
@@ -25,7 +25,7 @@ import java.util.concurrent.atomic.AtomicInteger
 /**
  * Unit test for [SearchPage].
  */
-class SearchPageTest: WebPageTest({ template, webInterface, loaders -> SearchPage(template, webInterface, loaders, ticker) }) {
+class SearchPageTest: WebPageTest({ template, webInterface, loaders, templateRenderer -> SearchPage(template, webInterface, loaders, templateRenderer, ticker) }) {
 
        companion object {
                val ticker = mock<Ticker>()
index c6db174..e7d9214 100644 (file)
@@ -20,7 +20,7 @@ import org.junit.Test
 /**
  * Unit test for [SoneTemplatePage].
  */
-class SoneTemplatePageTest : WebPageTest({ template, webInterface, loaders -> object : SoneTemplatePage("path.html", webInterface, loaders, template = template, requiresLogin = true) {} }) {
+class SoneTemplatePageTest : WebPageTest({ template, webInterface, loaders, templateRenderer -> object : SoneTemplatePage("path.html", webInterface, loaders, template, templateRenderer, requiresLogin = true) {} }) {
 
        init {
                request("index.html")
@@ -28,14 +28,14 @@ class SoneTemplatePageTest : WebPageTest({ template, webInterface, loaders -> ob
 
        @Test
        fun `page title is empty string if no page title key was given`() {
-               SoneTemplatePage("path.html", webInterface, loaders, template = template, requiresLogin = false).let { page ->
+               SoneTemplatePage("path.html", webInterface, loaders, template, templateRenderer, requiresLogin = false).let { page ->
                        assertThat(page.getPageTitle(soneRequest), equalTo(""))
                }
        }
 
        @Test
        fun `page title is retrieved from l10n if page title key is given`() {
-               SoneTemplatePage("path.html", webInterface, loaders, template = template, pageTitleKey = "page.title", requiresLogin = false).let { page ->
+               SoneTemplatePage("path.html", webInterface, loaders, template, templateRenderer, pageTitleKey = "page.title", requiresLogin = false).let { page ->
                        whenever(l10n.getString("page.title")).thenReturn("Page Title")
                        assertThat(page.getPageTitle(soneRequest), equalTo("Page Title"))
                }
@@ -148,7 +148,7 @@ class SoneTemplatePageTest : WebPageTest({ template, webInterface, loaders -> ob
        @Test
        fun `handleRequest method is called`() {
                var called = false
-               val page = object : SoneTemplatePage("path.html", webInterface, loaders, template = template, requiresLogin = true) {
+               val page = object : SoneTemplatePage("path.html", webInterface, loaders, template, templateRenderer, requiresLogin = true) {
                        override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
                                called = true
                        }
@@ -159,7 +159,7 @@ class SoneTemplatePageTest : WebPageTest({ template, webInterface, loaders -> ob
 
        @Test
        fun `redirect does not happen if login is not required`() {
-               val page = SoneTemplatePage("page.html", webInterface, loaders, template = template, requiresLogin = false)
+               val page = SoneTemplatePage("page.html", webInterface, loaders, template, templateRenderer, requiresLogin = false)
                assertThat(page.getRedirectTarget(freenetRequest), nullValue())
        }
 
@@ -211,7 +211,7 @@ class SoneTemplatePageTest : WebPageTest({ template, webInterface, loaders -> ob
 
        @Test
        fun `page is enabled if no full access is required and login is not required`() {
-               SoneTemplatePage("path.html", webInterface, loaders, template = template, requiresLogin = false).let { page ->
+               SoneTemplatePage("path.html", webInterface, loaders, template, templateRenderer, requiresLogin = false).let { page ->
                        assertThat(page.isEnabled(toadletContext), equalTo(true))
                }
        }
@@ -219,7 +219,7 @@ class SoneTemplatePageTest : WebPageTest({ template, webInterface, loaders -> ob
        @Test
        fun `handle request with sone request is called`() {
                var called = false
-           val page = object : SoneTemplatePage("path.html", webInterface, loaders, template = template) {
+           val page = object : SoneTemplatePage("path.html", webInterface, loaders, template, templateRenderer) {
                    override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
                            called = true
                    }
index f5bab99..fe8033b 100644 (file)
@@ -43,11 +43,12 @@ import kotlin.text.Charsets.UTF_8
 /**
  * Base class for web page tests.
  */
-open class WebPageTest(pageSupplier: (Template, WebInterface, Loaders) -> SoneTemplatePage = { _, _, _ -> mock() }) {
+open class WebPageTest(pageSupplier: (Template, WebInterface, Loaders, TemplateRenderer) -> SoneTemplatePage = { _, _, _, _ -> mock() }) {
 
        val currentSone = mock<Sone>()
        val loaders = mock<Loaders>()
        val template = mock<Template>()
+       val templateRenderer = mock<TemplateRenderer>()
        val webInterface = deepMock<WebInterface>()
        val core = webInterface.core
        val eventBus = mock<EventBus>()
@@ -55,7 +56,7 @@ open class WebPageTest(pageSupplier: (Template, WebInterface, Loaders) -> SoneTe
        val l10n = webInterface.l10n!!
        val sessionManager = mock<SessionManager>()
 
-       val page by lazy { pageSupplier(template, webInterface, loaders) }
+       val page by lazy { pageSupplier(template, webInterface, loaders, templateRenderer) }
 
        val httpRequest = mock<HTTPRequest>()
        val freenetRequest = mock<FreenetRequest>()