From: David ‘Bombe’ Roden Date: Fri, 26 Nov 2010 06:01:26 +0000 (+0100) Subject: Add template-based part. X-Git-Tag: 0.3.2-RC1~26^2~7 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=7b5ff1f6607f68d38da4e68d293f8146a3886772;p=Sone.git Add template-based part. --- diff --git a/src/main/java/net/pterodactylus/sone/text/TemplatePart.java b/src/main/java/net/pterodactylus/sone/text/TemplatePart.java new file mode 100644 index 0000000..2b27a89 --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/text/TemplatePart.java @@ -0,0 +1,75 @@ +/* + * Sone - TemplatePart.java - Copyright © 2010 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sone.text; + +import java.io.IOException; +import java.io.Writer; + +import net.pterodactylus.util.template.Template; + +/** + * {@link Part} implementation that is rendered using a {@link Template}. + * + * @author David ‘Bombe’ Roden + */ +public class TemplatePart implements Part { + + /** The template to render for this part. */ + private final Template template; + + /** + * Creates a new template part. + * + * @param template + * The template to render + */ + public TemplatePart(Template template) { + this.template = template; + } + + // + // ACTIONS + // + + /** + * Sets a variable in the template. + * + * @param key + * The key of the variable + * @param value + * The value of the variable + * @return This template part (for method chaining) + */ + public TemplatePart set(String key, String value) { + template.set(key, value); + return this; + } + + // + // PART METHODS + // + + /** + * {@inheritDoc} + */ + @Override + public void render(Writer writer) throws IOException { + template.render(writer); + } + +}