Stats reports: new option to embed the CSS into the HTML file

This commit is contained in:
Olivier Teulière 2012-12-14 10:58:25 +01:00
parent f38c7361c1
commit db6e81a288
2 changed files with 15 additions and 3 deletions

View file

@ -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));

View file

@ -3,8 +3,14 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8"/>
<title>$gameData.name</title>
#if $embedCss
<style type="text/css">
$cssContents
</style>
#else
<link rel="stylesheet" type="text/css" href="stats.css" />
<title>Page Title XXX</title>
#end if
</head>
<body>
<table class="statsTable">