Skip to content

Commit

Permalink
Add javadoc for gg.jte.Content
Browse files Browse the repository at this point in the history
  • Loading branch information
casid committed Nov 19, 2022
1 parent 80ffc02 commit a699cba
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions jte-runtime/src/main/java/gg/jte/Content.java
@@ -1,5 +1,45 @@
package gg.jte;

/**
* This interface can be used to create reusable content blocks for templates through Java code.
*
* When using the content block shorthand <code>@`...`</code> in templates, behind the scenes an anonymous class of
* {@link Content} is created as well. For example:
* <pre>
* !{var name = "world";}
* !{var myContent = @`
* Hello ${name}!
* This is a reusable content block.
* `;}
*
* ${myContent}
* ${myContent}
* </pre>
*
* Would be the same as:
* <pre>
* public class MyContent implements Content {
* private final String name;
*
* public MyContent(String name) {
* this.name = name;
* }
*
* &#64;Override
* public void writeTo(TemplateOutput output) {
* output.writeContent("Hello ");
*
* // User provided content, must be output escaped!
* output.writeUserContent(name);
*
* output.writeContent("!\n This is a reusable content block.");
* }
* }
* </pre>
*
* While the above example doesn't make a lot of sense, {@link Content} can be a very powerful
* abstraction for complex tasks.
*/
public interface Content {
void writeTo(TemplateOutput output);

Expand Down

0 comments on commit a699cba

Please sign in to comment.