Skip to content

Commit

Permalink
refactor: change render transformation order
Browse files Browse the repository at this point in the history
  • Loading branch information
janbritz committed Jan 14, 2025
1 parent 2c82630 commit 97528b8
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions questionpy_sdk/webserver/question_ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,17 +246,27 @@ def render(self) -> tuple[str, RenderErrorCollection]:
tuple: The rendered html and a render errors collection.
"""
if self._html is None:
self._resolve_placeholders()
# Handle our custom elements and attributes.
self._hide_unwanted_feedback()
self._hide_if_role()
self._shuffle_contents()
self._format_floats()

# Remove all unhandled custom elements, attributes, and non-default xmlns declarations.
self._clean_up()

# Modify standard HTML.
self._set_input_values_and_readonly()
self._soften_validation()
self._defuse_buttons()
self._shuffle_contents()

self._add_styles()
self._format_floats()

# We don't want to support QPy elements (and attributes, etc.) in placeholder expansions, so we resolve
# them after replacing QPy elements.
self._resolve_placeholders()

# TODO: mangle_ids_and_names
self._clean_up()

self._html = etree.tostring(self._xml, pretty_print=True, method="html").decode()
self._error_collector.collect()
Expand All @@ -270,10 +280,8 @@ def _replace_qpy_urls(self, xml: str) -> str:
def _resolve_placeholders(self) -> None:
"""Replace placeholder PIs such as `<?p my_key plain?>` with the appropriate value from `self.placeholders`.
TODD: remove comment or change call-order
Since QPy transformations should not be applied to the content of the placeholders, this method should be called
last.
near the end (see `_clean_up` method).
"""
for p_instruction in _assert_element_list(self._xpath("//processing-instruction('p')")):
if not p_instruction.text:
Expand Down

0 comments on commit 97528b8

Please sign in to comment.