Skip to content

Commit cebd967

Browse files
committed
Update README.md.
1 parent 42b0521 commit cebd967

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,35 @@ for (var credit : credits) {
835835
}
836836
```
837837

838+
Alternatively, the adapter could be used as the data dictionary for a template document:
839+
840+
```java
841+
var templateEncoder = new TemplateEncoder(Examples.class, "account.html");
842+
843+
templateEncoder.write(account, System.out);
844+
```
845+
846+
```html
847+
<html>
848+
<body>
849+
<p>Account ID: {{@id}}</p>
850+
<p>Account Holder: {{lastName}}, {{firstName}}</p>
851+
<p>Credits:</p>
852+
<ul>
853+
{{#transactions/credit*}}
854+
<li>{{date}} - {{amount}}</li>
855+
{{/transactions/credit*}}
856+
</ul>
857+
<p>Debits:</p>
858+
<ul>
859+
{{#transactions/debit*}}
860+
<li>{{date}} - {{amount}}</li>
861+
{{/transactions/debit*}}
862+
</ul>
863+
</body>
864+
</html>
865+
```
866+
838867
`ElementAdapter` also supports `put()` and `remove()` for modifying an element's contents.
839868

840869
## Pipe

kilo-test/src/test/java/org/httprpc/kilo/examples/Examples.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,12 @@ public static void elementAdapter() throws SAXException, IOException {
279279
System.out.println(credit.get("amount"));
280280
System.out.println(credit.get("date"));
281281
}
282+
283+
System.out.println();
284+
285+
var templateEncoder = new TemplateEncoder(Examples.class, "account.html");
286+
287+
templateEncoder.write(account, System.out);
282288
}
283289

284290
public static void collections() {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body>
4+
<p>Account ID: {{@id}}</p>
5+
<p>Account Holder: {{lastName}}, {{firstName}}</p>
6+
<p>Credits:</p>
7+
<ul>
8+
{{#transactions/credit*}}
9+
<li>{{date}} - {{amount}}</li>
10+
{{/transactions/credit*}}
11+
</ul>
12+
<p>Debits:</p>
13+
<ul>
14+
{{#transactions/debit*}}
15+
<li>{{date}} - {{amount}}</li>
16+
{{/transactions/debit*}}
17+
</ul>
18+
</body>
19+
</html>

0 commit comments

Comments
 (0)