From 6930f50f8a5a8c2bc53bd948a2e32c7cd63fd02a Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 21 Sep 2011 07:46:00 +0200 Subject: [PATCH] =?utf8?q?Add=20=E2=80=9Ctitle=E2=80=9D=20parameter.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../java/net/pterodactylus/sone/template/ImageLinkFilter.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/template/ImageLinkFilter.java b/src/main/java/net/pterodactylus/sone/template/ImageLinkFilter.java index 3d6c731..12f44ef 100644 --- a/src/main/java/net/pterodactylus/sone/template/ImageLinkFilter.java +++ b/src/main/java/net/pterodactylus/sone/template/ImageLinkFilter.java @@ -23,6 +23,7 @@ import java.util.Map; import net.pterodactylus.sone.data.Image; import net.pterodactylus.util.number.Numbers; +import net.pterodactylus.util.object.Default; import net.pterodactylus.util.template.Filter; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; @@ -62,6 +63,10 @@ public class ImageLinkFilter implements Filter { String imageClass = parameters.get("class"); int maxWidth = Numbers.safeParseInteger(parameters.get("max-width"), Integer.MAX_VALUE); int maxHeight = Numbers.safeParseInteger(parameters.get("max-height"), Integer.MAX_VALUE); + String title = parameters.get("title"); + if ((title != null) && title.startsWith("=")) { + title = String.valueOf(templateContext.get(title.substring(1))); + } TemplateContext linkTemplateContext = templateContextFactory.createTemplateContext(); linkTemplateContext.set("class", imageClass); @@ -78,8 +83,8 @@ public class ImageLinkFilter implements Filter { } linkTemplateContext.set("width", (int) (imageWidth * scale + 0.5)); linkTemplateContext.set("height", (int) (imageHeight * scale + 0.5)); - linkTemplateContext.set("alt", image.getDescription()); - linkTemplateContext.set("title", image.getTitle()); + linkTemplateContext.set("alt", Default.forNull(title, image.getDescription())); + linkTemplateContext.set("title", Default.forNull(title, image.getTitle())); StringWriter stringWriter = new StringWriter(); linkTemplate.render(linkTemplateContext, stringWriter); -- 2.7.4