Fix template search path
the source file path is now forwarded to the Harness object and on to the HTML generator code. Its the last argument to keep API compatibility. Ive also kept the output-relative search location to avoid anyone relying on that behavior
This commit is contained in:
parent
e4fe099f8c
commit
37d2394466
@ -70,6 +70,7 @@ class Harness:
|
|||||||
metadata: Metadata
|
metadata: Metadata
|
||||||
options: Options
|
options: Options
|
||||||
tweak: Tweak
|
tweak: Tweak
|
||||||
|
source_path: Path
|
||||||
|
|
||||||
def __post_init__(self):
|
def __post_init__(self):
|
||||||
self.connectors = {}
|
self.connectors = {}
|
||||||
@ -697,7 +698,7 @@ class Harness:
|
|||||||
print("CSV output is not yet supported")
|
print("CSV output is not yet supported")
|
||||||
# HTML output
|
# HTML output
|
||||||
if "html" in fmt:
|
if "html" in fmt:
|
||||||
generate_html_output(filename, bomlist, self.metadata, self.options)
|
generate_html_output(filename, bomlist, self.metadata, self.options, self.source_path)
|
||||||
# PDF output
|
# PDF output
|
||||||
if "pdf" in fmt:
|
if "pdf" in fmt:
|
||||||
# TODO: implement PDF output
|
# TODO: implement PDF output
|
||||||
|
|||||||
@ -31,6 +31,7 @@ def parse(
|
|||||||
output_dir: Union[str, Path] = None,
|
output_dir: Union[str, Path] = None,
|
||||||
output_name: Union[None, str] = None,
|
output_name: Union[None, str] = None,
|
||||||
image_paths: Union[Path, str, List] = [],
|
image_paths: Union[Path, str, List] = [],
|
||||||
|
source_path = None,
|
||||||
) -> Any:
|
) -> Any:
|
||||||
"""
|
"""
|
||||||
This function takes an input, parses it as a WireViz Harness file,
|
This function takes an input, parses it as a WireViz Harness file,
|
||||||
@ -115,6 +116,7 @@ def parse(
|
|||||||
metadata=Metadata(**yaml_data.get("metadata", {})),
|
metadata=Metadata(**yaml_data.get("metadata", {})),
|
||||||
options=Options(**yaml_data.get("options", {})),
|
options=Options(**yaml_data.get("options", {})),
|
||||||
tweak=Tweak(**yaml_data.get("tweak", {})),
|
tweak=Tweak(**yaml_data.get("tweak", {})),
|
||||||
|
source_path=source_path
|
||||||
)
|
)
|
||||||
# others
|
# others
|
||||||
# store mapping of components to their respective template
|
# store mapping of components to their respective template
|
||||||
|
|||||||
@ -144,6 +144,7 @@ def wireviz(file, format, prepend, output_dir, output_name, version):
|
|||||||
output_dir=_output_dir,
|
output_dir=_output_dir,
|
||||||
output_name=_output_name,
|
output_name=_output_name,
|
||||||
image_paths=list(image_paths),
|
image_paths=list(image_paths),
|
||||||
|
source_path=file
|
||||||
)
|
)
|
||||||
|
|
||||||
print()
|
print()
|
||||||
|
|||||||
@ -21,14 +21,19 @@ def generate_html_output(
|
|||||||
bom_list: List[List[str]],
|
bom_list: List[List[str]],
|
||||||
metadata: Metadata,
|
metadata: Metadata,
|
||||||
options: Options,
|
options: Options,
|
||||||
|
source: Union[str, Path] = None,
|
||||||
):
|
):
|
||||||
# load HTML template
|
# load HTML template
|
||||||
templatename = metadata.get("template", {}).get("name")
|
templatename = metadata.get("template", {}).get("name")
|
||||||
|
template_search_paths = [ Path(filename).parent, Path(__file__).parent / "templates"]
|
||||||
|
|
||||||
|
if source is not None:
|
||||||
|
template_search_paths.insert(0, Path(source).parent)
|
||||||
|
|
||||||
if templatename:
|
if templatename:
|
||||||
# if relative path to template was provided, check directory of YAML file first, fall back to built-in template directory
|
# if relative path to template was provided, check directory of YAML file first, fall back to built-in template directory
|
||||||
templatefile = smart_file_resolve(
|
templatefile = smart_file_resolve(
|
||||||
f"{templatename}.html",
|
f"{templatename}.html", template_search_paths
|
||||||
[Path(filename).parent, Path(__file__).parent / "templates"],
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# fall back to built-in simple template if no template was provided
|
# fall back to built-in simple template if no template was provided
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user