diff options
| author | Mistivia <i@mistivia.com> | 2025-01-15 19:12:12 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2025-01-15 19:12:46 +0800 |
| commit | 4da382953c830a61ae24ccbe95c4241db8788269 (patch) | |
| tree | 31f6d184273274e2660516d1ac1146b5661f20b6 /lib/crow/tests/template/mustachetest.cpp | |
restore
Diffstat (limited to 'lib/crow/tests/template/mustachetest.cpp')
| -rw-r--r-- | lib/crow/tests/template/mustachetest.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/crow/tests/template/mustachetest.cpp b/lib/crow/tests/template/mustachetest.cpp new file mode 100644 index 0000000..0041889 --- /dev/null +++ b/lib/crow/tests/template/mustachetest.cpp @@ -0,0 +1,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; +} |
