Skip to content

Commit

Permalink
Adding css files code to the LOBSTER HTML report (#156)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kedarnn authored Dec 12, 2024
1 parent 627eef6 commit 3bf1317
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
8 changes: 4 additions & 4 deletions lobster/html/htmldoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -293,11 +293,11 @@ def render(self):
for attr, value in style.items():
rv.append(" %s: %s;" % (attr, value))
rv.append("}")
rv.append("</style>")

# add css files that are appended to self.files
for css_file in self.css_files:
rv.append(f"<link rel='stylesheet' href={css_file}>")
for css_file in self.css:
rv.append(css_file)
rv.append("</style>")
rv.append("</head>")
rv.append("<body>")

Expand Down
17 changes: 12 additions & 5 deletions lobster/tools/core/html_report/html_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 3bf1317

Please sign in to comment.