templates folder added to cmake

This commit is contained in:
moneroexamples 2016-04-08 14:14:42 +08:00
parent 2b15f5d8ea
commit 8247faf232
5 changed files with 45 additions and 10 deletions

View File

@ -72,7 +72,6 @@ set_property(TARGET lmdb
include_directories(${Boost_INCLUDE_DIRS})
include_directories("ext/mstch/include")
# add ext/ subfolder
add_subdirectory(ext/)
@ -83,9 +82,25 @@ add_subdirectory(src/)
set(SOURCE_FILES
main.cpp)
ADD_CUSTOM_TARGET(driver DEPENDS src/templates/index.html)
add_executable(${PROJECT_NAME}
${SOURCE_FILES})
#add_custom_command(OUTPUT template_folder
# COMMAND ${CMAKE_COMMAND} -E
# copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/src/templates" "${CMAKE_CURRENT_BINARY_DIR}"
# DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/templates")
#
#add_custom_target(index_html
# ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/templates")
#
#ADD_DEPENDENCIES(${PROJECT_NAME}
# index_html)
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/src/templates"
DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
target_link_libraries(${PROJECT_NAME}
myxrm
myext

View File

@ -42,16 +42,15 @@ int main() {
fmt::print("\n\n"
"Top block height : {:d}\n", height);
std::ifstream t("src/templates/index.html");
std::string index_tmpl_str((std::istreambuf_iterator<char>(t)),
std::istreambuf_iterator<char>());
std::string view = xmreg::read("./templates/index.html");
mstch::map context {
{"height", fmt::format("{:d}", height)},
{"blocks", mstch::array()}
};
size_t no_of_last_blocks {10};
size_t no_of_last_blocks {50};
mstch::array& blocks = boost::get<mstch::array>(context["blocks"]);
@ -72,7 +71,7 @@ int main() {
CROW_ROUTE(app, "/")
([&]() {
return mstch::render(index_tmpl_str, context);
return mstch::render(view, context);
});
app.port(8080).multithreaded().run();

View File

@ -6,11 +6,15 @@
</head>
<body>
<div>
<h1>{{height}}</h1>
<h1>Detailed Monero blockchain explorer</h1>
<h2>Current height: {{height}}</h2>
<div>
{{#blocks}}
{{height}}: {{hash}}
{{/blocks}}
<ul>
{{#blocks}}
<li> {{height}}: {{hash}} </li>
{{/blocks}}
</ul>
</div>
</div>
</body>

View File

@ -334,4 +334,18 @@ namespace xmreg
};
string
read(string filename)
{
if (!bf::exists(bf::path(filename)))
{
return string();
}
std::ifstream t("./templates/index.html");
return string(std::istreambuf_iterator<char>(t),
std::istreambuf_iterator<char>());
}
}

View File

@ -144,6 +144,9 @@ namespace xmreg
array<size_t, 5>
timestamp_difference(uint64_t t1, uint64_t t2);
string
read(string filename);
}
#endif //XMREG01_TOOLS_H