Store preferences in template context instead of core
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 8 Feb 2017 06:14:21 +0000 (07:14 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 8 Feb 2017 06:14:21 +0000 (07:14 +0100)
src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java
src/main/resources/templates/imageBrowser.html
src/main/resources/templates/include/viewPost.html
src/main/resources/templates/include/viewReply.html
src/test/kotlin/net/pterodactylus/sone/web/SoneTemplatePageTest.kt

index 2b16dba..bece45d 100644 (file)
@@ -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);
index 7e4c824..b8b9cb2 100644 (file)
                                </div>
                        <%/if>
 
-                       <%foreach album.images image|paginate pageSize=core.preferences.imagesPerPage page=page>
+                       <%foreach album.images image|paginate pageSize=preferences.imagesPerPage page=page>
                                <%first>
                                        <h2><%= Page.ImageBrowser.Header.Images|l10n|html></h2>
                                        <%include include/pagination.html pageParameter=="page">
 
        <%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>
                                <h2><%= Page.ImageBrowser.Header.Albums|l10n|html></h2>
                                <%include include/pagination.html pagination=albumPagination pageParameter=="page">
index 12d37db..ed6e5cc 100644 (file)
@@ -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>
                        <div class="post-text raw-text<%if !raw> hidden<%/if>"><% originalText></div>
                        <div class="post-text text<%if raw> hidden<%/if><%if !shortText|match key=renderedText> hidden<%/if>"><% renderedText></div>
                        <div class="post-text short-text<%if raw> hidden<%/if><%if shortText|match key=renderedText> hidden<%/if>"><% shortText></div>
index 211c1d3..32fb73d 100644 (file)
@@ -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>
                        <div class="reply-text raw-text<%if !raw> hidden<%/if>"><% originalText></div>
                        <div class="reply-text text<%if raw> hidden<%/if><%if !shortText|match key=renderedText> hidden<%/if>"><% renderedText></div>
                        <div class="reply-text short-text<%if raw> hidden<%/if><%if shortText|match key=renderedText> hidden<%/if>"><% shortText></div>
index b4a6a55..06d4c19 100644 (file)
@@ -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