blob: 0041889a3667b9720a735bfcbc07d43327605d36 (
plain) (
blame)
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
|
#include <iostream>
#include <fstream>
#include <string>
#include <iterator>
#include "crow/mustache.h"
#include "crow/json.h"
using namespace std;
using namespace crow;
using namespace crow::mustache;
string read_all(const string& filename)
{
ifstream is(filename);
return {istreambuf_iterator<char>(is), istreambuf_iterator<char>()};
}
int main()
{
auto data = json::load(read_all("data"));
auto templ = compile(read_all("template"));
auto partials = json::load(read_all("partials"));
set_loader([&](std::string name)->std::string
{
if (partials.count(name))
{
return partials[name].s();
}
return "";
});
context ctx(data);
cout << templ.render(ctx);
return 0;
}
|