diff --git a/.gitignore b/.gitignore index 29e1845..b43a140 100644 --- a/.gitignore +++ b/.gitignore @@ -1,27 +1,3 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* -replay_pid* .idea/* # code style config @@ -29,12 +5,3 @@ replay_pid* .idea/codeStyles/* !.idea/codeStyles/Project.xml !.idea/codeStyles/codeStyleConfig.xml - -.vscode/* - -target/ -*.iml -dependency-reduced-pom.xml - -src/main/resources/webapp/*-admin/html/about.html -README.html diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fbeaf36..5c2e781 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -26,15 +26,6 @@ All contributors must have an active Polarion license. An active Polarion licens ## Asking questions Do not know how something in this project works? Curious if this project can achieve your desired functionality? Please ask questions in this project discussions [here](../../discussions) -## What should I know before I get started? - -### Tools and Packages -All extensions provided by SBB Polarion Team can be built, tested and packaged using Maven. -It is only possible when the dependencies are extract from Polarion installer. The process must be performed by each contributor. Please consider to use https://github.com/SchweizerischeBundesbahnen/polarion-artifacts-deployer to extract the dependencies for your own Polarion installer version. - -### Design Decisions -The generic implementation for extensions provided by SBB Polarion Team is located in [ch.sbb.polarion.extension.generic](https://github.com/SchweizerischeBundesbahnen/ch.sbb.polarion.extension.generic) - ## How Can I Contribute? ### Reporting Bugs diff --git a/README.md b/README.md index 756123a..7cc6495 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,20 @@ -# PDF-exporter webhook samples +# PDF-Exporter Webhook Samples -This project includes samples of webhooks that can incorporate additional logic for processing HTML prior to PDF generation. -Webhook can be implemented as a REST endpoint by any programming language (Java, JS, Python etc.) and be hosted anywhere (within Polarion as an extension, or absolutely external). +This project contains examples of webhooks that can include additional logic to process HTML prior to PDF generation. +Webhooks can be implemented as a REST endpoint by any programming language (Java, JS, Python, etc.) and hosted anywhere (inside Polarion as an extension or completely external). ## TableCellAutoHeightSetter -The TableCellAutHeightSetter webhook processes HTML content by replacing table cell height values specified in pixels (e.g., height: 100px) with height: auto. The processed HTML is then returned as a response to the client. +The TableCellAutHeightSetter webhook processes HTML content by replacing table cell height values specified in pixels (e.g. height: 100px) with height: auto. The processed HTML is then returned as a response to the client. ## Usage -This webhook endpoint can be started using the following command: +This webhook endpoint can be launched with the following command: + ```bash -python app/TableCellAutoHeightSetter.py --port=9333 +python table-cell-auto-height-setter/table_cell_auto_height_setter.py --port=9333 ``` -## Configuration Webhook URL in PDF-exporter: - -1. Navigate to: Administration ➙ PDF Export ➙ Webhooks - -2. Add the webhook URL, such as http://host.docker.internal:9333/process. - - - - +## Configuration of the webhook URL in the PDF Exporter: +1. Navigate to: `Administration` ➙ `PDF Export` ➙ `Webhooks` +2. Add the webhook URL, for example http://localhost:9333/td-height/auto. diff --git a/app/TableCellAutoHeightSetter.py b/app/TableCellAutoHeightSetter.py deleted file mode 100644 index 77a8ca7..0000000 --- a/app/TableCellAutoHeightSetter.py +++ /dev/null @@ -1,35 +0,0 @@ -import argparse -import logging -import re - -from flask import Flask, Response, request -from gevent.pywsgi import WSGIServer - -app = Flask(__name__) - - -@app.route("/process", methods=["POST"]) -def process_html(): - html_content = request.form.get('html') - if html_content: - pattern = r'(", methods=["POST"]) +def process_html(height): + export_params, html = validate_request() + + logging.info(f"Changing HTML table cell height to '{height}'") + + if export_params.get('fitToPage'): + html = change_height(html, height) + logging.info("Changing HTML table cell height finished.") + else: + logging.info("'fitToPage' is not set. Changing HTML table cell height skipped.") + + return Response(html, mimetype="text/html", status=200) + + +def change_height(html, height): + pattern = r'(