2014-07-30 15:50:38 +00:00
|
|
|
#include <fstream>
|
2020-10-19 08:02:57 +00:00
|
|
|
#include <iostream>
|
2014-07-30 15:50:38 +00:00
|
|
|
#include <iterator>
|
2020-10-19 08:02:57 +00:00
|
|
|
#include <string>
|
|
|
|
|
2016-09-21 14:11:06 +00:00
|
|
|
#include "crow/json.h"
|
2020-10-19 08:02:57 +00:00
|
|
|
#include "crow/mustache.h"
|
|
|
|
|
2014-07-30 15:50:38 +00:00
|
|
|
using namespace std;
|
|
|
|
using namespace crow;
|
|
|
|
using namespace crow::mustache;
|
|
|
|
|
|
|
|
string read_all(const string& filename)
|
|
|
|
{
|
2021-11-25 11:45:38 +00:00
|
|
|
ifstream is(filename);
|
|
|
|
return {istreambuf_iterator<char>(is), istreambuf_iterator<char>()};
|
2014-07-30 15:50:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2021-11-25 11:45:38 +00:00
|
|
|
auto data = json::load(read_all("data"));
|
|
|
|
auto templ = compile(read_all("template"));
|
|
|
|
auto partials = json::load(read_all("partials"));
|
2021-11-27 12:28:50 +00:00
|
|
|
set_loader([&](std::string name) -> std::string {
|
2021-11-27 17:44:51 +00:00
|
|
|
if (partials.count(name))
|
|
|
|
{
|
|
|
|
return partials[name].s();
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
});
|
2021-11-25 11:45:38 +00:00
|
|
|
context ctx(data);
|
2022-02-18 01:25:02 +00:00
|
|
|
cout << templ.render_string(ctx);
|
2021-11-25 11:45:38 +00:00
|
|
|
return 0;
|
2014-07-30 15:50:38 +00:00
|
|
|
}
|