Debug fix for optionnals
This commit is contained in:
parent
61351acb81
commit
cbee016a6a
|
|
@ -10,7 +10,7 @@
|
||||||
from bootstraparse.modules import config, pathresolver, error_mngr, context_mngr
|
from bootstraparse.modules import config, pathresolver, error_mngr, context_mngr
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
from bootstraparse.modules.syntax import split_optionals
|
from bootstraparse.modules.syntax import split_optionals, OptionalToken
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Named tuple containing all necessary information to select the appropriate
|
Named tuple containing all necessary information to select the appropriate
|
||||||
|
|
@ -29,7 +29,10 @@ def format_optionals(optionals):
|
||||||
"""
|
"""
|
||||||
Function handling parser output optional object, splitting it between html_insert and class_insert
|
Function handling parser output optional object, splitting it between html_insert and class_insert
|
||||||
on one hand and var on the other hand.
|
on one hand and var on the other hand.
|
||||||
rtype: str
|
:param optionals: SplitToken namedtuple
|
||||||
|
:type optionals: OptionalToken
|
||||||
|
:return: The formatted optionals (With the pretty whitespace)
|
||||||
|
:rtype: str
|
||||||
"""
|
"""
|
||||||
split = split_optionals(optionals)
|
split = split_optionals(optionals)
|
||||||
h = split.html_insert
|
h = split.html_insert
|
||||||
|
|
@ -42,9 +45,9 @@ class ExportManager:
|
||||||
"""
|
"""
|
||||||
Transforms ExportRequest tuples to ExportResponse tuples with the config-provided appropriate markup.
|
Transforms ExportRequest tuples to ExportResponse tuples with the config-provided appropriate markup.
|
||||||
"""
|
"""
|
||||||
def __init__(self, cnoifg, templates):
|
def __init__(self, cnoifg, templates): # noqa
|
||||||
# self.config = cnoifg TODO: actually import config
|
# self.config = cnoifg TODO: actually import config
|
||||||
# self.templates = templates TODO: actually import templates
|
# self.templates = templates # noqa TODO: actually import templates
|
||||||
self.config = config.ConfigLoader(pathresolver.b_path("configs/"))
|
self.config = config.ConfigLoader(pathresolver.b_path("configs/"))
|
||||||
self.templates = config.ConfigLoader(pathresolver.b_path("templates/"))
|
self.templates = config.ConfigLoader(pathresolver.b_path("templates/"))
|
||||||
self.advanced_export = {
|
self.advanced_export = {
|
||||||
|
|
@ -127,6 +130,8 @@ class ExportManager:
|
||||||
def header_transform(self, export_request):
|
def header_transform(self, export_request):
|
||||||
"""
|
"""
|
||||||
Specific template for headers.
|
Specific template for headers.
|
||||||
|
:type export_request: ExportRequest
|
||||||
|
:rtype: ExportResponse
|
||||||
"""
|
"""
|
||||||
start, end, optionals = self._get_template(export_request)
|
start, end, optionals = self._get_template(export_request)
|
||||||
try:
|
try:
|
||||||
|
|
@ -145,6 +150,7 @@ class ExportManager:
|
||||||
def display_transform(self, export_request):
|
def display_transform(self, export_request):
|
||||||
"""
|
"""
|
||||||
Specific template for display.
|
Specific template for display.
|
||||||
|
:type export_request: ExportRequest
|
||||||
"""
|
"""
|
||||||
start, end, optionals = self._get_template(export_request)
|
start, end, optionals = self._get_template(export_request)
|
||||||
start = start.format(optionals=optionals, display_level=export_request.others["display_level"])
|
start = start.format(optionals=optionals, display_level=export_request.others["display_level"])
|
||||||
|
|
@ -153,6 +159,7 @@ class ExportManager:
|
||||||
def link_transform(self, export_request):
|
def link_transform(self, export_request):
|
||||||
"""
|
"""
|
||||||
Specific template for link.
|
Specific template for link.
|
||||||
|
:type export_request: ExportRequest
|
||||||
"""
|
"""
|
||||||
start, end, _ = self._get_template(export_request)
|
start, end, _ = self._get_template(export_request)
|
||||||
start = start.format(url=export_request.others["url"])
|
start = start.format(url=export_request.others["url"])
|
||||||
|
|
@ -161,6 +168,7 @@ class ExportManager:
|
||||||
def t_transform(self, export_request):
|
def t_transform(self, export_request):
|
||||||
"""
|
"""
|
||||||
Specific template for table content.
|
Specific template for table content.
|
||||||
|
:type export_request: ExportRequest
|
||||||
"""
|
"""
|
||||||
start, end, _ = self._get_template(export_request)
|
start, end, _ = self._get_template(export_request)
|
||||||
start = start.format(col_span=export_request.others["col_span"])
|
start = start.format(col_span=export_request.others["col_span"])
|
||||||
|
|
@ -169,6 +177,7 @@ class ExportManager:
|
||||||
def image_transform(self, export_request):
|
def image_transform(self, export_request):
|
||||||
"""
|
"""
|
||||||
Specific template for images.
|
Specific template for images.
|
||||||
|
:type export_request: ExportRequest
|
||||||
"""
|
"""
|
||||||
start, end, optionals = self._get_template(export_request)
|
start, end, optionals = self._get_template(export_request)
|
||||||
end = end.format(optionals=optionals)
|
end = end.format(optionals=optionals)
|
||||||
|
|
@ -197,7 +206,7 @@ class ContextConverter:
|
||||||
Main method processing the given pile.
|
Main method processing the given pile.
|
||||||
"""
|
"""
|
||||||
for container in self.pile:
|
for container in self.pile:
|
||||||
print(container.export(self.exporter))
|
print(container.export(self.exporter)) # TODO : Finish this
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ import os
|
||||||
from itertools import zip_longest
|
from itertools import zip_longest
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
|
import rich
|
||||||
|
|
||||||
from bootstraparse.modules.error_mngr import MismatchedContainerError
|
from bootstraparse.modules.error_mngr import MismatchedContainerError
|
||||||
|
|
||||||
import pyparsing as pp
|
import pyparsing as pp
|
||||||
|
|
@ -330,6 +332,13 @@ SplitOptionals = namedtuple(
|
||||||
|
|
||||||
|
|
||||||
def split_optionals(optionals):
|
def split_optionals(optionals):
|
||||||
|
"""
|
||||||
|
Splits the optional attributes into separate lists.
|
||||||
|
:param optionals: list of optional attributes
|
||||||
|
:type optionals: OptionalToken
|
||||||
|
:return: SplitOptionals object containing the split optionals
|
||||||
|
:rtype: SplitOptionals
|
||||||
|
"""
|
||||||
var_list = []
|
var_list = []
|
||||||
var_dict = {}
|
var_dict = {}
|
||||||
ci = ''
|
ci = ''
|
||||||
|
|
@ -342,11 +351,12 @@ def split_optionals(optionals):
|
||||||
elif element.label == 'optional:insert':
|
elif element.label == 'optional:insert':
|
||||||
hi += " " + element.content[0]
|
hi += " " + element.content[0]
|
||||||
elif element.label == 'optional:var':
|
elif element.label == 'optional:var':
|
||||||
for e in element.content.var:
|
rich.inspect(optionals)
|
||||||
|
for e in element.content:
|
||||||
if e.label == 'be:var':
|
if e.label == 'be:var':
|
||||||
var_list.append(e.content.value[0])
|
var_list.append(e.content[0])
|
||||||
elif e.label == 'be:assign':
|
elif e.label == 'be:assign':
|
||||||
var_dict[e.content.assignation.var_name] = e.content.assignation.var_value[0]
|
var_dict[e.content[0][0]] = e.content[0][1] # Using the names makes it hard to debug
|
||||||
return SplitOptionals(html_insert=hi[1:], class_insert=ci[1:], var_list=var_list, var_dict=var_dict)
|
return SplitOptionals(html_insert=hi[1:], class_insert=ci[1:], var_list=var_list, var_dict=var_dict)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,14 @@ zipped_templates = [
|
||||||
for item in sublist
|
for item in sublist
|
||||||
]
|
]
|
||||||
|
|
||||||
|
_opts = syntax.OptionalToken([
|
||||||
|
syntax.OptionalVarToken([
|
||||||
|
syntax.BeAssignToken([["class", "blue"]]),
|
||||||
|
syntax.BeValueToken([123]),
|
||||||
|
]),
|
||||||
|
syntax.OptionalInsertToken(["var='test', number=11"]),
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
def test_export():
|
def test_export():
|
||||||
"""
|
"""
|
||||||
|
|
@ -108,15 +116,13 @@ def test_get_template_error():
|
||||||
|
|
||||||
def test_with_optionnals():
|
def test_with_optionnals():
|
||||||
em = export.ExportManager("test", "test")
|
em = export.ExportManager("test", "test")
|
||||||
em(export.ExportRequest("structural_elements", "div")) # noqa E741
|
em(export.ExportRequest("structural_elements", "div", _opts)) # noqa E741
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.xfail(reason="Not implemented")
|
@pytest.mark.xfail(reason="Not implemented")
|
||||||
def test_format_optionnals():
|
def test_format_optionnals():
|
||||||
import rich
|
|
||||||
from bootstraparse.modules import syntax # noqa E402
|
from bootstraparse.modules import syntax # noqa E402
|
||||||
export.format_optionals("")
|
export.format_optionals(_opts)
|
||||||
rich.inspect(export.format_optionals(""))
|
|
||||||
assert False
|
assert False
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -141,9 +147,9 @@ def test_get_templates(export_type, export_subtype, line):
|
||||||
"col_span": "1",
|
"col_span": "1",
|
||||||
"row_span": "1",
|
"row_span": "1",
|
||||||
"display_level": "1"
|
"display_level": "1"
|
||||||
|
|
||||||
}))
|
}))
|
||||||
assert isinstance(r, export.ExportResponse)
|
assert isinstance(r, export.ExportResponse)
|
||||||
|
# TODO : Add optional
|
||||||
|
|
||||||
|
|
||||||
def test_context_cov():
|
def test_context_cov():
|
||||||
|
|
|
||||||
|
|
@ -525,7 +525,7 @@ dict_advanced_syntax_input_and_expected_output = {
|
||||||
("|---|---|", (sy.TableSeparatorToken(["---", "---"]),), __GL()),
|
("|---|---|", (sy.TableSeparatorToken(["---", "---"]),), __GL()),
|
||||||
("- Text", (sy.EtUlistToken([sy.TextToken(["Text"])]),), __GL()),
|
("- Text", (sy.EtUlistToken([sy.TextToken(["Text"])]),), __GL()),
|
||||||
("div>>", (sy.StructuralElementEndToken(["div"]),), __GL()),
|
("div>>", (sy.StructuralElementEndToken(["div"]),), __GL()),
|
||||||
("#. Text with *em* and __underline__ and {arguments}{{super-arguments}}[a=1,'ui']", (
|
("#. Text with *em* and __underline__ and {arguments}{{super-arguments}}[a=1, c=2,'ui']", (
|
||||||
sy.EtOlistToken([
|
sy.EtOlistToken([
|
||||||
sy.TextToken(["Text with"]),
|
sy.TextToken(["Text with"]),
|
||||||
sy.EtEmToken(["*"]),
|
sy.EtEmToken(["*"]),
|
||||||
|
|
@ -545,6 +545,7 @@ dict_advanced_syntax_input_and_expected_output = {
|
||||||
]),
|
]),
|
||||||
sy.OptionalVarToken([
|
sy.OptionalVarToken([
|
||||||
sy.BeAssignToken([["a", 1]]),
|
sy.BeAssignToken([["a", 1]]),
|
||||||
|
sy.BeAssignToken([["c", 2]]),
|
||||||
sy.BeValueToken(["ui"]),
|
sy.BeValueToken(["ui"]),
|
||||||
]),
|
]),
|
||||||
]),
|
]),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue