0#import "Basic";
1#import "htmltemplate"();
4/**
5 jai 01_from_readme.jai -quiet && ./01_from_readme
6*/
9TEMPLATE :: #string STR_END
10<div>
11 <p>{{ :foo1: }}</p>
13 {{ :foo2: <a href="%" %>%</a> }}
15 {{ :foo3: <a href="#%1" target="%2">%1</a> }}
17 <ul>
18{{ loop:foo4: <li><a href="#%1">%1</a>%2</li> }}
19 </ul>
20</div>
21STR_END;
24main :: () {
25 queue_action: [..]Action;
26 defer array_free(queue_action);
28 commit("foo1", "My Title");
29 commit("foo2", "#about", "target=\"_self\"", "About");
30 commit("foo3", "blog", "_self");
31 commit("foo4", .[
32 .["Foo", "Bar"],
33 .["Fizz", "Buzz"],
34 .["contact", ""],
35 ]);
37 success,
38 html_string,
39 exit_code,
40 error_message := generate(queue_action, TEMPLATE, .STRING);
42 defer {
43 free(html_string);
44 free(error_message);
45 }
47 if !success {
48 log("%", error_message);
49 return;
50 }
52 log("%", html_string);
53}
index : htmltemplate
---