+ return h.root.hubapps[hubapp]
+ elif isinstance(hubapp, TreeFileApp):
+ return hubapp
+ return static_file.hubapp
+
+ def render(
+ self, filename: str = "", hubapp: str | TreeFileApp | None = None
+ ) -> str:
+ """
+ If filename starts with '/', interpret the path as relative to hubapp.base_dir,
+ otherwise assume the path is relative to the current file.
+ """
+ static_file = self.context["static_file"]
+ hubapp = self.get_hubapp(static_file, hubapp)
+ if filename.startswith("/") or hubapp != static_file.hubapp:
+ path = hubapp.base_dir / filename.lstrip("/")
+ else:
+ path = static_file.path.parent / filename
+ return hubapp.uri(path)