-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdemo.cpp
49 lines (41 loc) · 1.13 KB
/
demo.cpp
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
#include <iostream>
#include "qrqma/template.h"
#include "sargparse/Parameter.h"
namespace {
void demo();
auto demo_cmd = sargp::Command{"demo", "run the demo from the documentation", demo};
void demo() {
auto templateStr = R"(
<!DOCTYPE html>
<html lang="en">
<head>
<title>My Webpage</title>
</head>
<body>
<ul id="navigation">
{% for item in navigation %}
<li><a href="{{ href(item) }}">{{ caption(item) }}</a></li>
{% endfor %}
</ul>
<h1>My Webpage</h1>
{{ a_variable }}
{# a comment #}
</body>
</html>)";
struct NavItem { std::string href, caption; };
qrqma::Template rendering{
templateStr,
{
{"navigation", qrqma::symbol::List{{NavItem{"Home", "index.html"}, NavItem{"Blog", "blog.html"}}} },
{"href", qrqma::symbol::Function{[](NavItem const& ni) {
return ni.href;
}}},
{"caption", qrqma::symbol::Function{[](NavItem const& ni) {
return ni.caption;
}}},
{"a_variable", std::string{"qrqma is awesome!"}}
}
};
std::cout << rendering() << std::endl;
}
}