From 94f44f91489ec768fa05d34593c7533a9150c1fd Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 8 Feb 2017 07:14:21 +0100 Subject: [PATCH] Store preferences in template context instead of core --- src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java | 2 +- src/main/resources/templates/imageBrowser.html | 4 ++-- src/main/resources/templates/include/viewPost.html | 2 +- src/main/resources/templates/include/viewReply.html | 2 +- src/test/kotlin/net/pterodactylus/sone/web/SoneTemplatePageTest.kt | 6 +++--- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java b/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java index 2b16dba..bece45d 100644 --- a/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java +++ b/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java @@ -201,7 +201,7 @@ public class SoneTemplatePage extends FreenetTemplatePage { protected final void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); Sone currentSone = getCurrentSoneWithoutCreatingSession(request.getToadletContext()); - templateContext.set("core", webInterface.getCore()); + templateContext.set("preferences", webInterface.getCore().getPreferences()); templateContext.set("currentSone", currentSone); templateContext.set("localSones", webInterface.getCore().getLocalSones()); templateContext.set("request", request); diff --git a/src/main/resources/templates/imageBrowser.html b/src/main/resources/templates/imageBrowser.html index 7e4c824..b8b9cb2 100644 --- a/src/main/resources/templates/imageBrowser.html +++ b/src/main/resources/templates/imageBrowser.html @@ -376,7 +376,7 @@ <%/if> - <%foreach album.images image|paginate pageSize=core.preferences.imagesPerPage page=page> + <%foreach album.images image|paginate pageSize=preferences.imagesPerPage page=page> <%first>

<%= Page.ImageBrowser.Header.Images|l10n|html>

<%include include/pagination.html pageParameter=="page"> @@ -599,7 +599,7 @@ <%elseif galleryRequested> - <%foreach albums album|paginate pageSize=core.preferences.imagesPerPage pageParameter=request.page pagination=albumPagination> + <%foreach albums album|paginate pageSize=preferences.imagesPerPage pageParameter=request.page pagination=albumPagination> <%first>

<%= Page.ImageBrowser.Header.Albums|l10n|html>

<%include include/pagination.html pagination=albumPagination pageParameter=="page"> diff --git a/src/main/resources/templates/include/viewPost.html b/src/main/resources/templates/include/viewPost.html index 12d37db..ed6e5cc 100644 --- a/src/main/resources/templates/include/viewPost.html +++ b/src/main/resources/templates/include/viewPost.html @@ -29,7 +29,7 @@ <% post.text|html|store key==originalText text==true> <% post.text|parse sone=post.sone|store key==parsedText> <% parsedText|render|store key==renderedText text==true> - <% parsedText|shorten length=core.preferences.charactersPerPost cut-off-length=core.preferences.postCutOffLength|render|store key==shortText text==true> + <% parsedText|shorten length=preferences.charactersPerPost cut-off-length=preferences.postCutOffLength|render|store key==shortText text==true>
<% originalText>
<% renderedText>
<% shortText>
diff --git a/src/main/resources/templates/include/viewReply.html b/src/main/resources/templates/include/viewReply.html index 211c1d3..32fb73d 100644 --- a/src/main/resources/templates/include/viewReply.html +++ b/src/main/resources/templates/include/viewReply.html @@ -17,7 +17,7 @@ <% reply.text|html|store key==originalText text==true> <% reply.text|parse sone=reply.sone|store key==parsedText> <% parsedText|render|store key==renderedText text==true> - <% parsedText|shorten length=core.preferences.charactersPerPost cut-off-length=core.preferences.postCutOffLength|render|store key==shortText text==true> + <% parsedText|shorten length=preferences.charactersPerPost cut-off-length=preferences.postCutOffLength|render|store key==shortText text==true>
<% originalText>
<% renderedText>
<% shortText>
diff --git a/src/test/kotlin/net/pterodactylus/sone/web/SoneTemplatePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/SoneTemplatePageTest.kt index b4a6a55..06d4c19 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/SoneTemplatePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/SoneTemplatePageTest.kt @@ -24,7 +24,7 @@ import org.mockito.Mockito.verify */ class SoneTemplatePageTest : WebPageTest() { - // @get:JvmName("getPage1") + private val preferences by lazy { core.preferences!! } private val page = object : SoneTemplatePage("path.html", template, webInterface, true) {} @Test @@ -107,8 +107,8 @@ class SoneTemplatePageTest : WebPageTest() { } @Test - fun `core is set in template context`() { - verifyVariableIsSet("core", core) + fun `preferences are set in template context`() { + verifyVariableIsSet("preferences", preferences) } @Test -- 2.7.4