2014-07-30 15:50:38 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <string>
|
|
|
|
#include <iterator>
|
2014-08-06 19:46:28 +00:00
|
|
|
#include "mustache.h"
|
|
|
|
#include "json.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)
|
|
|
|
{
|
|
|
|
ifstream is(filename);
|
2014-08-02 01:46:00 +00:00
|
|
|
return {istreambuf_iterator<char>(is), istreambuf_iterator<char>()};
|
2014-07-30 15:50:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
auto data = json::load(read_all("data"));
|
|
|
|
auto templ = compile(read_all("template"));
|
2014-08-02 01:46:00 +00:00
|
|
|
auto partials = json::load(read_all("partials"));
|
|
|
|
set_loader([&](std::string name)->std::string
|
|
|
|
{
|
|
|
|
if (partials.count(name))
|
|
|
|
{
|
|
|
|
return partials[name].s();
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
});
|
2014-07-30 15:50:38 +00:00
|
|
|
context ctx(data);
|
|
|
|
cout << templ.render(ctx);
|
|
|
|
return 0;
|
|
|
|
}
|