Update cardlib.py

Adding formatting to the format() function to allow for html output
This commit is contained in:
reimannsum 2015-10-30 11:37:20 -04:00
parent 377aa9453c
commit 45caa1c16e

View file

@ -553,7 +553,7 @@ class Card:
return outstr return outstr
def format(self, gatherer = False, for_forum = False, for_mse = False, vdump = False): def format(self, gatherer = False, for_forum = False, for_mse = False, vdump = False, for_html = False):
outstr = '' outstr = ''
if gatherer: if gatherer:
cardname = titlecase(transforms.name_unpass_1_dashes(self.__dict__[field_name])) cardname = titlecase(transforms.name_unpass_1_dashes(self.__dict__[field_name]))
@ -634,6 +634,60 @@ class Card:
outstr += '[/i]' outstr += '[/i]'
outstr += '\n' outstr += '\n'
elif for_html:
outstr += '<div class="card-text">'
cardname = self.__dict__[field_name]
#cardname = transforms.name_unpass_1_dashes(self.__dict__[field_name])
outstr += "<h5>" + cardname + "</h5>"
if self.__dict__[field_rarity]:
if self.__dict__[field_rarity] in utils.json_rarity_unmap:
rarity = utils.json_rarity_unmap[self.__dict__[field_rarity]]
else:
rarity = self.__dict__[field_rarity]
outstr += ' (<b>' + rarity.lower() + '</b>)'
outstr += '\n'
# I need the simple formatting with '{'
coststr = self.__dict__[field_cost].format()
if vdump or not coststr == '_NOCOST_':
outstr += coststr.replace("/","-").replace("{",'<img src="~/mtgencode/Icons/' ).replace("}",'-mana;.png" >')
outstr += '\n'
outstr += ' <b>'.join(self.__dict__[field_supertypes] + self.__dict__[field_types])
if self.__dict__[field_subtypes]:
outstr += ' ' + utils.dash_marker + ' ' + ' '.join(self.__dict__[field_subtypes])
outstr += '</b>\n'
if self.__dict__[field_text].text:
mtext = self.__dict__[field_text].text
mtext = transforms.text_unpass_1_choice(mtext, delimit = True)
#mtext = transforms.text_unpass_2_counters(mtext)
#mtext = transforms.text_unpass_3_uncast(mtext)
mtext = transforms.text_unpass_4_unary(mtext)
mtext = transforms.text_unpass_5_symbols(mtext, for_forum)
#mtext = transforms.text_unpass_6_cardname(mtext, cardname)
mtext = transforms.text_unpass_7_newlines(mtext)
#mtext = transforms.text_unpass_8_unicode(mtext)
newtext = Manatext('')
newtext.text = mtext
newtext.costs = self.__dict__[field_text].costs
outstr += newtext.format().replace("/","-").replace("{",'<img src="~/mtgencode/Icons/' ).replace("}",'-mana;.png" >') + '\n'
if self.__dict__[field_pt]:
outstr += '(' + utils.from_unary(self.__dict__[field_pt]) + ')'
outstr += '\n'
if self.__dict__[field_loyalty]:
outstr += '((' + utils.from_unary(self.__dict__[field_loyalty]) + '))'
outstr += '\n'
if vdump and self.__dict__[field_other]:
outstr += utils.dash_marker * 2
outstr += '\n'
for idx, value in self.__dict__[field_other]:
outstr += '<' + str(idx) + '> ' + str(value)
outstr += '\n'
else: else:
cardname = self.__dict__[field_name] cardname = self.__dict__[field_name]
#cardname = transforms.name_unpass_1_dashes(self.__dict__[field_name]) #cardname = transforms.name_unpass_1_dashes(self.__dict__[field_name])
@ -694,7 +748,10 @@ class Card:
outstr += '\n' outstr += '\n'
if self.bside: if self.bside:
outstr += utils.dash_marker * 8 + '\n' if for_html:
outstr += "<hr>\n"
else:
outstr += utils.dash_marker * 8 + '\n'
outstr += self.bside.format(gatherer = gatherer, for_forum = for_forum) outstr += self.bside.format(gatherer = gatherer, for_forum = for_forum)
return outstr return outstr