-
Notifications
You must be signed in to change notification settings - Fork 53
/
Content.java
49 lines (47 loc) · 1.31 KB
/
Content.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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;
* }
*
* @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);
default boolean isEmptyContent() {
return false;
}
}