diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d88ab2..0cf8bf7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,4 +2,4 @@ cmake_minimum_required(VERSION 2.8.9) project (oastat_static_web_generator) find_package(Boost COMPONENTS program_options REQUIRED) add_executable(oastat_static_web_generator src/oastat_static_web_generator.cpp) -TARGET_LINK_LIBRARIES( oastat_static_web_generator ${Boost_LIBRARIES} cppdb ) +TARGET_LINK_LIBRARIES( oastat_static_web_generator ${Boost_LIBRARIES} cppdb ctemplate ) diff --git a/src/oastat_static_web_generator.cpp b/src/oastat_static_web_generator.cpp index 76354b9..ee825d6 100644 --- a/src/oastat_static_web_generator.cpp +++ b/src/oastat_static_web_generator.cpp @@ -3,6 +3,7 @@ #include #include "command_arguments.hpp" #include +#include #ifndef VERSIONNUMBER #define VERSIONNUMBER "0.1.0" @@ -12,6 +13,16 @@ CommandArguments cmdargs; const char* const SAGO_CONNECTION_STRING = "SAGO_CONNECTION_STRING"; +std::string timestamp_now_as_string(cppdb::session& database) { + cppdb::statement st = database.prepare("SELECT now()"); + cppdb::result res = st.query(); + if(res.next()) { + std::string value; + res >> value; + return value; + } + return ""; +} static void create_dir_recursive(const std::string& path) { std::string command = std::string("mkdir -p \"")+path+"\""; @@ -31,10 +42,13 @@ static void copy_static_files(const std::string& source, const std::string& dest void write_html_index(cppdb::session& database) { + ctemplate::TemplateDictionary index_tpl("templates/index.tpl"); + index_tpl.SetValue("GENERATION_DATE", timestamp_now_as_string(database)); + std::string output; + ctemplate::ExpandTemplate("templates/index.tpl", ctemplate::DO_NOT_STRIP, &index_tpl, &output); std::ofstream myfile; myfile.open (cmdargs.output_dir+"/index.html"); - myfile << "\n"; - myfile << "\n"; + myfile << output; myfile.close(); } @@ -43,6 +57,8 @@ void write_files(cppdb::session& database) { } + + void do_dbtest(cppdb::session& database) { cppdb::statement st = database.prepare("SELECT now()"); cppdb::result res = st.query(); diff --git a/templates/index.tpl b/templates/index.tpl new file mode 100644 index 0000000..dceab49 --- /dev/null +++ b/templates/index.tpl @@ -0,0 +1,22 @@ +{{%AUTOESCAPE context="HTML"}} + + + + + + + +OpenArena Stats + + +
+ + +
+
Last updated on {{GENERATION_DATE}}
+
OpenArena Stats
+
+
+ + +