-'''.strip()
+'''
HTML_CLEAR_FLOATS = ''
+HTML_ENTITY_HORIZONTAL_BAR = '―'
+HTML_ENTITY_MULTIPLICATION_SIGN = '×'
+HTML_ENTITY_FIGURE_DASH = '‒'
+
+PRE_PLACEHOLDER_CAMPAIGNS = "PLACE CAMPAIGNS HERE\n"
+PRE_PLACEHOLDER_ERAS = "PLACE ERAS HERE\n"
+
+def website_header(title='', path='../../', classes=[]):
+ """Returns the website header with the specified parameters."""
+ return WESMERE_HEADER % {
+ "title": title,
+ "path": path,
+ "cssprefix": WESMERE_CSS_PREFIX,
+ "cssver": WESMERE_CSS_VERSION,
+ "classes": ' '.join(['wmlunits'] + classes)}
+
+def website_footer(timestamp=''):
+ """Returns the website footer, including the current timestamp."""
+ if not timestamp:
+ timestamp = "Last updated on " + time.ctime() + "."
+ return WESMERE_FOOTER % { "generation_note": timestamp }
+
+
all_written_html_files = []
error_only_once = {}
+
def error_message(message):
if message in error_only_once:
return
@@ -131,6 +189,42 @@ def cleantext(text, quote=True):
return text
return html.escape(text, quote)
+def resistance_rating_color_class(resistance):
+ """Return a color class adequate for the provided unit resistance value."""
+ if resistance < 0:
+ return 'red'
+ elif resistance <= 20:
+ return 'yellow'
+ elif resistance <= 40:
+ return 'olive'
+ else:
+ return 'green'
+
+def defense_rating_color_class(defense):
+ """Return a color class adequate for the provided terrain defense value."""
+ if defense <= 10:
+ return 'red'
+ elif defense <= 30:
+ return 'yellow'
+ elif defense <= 50:
+ return 'olive'
+ else:
+ return 'green'
+
+def mvtcost_rating_color_class(str_mvtcost, str_moves):
+ """Return a color class adequate for the provided movement cost value."""
+ cost = int_fallback(str_mvtcost, 99)
+ moves = int_fallback(str_moves)
+ if cost >= moves:
+ return 'gray'
+ elif cost > moves/2:
+ return 'red'
+ elif cost > 1:
+ return 'yellow'
+ else:
+ return 'green'
+
+
class MyFile:
"""
Python 2 is a bit weird with encodings, really should switch this to
@@ -373,8 +467,6 @@ class HTMLOutput:
langlist = list(languages.keys())
langlist.sort()
- write(TOP_BAR % {"path" : "../../"})
-
write('
')
write('
')
@@ -389,22 +481,41 @@ class HTMLOutput:
return abbrev
def add_menu(menuid, name, classes='', is_table_container=False):
+ """
+ Writes the initial portion of a sidebar item, including the item's
+ label, the start tag for the popup menu container, and the label
+ for said menu.
+
+ If is_table_container=True, the popup menu prolog is suitable for
+ a table (currently used for the Language menu). This will be
+ removed one day, hopefully. (TODO)
+ """
html_name = cleantext(name)
html_classes = " ".join((cleantext(classes), "popuptrigger"))
+ # FIXME: This is legacy code needed for the Language menu, since it's
+ # a table and we can't make it otherwise because CSS column
+ # support is still hit-or-miss for some browsers still in use.
child_tag = 'ul' if not is_table_container else 'div'
label_tag = 'li' if not is_table_container else 'div'
write('
')
- write('' + html_name + "")
+ write('' + html_name + '')
write('<' + child_tag + ' class="popupmenu" id="' + menuid + '" role="menu" aria-label="' + html_name + '">')
write('<' + label_tag + '>' + html_name + '' + label_tag + '>')
- # FIXME: This is legacy code needed for the Language menu, since it's
- # a table and we can't make it otherwise since CSS column
- # support is still hit-or-miss for some browsers still in use.
- def add_menu2(menuid, name, classes=''):
- add_menu(menuid, name, classes, is_table_container=True)
+ def add_menuitem_placeholder():
+ """Writes a horizontal bar serving as a menu placeholder."""
+ write('
' + HTML_ENTITY_HORIZONTAL_BAR + '
')
def add_menuitem(url, label, standalone=False, title=''):
+ """
+ Writes a sidebar item.
+
+ If standalone=True, the item will be provided without the list
+ element tags so it can be used in pretty much any context. In
+ reality, the option is only provided for use with add_menu() with
+ is_table_container=True and it will be removed at some point in
+ the hopefully not-so-far future (TODO).
+ """
if not standalone:
write('
')
extra_attr = (' title="%s"' % cleantext(title)) if title else ''
@@ -413,10 +524,12 @@ class HTMLOutput:
if not standalone:
write('
')
- def add_menuitem_placeholder():
- write('
' + HTML_ENTITY_HORIZONTAL_BAR + '
')
-
def end_menu(is_table_container=False):
+ """
+ Writes the closing tags for a menu started with start_menu().
+ The is_table_container value used here ought to be the same as the
+ original.
+ """
if not is_table_container:
write('
\n')
else:
@@ -428,13 +541,13 @@ class HTMLOutput:
# Campaigns
x = self.translate("addon_type^Campaign", "wesnoth")
add_menu("campaigns_menu", x)
- write("PLACE CAMPAIGNS HERE\n")
+ write(PRE_PLACEHOLDER_CAMPAIGNS)
end_menu()
# Eras
x = self.translate("Era", "wesnoth")
add_menu("eras_menu", x)
- write("PLACE ERAS HERE\n")
+ write(PRE_PLACEHOLDER_ERAS)
end_menu()
# Races / Factions
@@ -490,8 +603,6 @@ class HTMLOutput:
# Add entries for the races also to the navbar itself.
if not self.is_era:
- class Entry:
- pass
races = {}
for uid, u in list(self.wesnoth.unit_lookup.items()):
@@ -540,31 +651,31 @@ class HTMLOutput:
# Languages
x = self.translate("Language", "wesnoth")
- add_menu2("languages_menu", x)
+ add_menu("languages_menu", x, is_table_container=True)
cell = 0
col = 0
colcount = 5
lastcell = len(langlist) - 1
- write("
")
- write("
")
+ write('
')
+ write('
')
for lang in langlist:
cell += 1
col += 1
- write("
")
+ write('
')
filename = self.target if self.addon == 'mainline' else 'mainline.html'
url = cleanurl('../%s/%s' % (lang, filename))
# TODO: Maybe use the language name instead of its code for the label?
add_menuitem(url, lang, title=languages[lang], standalone=True)
- write("
")
+ write('')
if cell % colcount == 0:
if cell < lastcell:
- write("
")
+ write('
')
col = 0
if col:
for i in range(colcount - col + 1, colcount):
- write("
' % i)
+ write('')
pic = image_collector.add_image("general",
"../../../images/misc/leader-crown.png",
@@ -673,7 +784,7 @@ class HTMLOutput:
crownimage = cleanurl(os.path.join(PICS_LOCATION, pic))
ms = None
for row in range(len(rows)):
- write("
\n")
+ write('
\n')
for column in range(6):
hspan, vspan, un = rows[row][column]
if vspan:
@@ -681,9 +792,9 @@ class HTMLOutput:
if hspan == 1 and vspan == 1:
pass
elif hspan == 1:
- attributes += " rowspan=\"%d\"" % vspan
+ attributes += ' rowspan="%d"' % vspan
elif vspan == 1:
- attributes += " colspan=\"%d\"" % hspan
+ attributes += ' colspan="%d"' % hspan
if un and isinstance(un, helpers.GroupNode):
# Find the current multiplayer side so we can show the
@@ -700,14 +811,14 @@ class HTMLOutput:
racename = un.name
# TODO: we need to use a unique race id instead of a potentially duplicate
# name for the header id and link target!
- attributes += " id=\"%s\" class=\"raceheader\"" % cleantext(racename)
- write("
" % cleantext(_(r), quote=False))
+ write(' %s' % cleantext(_(r), quote=False))
n = attack.get_text_val("number")
x = attack.get_text_val("damage")
x = '%s %s %s' % (cleantext(x, quote=False), HTML_ENTITY_MULTIPLICATION_SIGN, cleantext(n, quote=False))
- write("
%s" % x)
+ write('
%s' % x)
t = T(attack, "type")
write(' %s
' % cleantext(_(t), quote=False))
@@ -1041,35 +1146,16 @@ class HTMLOutput:
else:
error_message("Warning: Weapon special %s has no name for %s.\n" %
(special.name.decode("utf8"), uid))
- write("