diff options
author | ipknHama <ipknhama@gmail.com> | 2014-08-08 03:53:36 +0900 |
---|---|---|
committer | ipknHama <ipknhama@gmail.com> | 2014-08-08 03:53:36 +0900 |
commit | 3018ff063acb747065adea877e3e2ac9423f5233 (patch) | |
tree | 110f1a6596242b7837c16f88b4838d6fd93dc93c /tests/template/mustachetest.cpp | |
parent | a0c93f5b84cc11b30bc6320ac26127832ef8bf7a (diff) | |
parent | 001c66b378d200bdecc8a4a692c5a73a7d426b8f (diff) | |
download | crow-3018ff063acb747065adea877e3e2ac9423f5233.tar.gz crow-3018ff063acb747065adea877e3e2ac9423f5233.zip |
Merge branch 'directory-restructuring'
Directory structure changed.
Crow becomes a complete header-only library with http_parser_merged.h.
Provides amalgamated crow_all.h (all feature in one header file).
Diffstat (limited to 'tests/template/mustachetest.cpp')
-rw-r--r-- | tests/template/mustachetest.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
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 <iostream> +#include <fstream> +#include <string> +#include <iterator> +#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<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; +} |