diff options
author | emkael <emkael@tlen.pl> | 2018-05-01 11:53:23 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2018-05-01 11:53:23 +0200 |
commit | 28218c054785e3cb77b6e36182bce97c8010319e (patch) | |
tree | 7006179fbcbe203ac588d011a31b797074907151 /jfr_playoff/template.py | |
parent | 9a5f06ee9cddd38e11f49a2f934de202d34e63e2 (diff) |
Refactoring template "engine" to provide a uniform interface
Diffstat (limited to 'jfr_playoff/template.py')
-rw-r--r-- | jfr_playoff/template.py | 364 |
1 files changed, 186 insertions, 178 deletions
diff --git a/jfr_playoff/template.py b/jfr_playoff/template.py index b99c7c7..0699c1e 100644 --- a/jfr_playoff/template.py +++ b/jfr_playoff/template.py @@ -1,180 +1,188 @@ # -*- coding: utf-8 -*- -MATCH_TABLE = ''' -<table border="0" cellspacing="0"> -<tr> -<td class="s12" width="%d"> </td> -<td class="bdcc2" width="%d"> wynik </td> -</tr> -%s -</table> -''' - -MATCH_LINK = ''' -<a href="%s" target="_top"> -%s -</a> -''' - -MATCH_SCORE = ''' - %.1f -''' - -MATCH_TEAM_LINK = ''' -<a href="%s" onmouseover="Tip('%s')" onmouseout="UnTip()">%s</a> -''' - -MATCH_TEAM_NON_LINK = ''' -<a onmouseover="Tip('%s')" onmouseout="UnTip()">%s</a> -''' - -MATCH_TEAM_ROW = ''' -<tr class="%s"> -<td class="bd1"> %s </td> -<td class="bdc"> -%s -</td> -</tr> -''' - -MATCH_RUNNING = ''' -<img src="images/A.gif" /> -<span style="font-size: 10pt">%d</span> -<img src="images/A.gif" /> -''' - -MATCH_GRID = ''' -<div style="position: relative; width: %dpx; height: %dpx; margin: 10px"> -<canvas width="%d" height="%d" id="playoff_canvas" %s></canvas> -%s -<script src="sklady/playoff.js" type="text/javascript"></script> -</div> -''' - -MATCH_GRID_PHASE_LINK = ''' -<a href="%s" target="_top" style="display: inline-block; width: %dpx; text-align: center; position: absolute; top: 0; left: %dpx"> -%s -</a> -''' - -MATCH_GRID_PHASE_NON_LINK = ''' -<span class="phase_header" style="display: inline-block; width: %dpx; text-align: center; position: absolute; top: 0; left: %dpx"> -<p style="margin: 0">%s</p> -</span> -''' - -MATCH_GRID_PHASE = ''' -<font size="4">%s</font> -''' - -MATCH_GRID_PHASE_RUNNING = ''' -<img src="images/A.gif" /> -<font size="4">%s</font> -<img src="images/A.gif" /> -''' - -MATCH_BOX = ''' -<div style="text-align: center; position: absolute; left: %dpx; top: %dpx" data-id="%d" data-winner="%s" data-loser="%s" class="playoff_matchbox"> -%s -</div> -''' - -LEADERBOARD = ''' -<table border="0" cellspacing="0"> -<tr> -<td class="bdnl12" colspan="2" align="center"><b> KLASYFIKACJA KOŃCOWA </b></td> -</tr> -<tr> -<td class="e" colspan="2"> </td> -</tr> -<tr> -<td class="bdcc12"> miejsce </td> -<td class="bdcc2"> drużyna </td> -</tr> -%s -</table> -''' - -LEADERBOARD_ROW = ''' -<tr class="%s"> -<td class="bdc1">%d</td> -<td class="bd"> - %s %s -</td> -</tr> -''' - -LEADERBOARD_ROW_FLAG = ''' -<img class="fl" src="images/%s" /> -''' - -LEADERBOARD_CAPTION_TABLE = ''' -<table class="caption_table" border="0" cellspacing="0"> -<tr><td class="e"> </td></tr> -<tr><td class="bdnl12" align="center"><b> LEGENDA </b></td></tr> -%s -</table> -''' - -LEADERBOARD_CAPTION_TABLE_ROW = ''' -<tr class="%s"> -<td class="bd1"> - %s -</td> -</tr> -''' - -PAGE_HEAD = ''' -<meta http-equiv="Pragma" content="no-cache" /> -<meta http-equiv="Cache-Control" content="no-cache" /> -<meta name="robots" content="noarchive" /> -<meta http-equiv="expires" content="0" /> -<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> -<meta name="Generator" content="PlayOff" /> -%s -<title>%s</title> -<link rel="stylesheet" type="text/css" href="css/kolorki.css" /> -<script type="text/javascript" src="sklady/myAjax.js"></script> -''' - -PAGE_HEAD_REFRESH = ''' -<meta http-equiv="Refresh" content="%d" /> -''' - -PAGE_BODY = ''' -<script type="text/javascript" src="sklady/wz_tooltip.js"></script> -%s -%s -<p> -%s -</p> -%s -%s -%s -''' - -PAGE_BODY_FOOTER = ''' -<p class="f"> Admin ©Jan Romański'2005, PlayOff ©Michał Klichowicz'2017-2018, strona wygenerowana %s</p> -''' - -PAGE = ''' -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> -<html> -<head> -%s -</head> -<body class="all"> -%s -</body> -</html> -''' - -SWISS_LINK = ''' -[<a href="%s" class="zb" target="_top"> %s </a>]<br /><br /> -''' - -SWISS_RUNNING_LINK = ''' -[<a href="%s" class="zb" target="_top"> <img src="images/A.gif" /> %s <img src="images/A.gif" /> </a>]<br /><br /> -''' - -SWISS_DEFAULT_LABEL = 'Turniej o %d. miejsce' +class TemplateStrings(object): + + MATCH_TABLE = ''' + <table border="0" cellspacing="0"> + <tr> + <td class="s12" width="%d"> </td> + <td class="bdcc2" width="%d"> wynik </td> + </tr> + %s + </table> + ''' + + MATCH_LINK = ''' + <a href="%s" target="_top"> + %s + </a> + ''' + + MATCH_SCORE = ''' + %.1f + ''' + + MATCH_TEAM_LINK = ''' + <a href="%s" onmouseover="Tip('%s')" onmouseout="UnTip()">%s</a> + ''' + + MATCH_TEAM_NON_LINK = ''' + <a onmouseover="Tip('%s')" onmouseout="UnTip()">%s</a> + ''' + + MATCH_TEAM_ROW = ''' + <tr class="%s"> + <td class="bd1"> %s </td> + <td class="bdc"> + %s + </td> + </tr> + ''' + + MATCH_RUNNING = ''' + <img src="images/A.gif" /> + <span style="font-size: 10pt">%d</span> + <img src="images/A.gif" /> + ''' + + MATCH_GRID = ''' + <div style="position: relative; width: %dpx; height: %dpx; margin: 10px"> + <canvas width="%d" height="%d" id="playoff_canvas" %s></canvas> + %s + <script src="sklady/playoff.js" type="text/javascript"></script> + </div> + ''' + + MATCH_GRID_PHASE_LINK = ''' + <a href="%s" target="_top" style="display: inline-block; width: %dpx; text-align: center; position: absolute; top: 0; left: %dpx"> + %s + </a> + ''' + + MATCH_GRID_PHASE_NON_LINK = ''' + <span class="phase_header" style="display: inline-block; width: %dpx; text-align: center; position: absolute; top: 0; left: %dpx"> + <p style="margin: 0">%s</p> + </span> + ''' + + MATCH_GRID_PHASE = ''' + <font size="4">%s</font> + ''' + + MATCH_GRID_PHASE_RUNNING = ''' + <img src="images/A.gif" /> + <font size="4">%s</font> + <img src="images/A.gif" /> + ''' + + MATCH_BOX = ''' + <div style="text-align: center; position: absolute; left: %dpx; top: %dpx" data-id="%d" data-winner="%s" data-loser="%s" class="playoff_matchbox"> + %s + </div> + ''' + + LEADERBOARD = ''' + <table border="0" cellspacing="0"> + <tr> + <td class="bdnl12" colspan="2" align="center" style="text-transform: uppercase"><b> KLASYFIKACJA KOŃCOWA </b></td> + </tr> + <tr> + <td class="e" colspan="2"> </td> + </tr> + <tr> + <td class="bdcc12"> miejsce </td> + <td class="bdcc2"> drużyna </td> + </tr> + %s + </table> + ''' + + LEADERBOARD_ROW = ''' + <tr class="%s"> + <td class="bdc1">%d</td> + <td class="bd"> + %s %s + </td> + </tr> + ''' + + LEADERBOARD_ROW_FLAG = ''' + <img class="fl" src="images/%s" /> + ''' + + LEADERBOARD_CAPTION_TABLE = ''' + <table class="caption_table" border="0" cellspacing="0"> + <tr><td class="e"> </td></tr> + <tr><td class="bdnl12" align="center" style="text-transform: uppercase"><b> LEGENDA </b></td></tr> + %s + </table> + ''' + + LEADERBOARD_CAPTION_TABLE_ROW = ''' + <tr class="%s"> + <td class="bd1"> + %s + </td> + </tr> + ''' + + PAGE_HEAD = ''' + <meta http-equiv="Pragma" content="no-cache" /> + <meta http-equiv="Cache-Control" content="no-cache" /> + <meta name="robots" content="noarchive" /> + <meta http-equiv="expires" content="0" /> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <meta name="Generator" content="PlayOff" /> + %s + <title>%s</title> + <link rel="stylesheet" type="text/css" href="css/kolorki.css" /> + <script type="text/javascript" src="sklady/myAjax.js"></script> + ''' + + PAGE_HEAD_REFRESH = ''' + <meta http-equiv="Refresh" content="%d" /> + ''' + + PAGE_BODY = ''' + <script type="text/javascript" src="sklady/wz_tooltip.js"></script> + %s + %s + <p> + %s + </p> + %s + %s + %s + ''' + + PAGE_BODY_FOOTER = ''' + <p class="f"> Admin ©Jan Romański'2005, PlayOff ©Michał Klichowicz'2017-2018, strona wygenerowana %s</p> + ''' + + PAGE = ''' + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> + <html> + <head> + %s + </head> + <body class="all"> + %s + </body> + </html> + ''' + + SWISS_LINK = ''' + [<a href="%s" class="zb" target="_top"> %s </a>]<br /><br /> + ''' + + SWISS_RUNNING_LINK = ''' + [<a href="%s" class="zb" target="_top"> <img src="images/A.gif" /> %s <img src="images/A.gif" /> </a>]<br /><br /> + ''' + + SWISS_DEFAULT_LABEL = 'Turniej o %d. miejsce' + +class Template(object): + + @staticmethod + def get(string, *params): + return getattr(TemplateStrings, string).decode('utf8') % params |