git repos / oastat_static_web_generator

commit 7bfcd113

sago007 · 2019-01-08 18:18
7bfcd113f92b958004558bda2717d4e1dbdda021 patch · browse files
parent 537fef31b0c3c629c414b4cc372579a93ba2c826

Added a "game" template

Changed files

M src/oastat_static_web_generator.cpp before
A templates/game.tpl
diff --git a/src/oastat_static_web_generator.cpp b/src/oastat_static_web_generator.cpp index ac458a4..b894d8d 100644 --- a/src/oastat_static_web_generator.cpp +++ b/src/oastat_static_web_generator.cpp
@@ -19,6 +19,8 @@ const size_t MAX_MAP_LIST = 10;
const char* const SAGO_CONNECTION_STRING = "SAGO_CONNECTION_STRING";
+void write_html_game(cppdb::session& database, int game_number);
+
// means of death
typedef enum {
MOD_UNKNOWN,
@@ -214,6 +216,18 @@ OastatPlayer getPlayer(cppdb::session& database, int playerid) {
return ret;
}
+void write_html_game(cppdb::session& database, int game_number) {
+ ctemplate::TemplateDictionary game_tpl("templates/game.tpl");
+ game_tpl.SetValue("GENERATION_DATE", timestamp_now_as_string(database));
+ game_tpl.SetValue("GAME_NUMBER", std::to_string(game_number));
+ std::string output;
+ ctemplate::ExpandTemplate("templates/game.tpl", ctemplate::DO_NOT_STRIP, &game_tpl, &output);
+ std::ofstream myfile;
+ myfile.open (cmdargs.output_dir+"/game/"+std::to_string(game_number)+".html");
+ myfile << output;
+ myfile.close();
+}
+
void write_html_index(cppdb::session& database) {
ctemplate::TemplateDictionary index_tpl("templates/index.tpl");
index_tpl.SetValue("GENERATION_DATE", timestamp_now_as_string(database));
@@ -276,6 +290,7 @@ void write_html_index(cppdb::session& database) {
void write_files(cppdb::session& database) {
write_html_index(database);
+ write_html_game(database, 1);
}
@@ -322,6 +337,7 @@ int main(int argc, const char* argv[]) {
cppdb::session database(cmdargs.connectstring);
do_dbtest(database);
create_dir_recursive(cmdargs.output_dir+"/static");
+ create_dir_recursive(cmdargs.output_dir+"/game");
copy_static_files("static_content", cmdargs.output_dir+"/static");
write_files(database);
return 0;
diff --git a/templates/game.tpl b/templates/game.tpl new file mode 100644 index 0000000..72f0d47 --- /dev/null +++ b/templates/game.tpl
@@ -0,0 +1,13 @@
+{{%AUTOESCAPE context="HTML"}}
+
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <meta http-equiv="Content-Language" content="en">
+ <meta name="description" content="OpenArena stats by oastats">
+ <meta rel="stylesheet" href="../static/css/oastat.css" type="text/css">
+ <title>OpenArena Stats - {{GAME_NUMBER}}</title>
+</head>
+<body>
+</body>
+</html>