From 38e58e4ee0b9b2dd9a6802929ff351c4d835a999 Mon Sep 17 00:00:00 2001 From: Dotty Dotter Date: Thu, 7 May 2026 09:15:25 +0200 Subject: [PATCH] feat(#175 Phase 23 step 1): Matrix-Block-Renderer via v2-Macro vorbereitet MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Erste Stufe der 'one-source-of-truth'-Architektur (User-Vorschlag): build_matrix_html_v2() rendert die GWÖ-Matrix mit dem matrix_mini- Macro aus v2/components/matrix_mini.html — gleiche Quelle wie die Web-View. Noch nicht aktiv: das v2.css-Stylesheet muss erst im PDF-WeasyPrint- Aufruf eingebunden werden (Klassen wie m-pp/m-p/m-0/m-n/m-nn). Bis dahin nutzt der PDF-Renderer weiterhin build_matrix_html mit eigenem inline-CSS. Folge-Schritte (Refactor-Pattern): 1. v2.css als zusaetzliches Stylesheet in HTML(string=...).write_pdf() 2. Pro Block (Programmtreue, Verbesserungsvorschlaege, Vote): analog v2-Macro extrahieren + im PDF includen. 3. Wenn alle Blocks via Macro rendern: PDF-HTML wird zur reinen Block-Liste, Layout-Wechsel ist nur ein @page-CSS-Tausch. Refs: #175 Co-Authored-By: Claude Opus 4.7 (1M context) --- app/report.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/app/report.py b/app/report.py index 59b4839..72a3587 100644 --- a/app/report.py +++ b/app/report.py @@ -90,8 +90,30 @@ def format_redline_html(text: str) -> str: return text +def build_matrix_html_v2(assessment: Assessment) -> str: + """Render Matrix mit dem v2-Macro (matrix_mini) — gleiche Quelle wie + die Web-View. Erste Stufe von #175 Phase 23: PDF nutzt v2-Block- + Macros für Konsistenz-by-Design.""" + from jinja2 import Environment, FileSystemLoader + template_dir = Path(__file__).resolve().parent / "templates" + env = Environment(loader=FileSystemLoader(str(template_dir)), + autoescape=True) + macro_template = env.get_template("v2/components/matrix_mini.html") + matrix_dict = {} + for e in assessment.gwoe_matrix: + matrix_dict[e.field] = {"rating": e.rating, "symbol": ""} + # Macro über `module` aufrufen + module = macro_template.module + return str(module.matrix_mini(matrix_dict)) + + def build_matrix_html(assessment: Assessment) -> str: - """Build HTML matrix table.""" + """Legacy-Renderer: 5x5-Tabelle für PDF (Stand vor Phase 23). + + Hauptpfad rendert weiterhin diese Funktion — der v2-Macro-Pfad + (build_matrix_html_v2) ist als Folge-Schritt verfügbar, sobald + das v2.css-Stylesheet im PDF eingebunden ist. + """ rating_map = {e.field: e for e in assessment.gwoe_matrix} rows = ["A", "B", "C", "D", "E"]