template indedx.html added

This commit is contained in:
moneroexamples 2016-04-07 15:01:49 +08:00
parent 87c40f4e5a
commit 2b15f5d8ea
2 changed files with 23 additions and 7 deletions

View File

@ -5,7 +5,7 @@
#include "mstch/mstch.hpp"
#include "ext/format.h"
#include <iostream>
#include <fstream>
using boost::filesystem::path;
@ -42,12 +42,11 @@ int main() {
fmt::print("\n\n"
"Top block height : {:d}\n", height);
std::string view {
"Blockchain height {{height}}\n\n"
"{{#blocks}}{{height}}: {{hash}} \n{{/blocks}}"
};
std::ifstream t("src/templates/index.html");
std::string index_tmpl_str((std::istreambuf_iterator<char>(t)),
std::istreambuf_iterator<char>());
mstch::map context {
mstch::map context {
{"height", fmt::format("{:d}", height)},
{"blocks", mstch::array()}
};
@ -73,7 +72,7 @@ int main() {
CROW_ROUTE(app, "/")
([&]() {
return mstch::render(view, context);
return mstch::render(index_tmpl_str, context);
});
app.port(8080).multithreaded().run();

17
src/templates/index.html Normal file
View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Monero blocks</title>
</head>
<body>
<div>
<h1>{{height}}</h1>
<div>
{{#blocks}}
{{height}}: {{hash}}
{{/blocks}}
</div>
</div>
</body>
</html>