--- /dev/null
+package net.pterodactylus.sone.main;
+
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.Map;
+
+import net.pterodactylus.util.template.Filter;
+import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
+import net.pterodactylus.util.template.TemplateException;
+import net.pterodactylus.util.template.TemplateParser;
+
+/**
+ * Takes the input and parses it as a new {@link Template}.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class ReparseFilter implements Filter {
+
+ @Override
+ public Object format(TemplateContext templateContext, Object data, Map<String, Object> parameters) {
+ Template template = TemplateParser.parse(new StringReader(String.valueOf(data)));
+ StringWriter stringWriter = new StringWriter();
+ try {
+ template.render(templateContext, stringWriter);
+ } catch (TemplateException e) {
+ throw new RuntimeException(e);
+ } finally {
+ return stringWriter.toString();
+ }
+ }
+
+}
import net.pterodactylus.sone.freenet.L10nFilter;
import net.pterodactylus.sone.freenet.wot.Identity;
import net.pterodactylus.sone.freenet.wot.Trust;
+import net.pterodactylus.sone.main.ReparseFilter;
import net.pterodactylus.sone.main.SonePlugin;
import net.pterodactylus.sone.notify.ListNotification;
import net.pterodactylus.sone.template.AlbumAccessor;
templateContextFactory.addFilter("css", new CssClassNameFilter());
templateContextFactory.addFilter("js", new JavascriptFilter());
templateContextFactory.addFilter("parse", parserFilter = new ParserFilter(getCore(), templateContextFactory, soneTextParser));
+ templateContextFactory.addFilter("reparse", new ReparseFilter());
templateContextFactory.addFilter("unknown", new UnknownDateFilter(getL10n(), "View.Sone.Text.UnknownDate"));
templateContextFactory.addFilter("format", new FormatFilter());
templateContextFactory.addFilter("sort", new CollectionSortFilter());
--- /dev/null
+package net.pterodactylus.sone.main;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+
+import java.util.Collections;
+
+import net.pterodactylus.util.template.TemplateContext;
+
+import org.junit.Test;
+
+/**
+ * Unit test for {@link ReparseFilter}.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class ReparseFilterTest {
+
+ private final ReparseFilter reparseFilter = new ReparseFilter();
+
+ @Test
+ public void filterParsesTemplateCorrectly() {
+ TemplateContext templateContext = new TemplateContext();
+ templateContext.set("bar", "baz");
+ assertThat(reparseFilter.format(templateContext, "foo <% bar>", Collections.<String, Object>emptyMap()),
+ is((Object) "foo baz"));
+ }
+
+}