From db6e81a288947eda2e01f9d961468697f0601e05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Teuli=C3=A8re?= Date: Fri, 14 Dec 2012 10:58:25 +0100 Subject: [PATCH] Stats reports: new option to embed the CSS into the HTML file --- extras/reports/stats.py | 10 ++++++++-- extras/reports/stats.tmpl | 8 +++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/extras/reports/stats.py b/extras/reports/stats.py index 6205e2c..3f93475 100755 --- a/extras/reports/stats.py +++ b/extras/reports/stats.py @@ -8,12 +8,15 @@ from Cheetah.Template import Template # Eliot modules import eliot +tmpl_file = "stats.tmpl" +css_file = "stats.css" # Command-line parsing parser = argparse.ArgumentParser(description="""Generate an HTML page roughly equivalent to the Statistics window in Eliot""") parser.add_argument("-s", "--savegame", help="game saved with Eliot", type=file, required=True) parser.add_argument("-o", "--output", help="output file (stdout by default)", type=argparse.FileType('w'), default=sys.stdout) +parser.add_argument("-e", "--embed-css", help="embed the CSS file into the resulting HTML file", default=False, action="store_true") args = parser.parse_args() # Do most of the work: open the save game file, parse it, @@ -21,11 +24,14 @@ args = parser.parse_args() gameData = eliot.readSaveGame(args.savegame.name) # Load the template -with file("stats.tmpl") as f: +with file(tmpl_file) as f: templDef = f.read() # Fill it with values -templ = Template(templDef, {'gameData': gameData}) +templ = Template(templDef, + {'gameData': gameData, + 'embedCss': args.embed_css, + 'cssContents': file(css_file).read()}) # Print the generated document args.output.write(str(templ)); diff --git a/extras/reports/stats.tmpl b/extras/reports/stats.tmpl index 864aec8..39f914f 100644 --- a/extras/reports/stats.tmpl +++ b/extras/reports/stats.tmpl @@ -3,8 +3,14 @@ + $gameData.name + #if $embedCss + + #else - Page Title XXX + #end if