From 45caa1c16e7b94dbf8745f35564b10179b46b92a Mon Sep 17 00:00:00 2001 From: reimannsum Date: Fri, 30 Oct 2015 11:37:20 -0400 Subject: [PATCH] Update cardlib.py Adding formatting to the format() function to allow for html output --- lib/cardlib.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/lib/cardlib.py b/lib/cardlib.py index 3478fcc..75dca7f 100644 --- a/lib/cardlib.py +++ b/lib/cardlib.py @@ -553,7 +553,7 @@ class Card: 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 = '' if gatherer: cardname = titlecase(transforms.name_unpass_1_dashes(self.__dict__[field_name])) @@ -634,6 +634,60 @@ class Card: outstr += '[/i]' outstr += '\n' + elif for_html: + outstr += '
' + cardname = self.__dict__[field_name] + #cardname = transforms.name_unpass_1_dashes(self.__dict__[field_name]) + outstr += "
" + cardname + "
" + 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 += ' (' + rarity.lower() + ')' + outstr += '\n' + + # I need the simple formatting with '{' + coststr = self.__dict__[field_cost].format() + if vdump or not coststr == '_NOCOST_': + outstr += coststr.replace("/","-").replace("{",'') + outstr += '\n' + + outstr += ' '.join(self.__dict__[field_supertypes] + self.__dict__[field_types]) + if self.__dict__[field_subtypes]: + outstr += ' ' + utils.dash_marker + ' ' + ' '.join(self.__dict__[field_subtypes]) + outstr += '\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("{",'') + '\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: cardname = self.__dict__[field_name] #cardname = transforms.name_unpass_1_dashes(self.__dict__[field_name]) @@ -694,7 +748,10 @@ class Card: outstr += '\n' if self.bside: - outstr += utils.dash_marker * 8 + '\n' + if for_html: + outstr += "
\n" + else: + outstr += utils.dash_marker * 8 + '\n' outstr += self.bside.format(gatherer = gatherer, for_forum = for_forum) return outstr