Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 56 additions & 2 deletions strictdoc/export/html/html_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
from strictdoc.helpers.git_client import GitClient
from strictdoc.helpers.mid import MID
from strictdoc.helpers.parallelizer import Parallelizer
from strictdoc.helpers.paths import SDocRelativePath
from strictdoc.helpers.paths import SDocRelativePath, path_to_posix_path
from strictdoc.helpers.timing import measure_performance, timing_decorator


Expand Down Expand Up @@ -171,6 +171,9 @@ def export_complete_tree(
if self.project_config.is_feature_activated(
ProjectFeature.REQUIREMENT_TO_SOURCE_TRACEABILITY
):
self.export_source_files_screens(
traceability_index=traceability_index,
)
self.export_source_coverage_screen(
traceability_index=traceability_index,
)
Expand Down Expand Up @@ -579,7 +582,8 @@ def export_requirements_coverage_screen(
) as file:
file.write(requirements_coverage_content)

def export_source_coverage_screen(
@timing_decorator("Export source file pages")
def export_source_files_screens(
self,
*,
traceability_index: TraceabilityIndex,
Expand All @@ -601,6 +605,15 @@ def export_source_coverage_screen(
html_templates=self.html_templates,
)

def export_source_coverage_screen(
self,
*,
traceability_index: TraceabilityIndex,
) -> None:
assert isinstance(
traceability_index.document_tree.source_tree, SourceTree
), traceability_index.document_tree.source_tree

source_coverage_content = SourceFileCoverageHTMLGenerator.export(
project_config=self.project_config,
traceability_index=traceability_index,
Expand All @@ -612,6 +625,47 @@ def export_source_coverage_screen(
with open(output_html_source_coverage, "w", encoding="utf8") as file:
file.write(source_coverage_content)

def export_single_source_file_screen(
self,
*,
traceability_index: TraceabilityIndex,
path_to_source_file: str,
) -> None:
assert isinstance(
traceability_index.document_tree.source_tree, SourceTree
), traceability_index.document_tree.source_tree

# FIXME: path_to_source_file must not enter this function with forward slashes.
# Test and fix this on Windows.
# https://github.com/strictdoc-project/strictdoc/issues/2068
relative_path_to_source_file = path_to_posix_path(path_to_source_file)
relative_path_to_source_file = (
relative_path_to_source_file.removeprefix("_source_files/")
)
relative_path_to_source_file = (
relative_path_to_source_file.removesuffix(".html")
)

for (
source_file
) in traceability_index.document_tree.source_tree.source_files:
if not source_file.is_referenced:
continue

if (
relative_path_to_source_file
== source_file.in_doctree_source_file_rel_path_posix
):
SourceFileViewHTMLGenerator.export_to_file(
project_config=self.project_config,
source_file=source_file,
traceability_index=traceability_index,
html_templates=self.html_templates,
)
return

raise FileNotFoundError

def export_project_statistics(
self,
traceability_index: TraceabilityIndex,
Expand Down
22 changes: 17 additions & 5 deletions strictdoc/server/routers/main_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -2518,11 +2518,23 @@ def get_document(request: Request, url_to_document: str) -> Response:
return Response(status_code=304)
else:
if document_relative_path.relative_path.startswith("_source_files"):
# FIXME: We could be more specific here and only generate the
# requested file.
html_generator.export_source_coverage_screen(
traceability_index=export_action.traceability_index,
)
if document_relative_path.relative_path.endswith(
"source_coverage.html"
):
html_generator.export_source_coverage_screen(
traceability_index=export_action.traceability_index,
)
else:
try:
html_generator.export_single_source_file_screen(
traceability_index=export_action.traceability_index,
path_to_source_file=document_relative_path.relative_path,
)
except FileNotFoundError:
return HTMLResponse(
content=f"Not Found: {url_to_document}",
status_code=404,
)
elif document_relative_path.relative_path == "index.html":
html_generator.export_project_tree_screen(
traceability_index=export_action.traceability_index,
Expand Down
Loading