mirror of
https://github.com/CrowCpp/Crow.git
synced 2024-06-07 21:10:44 +00:00
9a876e9451
Justification is for the content-type header to be set to HTML instead of text. Also added render_string() functions to replace the old methods.
35 lines
762 B
C++
35 lines
762 B
C++
#include <fstream>
|
|
#include <iostream>
|
|
#include <iterator>
|
|
#include <string>
|
|
|
|
#include "crow/json.h"
|
|
#include "crow/mustache.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_string(ctx);
|
|
return 0;
|
|
}
|