From 3bf13170f833d9ae5550d07a7b593b3abe273920 Mon Sep 17 00:00:00 2001 From: kedarnn Date: Thu, 12 Dec 2024 18:57:46 +0530 Subject: [PATCH] Adding css files code to the LOBSTER HTML report (#156) Added code to read css files for html report and add it to the html report, modified reading of js code from specific file to all the js files that are in the assets folder --- lobster/html/htmldoc.py | 8 ++++---- lobster/tools/core/html_report/html_report.py | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lobster/html/htmldoc.py b/lobster/html/htmldoc.py index fbdea7d..4972582 100644 --- a/lobster/html/htmldoc.py +++ b/lobster/html/htmldoc.py @@ -247,7 +247,7 @@ def __init__(self, title, subtitle): } self.scripts = [] self.body = [] - self.css_files = [] + self.css = [] def add_line(self, line): assert isinstance(line, str) @@ -293,11 +293,11 @@ def render(self): for attr, value in style.items(): rv.append(" %s: %s;" % (attr, value)) rv.append("}") - rv.append("") # add css files that are appended to self.files - for css_file in self.css_files: - rv.append(f"") + for css_file in self.css: + rv.append(css_file) + rv.append("") rv.append("") rv.append("") diff --git a/lobster/tools/core/html_report/html_report.py b/lobster/tools/core/html_report/html_report.py index c40a950..4e0920b 100755 --- a/lobster/tools/core/html_report/html_report.py +++ b/lobster/tools/core/html_report/html_report.py @@ -488,14 +488,21 @@ def write_html(fd, report, dot, high_contrast): # Add the css from assets dir_path = os.path.dirname(os.path.abspath(__file__)) - file_path = dir_path + "/assets/html_report.css" - doc.css_files.append(file_path) + file_path = dir_path + "/assets" + for filename in os.listdir(file_path): + if filename.endswith(".css"): + filename = os.path.join(file_path, filename) + with open(filename, "r", encoding="UTF-8") as styles: + doc.css.append("".join(styles.readlines())) # Add javascript from assets/html_report.js file dir_path = os.path.dirname(os.path.abspath(__file__)) - file_path = dir_path + "/assets/html_report.js" - with open(file_path, "r", encoding="UTF-8") as scripts: - doc.scripts.append("".join(scripts.readlines())) + file_path = dir_path + "/assets" + for filename in os.listdir(file_path): + if filename.endswith(".js"): + filename = os.path.join(file_path, filename) + with open(filename, "r", encoding="UTF-8") as scripts: + doc.scripts.append("".join(scripts.readlines())) ### STM # doc.add_heading(2, "Software traceability matrix", "matrix")