X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftemplate%2FImageLinkFilter.java;h=fc4b803ffcfb354be9ec1b839fbedd2fe3ac4ed2;hb=110a933c2724aba6a604fc5eed6372ff1e1e6144;hp=458d40f382f6d654a4aa98ac334a716fd9964bea;hpb=5f0219160b8306a26619de5e0f2b43803b3e22c2;p=Sone.git
diff --git a/src/main/java/net/pterodactylus/sone/template/ImageLinkFilter.java b/src/main/java/net/pterodactylus/sone/template/ImageLinkFilter.java
index 458d40f..fc4b803 100644
--- a/src/main/java/net/pterodactylus/sone/template/ImageLinkFilter.java
+++ b/src/main/java/net/pterodactylus/sone/template/ImageLinkFilter.java
@@ -1,5 +1,5 @@
/*
- * Sone - ImageLinkFilter.java - Copyright © 2011â2013 David Roden
+ * Sone - ImageLinkFilter.java - Copyright © 2011â2019 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -28,6 +28,7 @@ import java.util.Map;
import net.pterodactylus.sone.core.Core;
import net.pterodactylus.sone.data.Image;
import net.pterodactylus.util.template.Filter;
+import net.pterodactylus.util.template.HtmlFilter;
import net.pterodactylus.util.template.Template;
import net.pterodactylus.util.template.TemplateContext;
import net.pterodactylus.util.template.TemplateContextFactory;
@@ -39,31 +40,22 @@ import com.google.common.base.Optional;
/**
* Template filter that turns an {@link Image} into an HTML <img> tag,
* using some parameters to influence parameters of the image.
- *
- * @author David âBombeâ Roden
*/
public class ImageLinkFilter implements Filter {
/** The template to render for the <img> tag. */
- private static final Template linkTemplate = TemplateParser.parse(new StringReader(" class=\"<%class|css>\"<%/if> src=\"<%src|html><%if forceDownload>?forcedownload=true<%/if>\" alt=\"<%alt|html>\" title=\"<%title|html>\" width=\"<%width|html>\" height=\"<%height|html>\" style=\"position: relative;<%ifnull ! top>top: <% top|html>;<%/if><%ifnull ! left>left: <% left|html>;<%/if>\"/>"));
+ private static final Template linkTemplate = TemplateParser.parse(new StringReader(" class=\"<%class|css>\"<%/if> src=\"<%src|html>\" alt=\"<%alt|html>\" title=\"<%title|html>\" width=\"<%width|html>\" height=\"<%height|html>\" style=\"position: relative;<%ifnull ! top>top: <% top|html>;<%/if><%ifnull ! left>left: <% left|html>;<%/if>\"/>"));
/** The core. */
private final Core core;
/** The template context factory. */
- private final TemplateContextFactory templateContextFactory;
+ private final TemplateContextFactory templateContextFactory = new TemplateContextFactory();
- /**
- * Creates a new image link filter.
- *
- * @param core
- * The core
- * @param templateContextFactory
- * The template context factory
- */
- public ImageLinkFilter(Core core, TemplateContextFactory templateContextFactory) {
+ public ImageLinkFilter(Core core) {
this.core = core;
- this.templateContextFactory = templateContextFactory;
+ templateContextFactory.addFilter("html", new HtmlFilter());
+ templateContextFactory.addFilter("css", new CssClassNameFilter());
}
/**
@@ -80,22 +72,16 @@ public class ImageLinkFilter implements Filter {
if (image == null) {
return null;
}
- String imageClass = Optional.fromNullable(parameters.get("class")).transform(new Function