diff --git a/htmltools/_core.py b/htmltools/_core.py index 78ca86d..0139f8d 100644 --- a/htmltools/_core.py +++ b/htmltools/_core.py @@ -46,6 +46,8 @@ _html_escape, # type: ignore _flatten, # type: ignore hash_deterministic, + MISSING, + MISSING_TYPE, ) __all__ = ( @@ -194,7 +196,11 @@ def tagify(self) -> "TagList": return cp def save_html( - self, file: str, *, libdir: Optional[str] = "lib", include_version: bool = True + self, + file: str, + *, + libdir: Union[str, MISSING_TYPE] = MISSING, + include_version: bool = True, ) -> str: """ Save to a HTML file. @@ -583,7 +589,11 @@ def render(self) -> RenderedHTML: return {"dependencies": deps, "html": cp.get_html_string()} def save_html( - self, file: str, *, libdir: Optional[str] = "lib", include_version: bool = True + self, + file: str, + *, + libdir: Union[str, MISSING_TYPE] = MISSING, + include_version: bool = True, ) -> str: """ Save to a HTML file. @@ -707,7 +717,10 @@ def append(self, *args: TagChildArg) -> None: self._content.append(*args) def render( - self, *, lib_prefix: Optional[str] = "lib", include_version: bool = True + self, + *, + lib_prefix: Union[str, MISSING_TYPE] = MISSING, + include_version: bool = True, ) -> RenderedHTML: """ Render the document. @@ -726,7 +739,10 @@ def render( return rendered def save_html( - self, file: str, libdir: Optional[str] = "lib", include_version: bool = True + self, + file: str, + libdir: Union[str, MISSING_TYPE] = MISSING, + include_version: bool = True, ) -> str: """ Save the document to a HTML file. @@ -743,9 +759,10 @@ def save_html( # Directory where dependencies are copied to. destdir = str(Path(file).resolve().parent) - if libdir: - destdir = os.path.join(destdir, libdir) + libdir = resolve_missing_lib_path(libdir) + destdir = os.path.join(destdir, libdir) + # TODO: fix all libdir occurrences rendered = self.render(lib_prefix=libdir, include_version=include_version) for dep in rendered["dependencies"]: dep.copy_to(destdir, include_version=include_version) @@ -760,12 +777,14 @@ def save_html( # - lib_prefix: A directoy prefix to add to