From 3dc1b526bc547f89a8a9e5d67344e05ae7004d04 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 12 Nov 2011 11:54:34 +0100 Subject: [PATCH] Parse descriptions of albums and images. --- src/main/java/net/pterodactylus/sone/web/WebInterface.java | 7 +++++-- .../net/pterodactylus/sone/web/ajax/EditImageAjaxPage.java | 13 +++++++++++-- src/main/resources/templates/imageBrowser.html | 8 ++++---- src/main/resources/templates/include/browseAlbums.html | 2 +- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 7320ad5..4c41581 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -170,6 +170,9 @@ public class WebInterface implements CoreListener { /** The Sone text parser. */ private final SoneTextParser soneTextParser; + /** The parser filter. */ + private final ParserFilter parserFilter; + /** The “new Sone” notification. */ private final ListNotification newSoneNotification; @@ -242,7 +245,7 @@ public class WebInterface implements CoreListener { templateContextFactory.addFilter("match", new MatchFilter()); templateContextFactory.addFilter("css", new CssClassNameFilter()); templateContextFactory.addFilter("js", new JavascriptFilter()); - templateContextFactory.addFilter("parse", new ParserFilter(getCore(), templateContextFactory, soneTextParser)); + templateContextFactory.addFilter("parse", parserFilter = new ParserFilter(getCore(), templateContextFactory, soneTextParser)); templateContextFactory.addFilter("unknown", new UnknownDateFilter(getL10n(), "View.Sone.Text.UnknownDate")); templateContextFactory.addFilter("format", new FormatFilter()); templateContextFactory.addFilter("sort", new CollectionSortFilter()); @@ -668,7 +671,7 @@ public class WebInterface implements CoreListener { pageToadlets.add(pageToadletFactory.createPageToadlet(new FollowSoneAjaxPage(this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new UnfollowSoneAjaxPage(this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new EditAlbumAjaxPage(this))); - pageToadlets.add(pageToadletFactory.createPageToadlet(new EditImageAjaxPage(this))); + pageToadlets.add(pageToadletFactory.createPageToadlet(new EditImageAjaxPage(this, parserFilter))); pageToadlets.add(pageToadletFactory.createPageToadlet(new TrustAjaxPage(this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new DistrustAjaxPage(this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new UntrustAjaxPage(this))); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/EditImageAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/EditImageAjaxPage.java index 3bef432..3c4de8e 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/EditImageAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/EditImageAjaxPage.java @@ -18,10 +18,13 @@ package net.pterodactylus.sone.web.ajax; import net.pterodactylus.sone.data.Image; +import net.pterodactylus.sone.template.ParserFilter; import net.pterodactylus.sone.text.TextFilter; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; +import net.pterodactylus.util.collection.MapBuilder; import net.pterodactylus.util.json.JsonObject; +import net.pterodactylus.util.template.TemplateContext; /** * Page that stores a user’s image modifications. @@ -30,14 +33,20 @@ import net.pterodactylus.util.json.JsonObject; */ public class EditImageAjaxPage extends JsonPage { + /** Parser for image descriptions. */ + private final ParserFilter parserFilter; + /** * Creates a new edit image AJAX page. * * @param webInterface * The Sone web interface + * @param parserFilter + * The parser filter for image descriptions */ - public EditImageAjaxPage(WebInterface webInterface) { + public EditImageAjaxPage(WebInterface webInterface, ParserFilter parserFilter) { super("editImage.ajax", webInterface); + this.parserFilter = parserFilter; } // @@ -71,7 +80,7 @@ public class EditImageAjaxPage extends JsonPage { String description = request.getHttpRequest().getParam("description").trim(); image.setTitle(title).setDescription(TextFilter.filter(request.getHttpRequest().getHeader("host"), description)); webInterface.getCore().touchConfiguration(); - return createSuccessJsonObject().put("imageId", image.getId()).put("title", image.getTitle()).put("description", image.getDescription()); + return createSuccessJsonObject().put("imageId", image.getId()).put("title", image.getTitle()).put("description", image.getDescription()).put("parsedDescription", (String) parserFilter.format(new TemplateContext(), image.getDescription(), new MapBuilder().put("sone", image.getSone().getId()).get())); } } diff --git a/src/main/resources/templates/imageBrowser.html b/src/main/resources/templates/imageBrowser.html index d97fc25..1da99ff 100644 --- a/src/main/resources/templates/imageBrowser.html +++ b/src/main/resources/templates/imageBrowser.html @@ -118,9 +118,9 @@ ajaxGet("editImage.ajax", { "formPassword": getFormPassword(), "image": imageId, "title": title, "description": description }, function(data) { if (data && data.success) { getImage(data.imageId).find(".image-title").text(data.title); - getImage(data.imageId).find(".image-description").text(data.description); + getImage(data.imageId).find(".image-description").html(data.parsedDescription); getImage(data.imageId).find(":input[name='title']").attr("defaultValue", title); - getImage(data.imageId).find(":input[name='description']").attr("defaultValue", description); + getImage(data.imageId).find(":input[name='description']").attr("defaultValue", data.description); cancelImageEditing(); } }); @@ -322,7 +322,7 @@ <%/foreach> -

<% album.description|html>

+

<% album.description|parse sone=album.sone>

<%if album.sone.local> @@ -378,7 +378,7 @@
<% image.title|html>
-
<% image.description|html>
+
<% image.description|parse sone=image.sone>
<%if album.sone.local>
diff --git a/src/main/resources/templates/include/browseAlbums.html b/src/main/resources/templates/include/browseAlbums.html index d925a3c..1fddebd 100644 --- a/src/main/resources/templates/include/browseAlbums.html +++ b/src/main/resources/templates/include/browseAlbums.html @@ -14,7 +14,7 @@
<% album.title|html> (<%= View.Sone.Stats.Images|l10n 0=album.images.size>)
-
<% album.description|html>
+
<% album.description|parse sone=album.sone>
<%if album.sone.local> -- 2.7.4