mirror of
https://git.wownero.com/wownero/onion-wownero-blockchain-explorer.git
synced 2024-08-15 00:33:12 +00:00
templates folder added to cmake
This commit is contained in:
parent
2b15f5d8ea
commit
8247faf232
5 changed files with 45 additions and 10 deletions
|
@ -72,7 +72,6 @@ set_property(TARGET lmdb
|
||||||
include_directories(${Boost_INCLUDE_DIRS})
|
include_directories(${Boost_INCLUDE_DIRS})
|
||||||
include_directories("ext/mstch/include")
|
include_directories("ext/mstch/include")
|
||||||
|
|
||||||
|
|
||||||
# add ext/ subfolder
|
# add ext/ subfolder
|
||||||
add_subdirectory(ext/)
|
add_subdirectory(ext/)
|
||||||
|
|
||||||
|
@ -83,9 +82,25 @@ add_subdirectory(src/)
|
||||||
set(SOURCE_FILES
|
set(SOURCE_FILES
|
||||||
main.cpp)
|
main.cpp)
|
||||||
|
|
||||||
|
ADD_CUSTOM_TARGET(driver DEPENDS src/templates/index.html)
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME}
|
add_executable(${PROJECT_NAME}
|
||||||
${SOURCE_FILES})
|
${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}
|
target_link_libraries(${PROJECT_NAME}
|
||||||
myxrm
|
myxrm
|
||||||
myext
|
myext
|
||||||
|
|
9
main.cpp
9
main.cpp
|
@ -42,16 +42,15 @@ int main() {
|
||||||
fmt::print("\n\n"
|
fmt::print("\n\n"
|
||||||
"Top block height : {:d}\n", height);
|
"Top block height : {:d}\n", height);
|
||||||
|
|
||||||
std::ifstream t("src/templates/index.html");
|
|
||||||
std::string index_tmpl_str((std::istreambuf_iterator<char>(t)),
|
std::string view = xmreg::read("./templates/index.html");
|
||||||
std::istreambuf_iterator<char>());
|
|
||||||
|
|
||||||
mstch::map context {
|
mstch::map context {
|
||||||
{"height", fmt::format("{:d}", height)},
|
{"height", fmt::format("{:d}", height)},
|
||||||
{"blocks", mstch::array()}
|
{"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"]);
|
mstch::array& blocks = boost::get<mstch::array>(context["blocks"]);
|
||||||
|
|
||||||
|
@ -72,7 +71,7 @@ int main() {
|
||||||
|
|
||||||
CROW_ROUTE(app, "/")
|
CROW_ROUTE(app, "/")
|
||||||
([&]() {
|
([&]() {
|
||||||
return mstch::render(index_tmpl_str, context);
|
return mstch::render(view, context);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.port(8080).multithreaded().run();
|
app.port(8080).multithreaded().run();
|
||||||
|
|
|
@ -6,11 +6,15 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div>
|
<div>
|
||||||
<h1>{{height}}</h1>
|
<h1>Detailed Monero blockchain explorer</h1>
|
||||||
|
<h2>Current height: {{height}}</h2>
|
||||||
<div>
|
<div>
|
||||||
|
<ul>
|
||||||
{{#blocks}}
|
{{#blocks}}
|
||||||
{{height}}: {{hash}}
|
<li> {{height}}: {{hash}} </li>
|
||||||
{{/blocks}}
|
{{/blocks}}
|
||||||
|
</ul>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -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>());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,6 +144,9 @@ namespace xmreg
|
||||||
array<size_t, 5>
|
array<size_t, 5>
|
||||||
timestamp_difference(uint64_t t1, uint64_t t2);
|
timestamp_difference(uint64_t t1, uint64_t t2);
|
||||||
|
|
||||||
|
string
|
||||||
|
read(string filename);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //XMREG01_TOOLS_H
|
#endif //XMREG01_TOOLS_H
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue