From b33af4042e75928fe200e49a80ab1a8c71304652 Mon Sep 17 00:00:00 2001 From: Brian Read Date: Sun, 17 Nov 2024 14:28:59 +0000 Subject: [PATCH] Skip template expansion when html control does not have any chameleon tokens --- Templates/controller.pm.tem | 10 +++--- Templates/html_controls.html.ep.xml | 14 ++++++--- Templates/layout.html.ep.tem | 5 +-- json5/Letsencrypt.json5 | 4 +-- sm2gen.py | 48 +++++++++++++++++++---------- 5 files changed, 50 insertions(+), 31 deletions(-) diff --git a/Templates/controller.pm.tem b/Templates/controller.pm.tem index 6e36877..5739ca7 100644 --- a/Templates/controller.pm.tem +++ b/Templates/controller.pm.tem @@ -90,9 +90,8 @@ sub main { } # and table control fields - - $c->stash(${tablecontrol}=>$c->get_${tablecontrol}()); - + $c->stash(${tablecontrol[0]}=>$c->get_${tablecontrol[0]}()); + $c->stash( title => $title, @@ -262,9 +261,8 @@ sub do_display { # and table control fields - - $c->stash(${tablecontrol}=>$c->get_${tablecontrol}()); - + $c->stash(${tablecontrol[0]}=>$c->get_${tablecontrol[0]}()); + # Data for panel $c->stash( diff --git a/Templates/html_controls.html.ep.xml b/Templates/html_controls.html.ep.xml index ed1d388..c39ddce 100644 --- a/Templates/html_controls.html.ep.xml +++ b/Templates/html_controls.html.ep.xml @@ -224,7 +224,7 @@ - % my $control_data = $self->stash('${TableControl}'); + % my $control_data = $c->stash('${TableControl}'); % foreach my $row (@$control_data) { <%=$c->render_to_string(inline=>$row->{'${ColContent}'})%> @@ -243,12 +243,18 @@ 'link link${type_serial}' + + %= l('${title}') + + %#= link_to l('${title}'), '${structure:href}' , class=>'link link${type_serial}' ]]> 'buttonlink buttonlink${type_serial}' + + %#= button_to l('${title}'), '${structure:href}' , class=>'buttonlink buttonlink${type_serial}' ]]> @@ -265,7 +271,7 @@ + ]]> diff --git a/Templates/layout.html.ep.tem b/Templates/layout.html.ep.tem index f2b45b4..ccb4300 100644 --- a/Templates/layout.html.ep.tem +++ b/Templates/layout.html.ep.tem @@ -8,9 +8,10 @@
% if ($config->{debug} == 1) { -

+

 		%= dumper $c->current_route
-	

+ %= dumper $$${prefix}_data->{trt} +
% }

<%=$title%>

diff --git a/json5/Letsencrypt.json5 b/json5/Letsencrypt.json5 index 0b28277..7cf6bf9 100644 --- a/json5/Letsencrypt.json5 +++ b/json5/Letsencrypt.json5 @@ -26,8 +26,8 @@ }, 'Link4': { 'Type': 'Link', - 'href': 'letsencryptd?trt=CHECKENABLEDDOMAINS', - 'title': 'CHECK_ENABLED_DOMAINS' + 'href': 'letsencryptd?trt=CHECKALLENABLEDDOMAINS', + 'title': 'CHECK_ALL_ENABLED_DOMAINS' }, 'Endgroup': '', SubHeader2: 'For this Server', diff --git a/sm2gen.py b/sm2gen.py index 3a9751a..f5f6ed2 100644 --- a/sm2gen.py +++ b/sm2gen.py @@ -482,6 +482,10 @@ def extract_input_fields(json_data, value_type): result[panel_name].append(input_name) # Note: Empty lists are not removed, so all panels will be present in the result return result + +def contains_chameleon_code(template: str) -> bool: + # Check for common Chameleon code indicators + return "${" in template or "tal:" in template or "metal:" in template if __name__ == "__main__": @@ -738,29 +742,39 @@ if __name__ == "__main__": ) else: # just a simple entry - name less numerics is type + # If the html does not include any Chameleon / TAL symbols, then do not run the Template extraction, just + # insert the result of the html directly. This avoids Chameleon aborting things when a closing tag is on its own + # such as the "Endgroup" token. html_Type = "".join(char for char in html_control if not char.isdigit()) type_serial = "".join(char for char in html_control if char.isdigit()) class_name = html_Type.lower()[:4]+type_serial acc_css_entries += f".{class_name} {{}}\n" + simple_control_html = "" + logger.debug(f"Partial ep generation html type:{html_Type}") if not type_serial == "": logger.debug(f"{html_control},{html_Type},{type_serial}") - try: - simple_control_template = PageTemplate(html_controls[html_Type]) - try: - simple_control_html = simple_control_template.render( - version=strVersion, Value=inner_html, prefix=prefix_is, - type_serial=type_serial - ) - all_controls_html = all_controls_html + simple_control_html - except Exception as e: - logger.warning( - f"A Chameleon render on partial file control {html_control} error occurred: {e}" - ) - except Exception as e: - logger.warning( - f"A Chameleon template partial file control {html_control} error occurred: {e}" - ) - + if html_Type in html_controls: + if contains_chameleon_code(html_controls[html_Type]): + try: + simple_control_template = PageTemplate(html_controls[html_Type]) + try: + simple_control_html = simple_control_template.render( + version=strVersion, Value=inner_html, prefix=prefix_is, + type_serial=type_serial + ) + except Exception as e: + logger.warning( + f"A Chameleon render on partial file control {html_control} error occurred: {e}" + ) + except Exception as e: + logger.warning( + f"A Chameleon template partial file control {html_control} error occurred: {e}" + ) + else: + logger.debug(f"Skipping Chameleon expansion for {html_control}") + simple_control_html = html_controls[html_Type] + all_controls_html = all_controls_html + simple_control_html + # Now insert it into the partial file in the correct place. # Read in the text file and split at "%# Inputs etc in here." with open(partial_files[i], "r") as file: