From e70380e003ae28822a6b903193c9a699cc02c405 Mon Sep 17 00:00:00 2001 From: ipknHama Date: Thu, 7 Aug 2014 04:46:28 +0900 Subject: cmake update, added template test --- tests/template/mustachetest.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/template/mustachetest.cpp (limited to 'tests/template/mustachetest.cpp') diff --git a/tests/template/mustachetest.cpp b/tests/template/mustachetest.cpp new file mode 100644 index 0000000..1caf537 --- /dev/null +++ b/tests/template/mustachetest.cpp @@ -0,0 +1,33 @@ +#include +#include +#include +#include +#include "mustache.h" +#include "json.h" +using namespace std; +using namespace crow; +using namespace crow::mustache; + +string read_all(const string& filename) +{ + ifstream is(filename); + return {istreambuf_iterator(is), istreambuf_iterator()}; +} + +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; +} -- cgit v1.2.3-54-g00ecf