X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftext%2FTemplatePart.java;h=1ac1fdd32c36307271662cb45ac13f7119a2690e;hb=9e4db46b86d084eba9029906e779ec1d96f78ac4;hp=2b27a895bcb9a3a89c3fbe8190b1ec2321a8706f;hpb=967adc51224c9cfc5ce3fe36faa8ecd6e31959b3;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/text/TemplatePart.java b/src/main/java/net/pterodactylus/sone/text/TemplatePart.java index 2b27a89..1ac1fdd 100644 --- a/src/main/java/net/pterodactylus/sone/text/TemplatePart.java +++ b/src/main/java/net/pterodactylus/sone/text/TemplatePart.java @@ -21,13 +21,19 @@ import java.io.IOException; import java.io.Writer; import net.pterodactylus.util.template.Template; +import net.pterodactylus.util.template.TemplateContext; +import net.pterodactylus.util.template.TemplateContextFactory; +import net.pterodactylus.util.template.TemplateException; /** * {@link Part} implementation that is rendered using a {@link Template}. * * @author David ‘Bombe’ Roden */ -public class TemplatePart implements Part { +public class TemplatePart implements Part, net.pterodactylus.util.template.Part { + + /** The template context factory. */ + private final TemplateContextFactory templateContextFactory; /** The template to render for this part. */ private final Template template; @@ -35,10 +41,13 @@ public class TemplatePart implements Part { /** * Creates a new template part. * + * @param templateContextFactory + * The template context factory * @param template * The template to render */ - public TemplatePart(Template template) { + public TemplatePart(TemplateContextFactory templateContextFactory, Template template) { + this.templateContextFactory = templateContextFactory; this.template = template; } @@ -55,8 +64,8 @@ public class TemplatePart implements Part { * The value of the variable * @return This template part (for method chaining) */ - public TemplatePart set(String key, String value) { - template.set(key, value); + public TemplatePart set(String key, Object value) { + template.getInitialContext().set(key, value); return this; } @@ -69,7 +78,15 @@ public class TemplatePart implements Part { */ @Override public void render(Writer writer) throws IOException { - template.render(writer); + template.render(templateContextFactory.createTemplateContext().mergeContext(template.getInitialContext()), writer); + } + + /** + * {@inheritDoc} + */ + @Override + public void render(TemplateContext templateContext, Writer writer) throws TemplateException { + template.render(templateContext.mergeContext(template.getInitialContext()), writer); } }