Started working on optionnals

This commit is contained in:
Maximilien Rigaut 2022-05-30 23:23:06 +02:00
parent c943bb94a0
commit 42436e51f6
No known key found for this signature in database
GPG Key ID: 4F14B23709ADA5B1
2 changed files with 10 additions and 8 deletions

View File

@ -16,7 +16,7 @@ from bootstraparse.modules.syntax import split_optionals
Named tuple containing all necessary information to select the appropriate Named tuple containing all necessary information to select the appropriate
markup element and pass it over to ExportManager. markup element and pass it over to ExportManager.
""" """
ExportRequest = namedtuple("ExportRequest", ["type", "subtype", "optionals", "others"], defaults=[None, None, "", {}]) ExportRequest = namedtuple("ExportRequest", ["type", "subtype", "optionals", "others"], defaults=[None, None, None, {}])
""" """
Named tuple containing all necessary information to proceed with the Named tuple containing all necessary information to proceed with the
@ -34,7 +34,7 @@ def format_optionals(optionals):
split = split_optionals(optionals) split = split_optionals(optionals)
h = split.html_insert h = split.html_insert
c = split.class_insert c = split.class_insert
output = f'''{h}{' ' if h and c else ''}{f'class="{c}"' if c else ''}''' output = f'''{' ' if h or c else ''}{h}{' ' if h and c else ''}{f'class="{c}"' if c else ''}'''
return output return output
@ -80,7 +80,7 @@ class ExportManager:
Function for initializing other transform functions. Function for initializing other transform functions.
:return: start, end, optionals :return: start, end, optionals
""" """
start, end, optionals = None, None, '' start, end = None, None
try: try:
start, end = self.templates["bootstrap"][export_request.type][export_request.subtype] start, end = self.templates["bootstrap"][export_request.type][export_request.subtype]
except KeyError: except KeyError:
@ -95,10 +95,12 @@ class ExportManager:
level='CRITICAL' level='CRITICAL'
) )
# future: allow for template selection # future: allow for template selection
if export_request.optionals != '': # TODO: Use format_optionals # error when not giving "" rich.inspect(export_request.optionals)
optionals = " " # + export_request.optionals # causes error, TODO: investigate optionals = format_optionals(export_request.optionals)
else: # if export_request.optionals != '': # TODO: Use format_optionals # error when not giving ""
optionals = '' # optionals = " " + export_request.optionals # causes error, TODO: investigate
# else:
# optionals = ''
return start, end, optionals return start, end, optionals
def basic_transform(self, export_request): def basic_transform(self, export_request):

View File

@ -290,7 +290,7 @@ class PreParser:
shortcut_s = self.get_element_from_config('aliases', 'images', shortcut) shortcut_s = self.get_element_from_config('aliases', 'images', shortcut)
_, _, var_list, var_dict = export.split_optionals(optionals) _, _, var_list, var_dict = export.split_optionals(optionals)
request = export.ExportRequest('inline_elements', 'image', export.format_optionals(optionals)) request = export.ExportRequest('inline_elements', 'image', optionals)
output = self.__env.export_mngr(request) output = self.__env.export_mngr(request)
return output.start + self.make_replacements(shortcut_s, *var_list, **var_dict) + output.end return output.start + self.make_replacements(shortcut_s, *var_list, **var_dict) + output.end