dynamically fetch the path to the templates
This commit is contained in:
parent
5632cd69c8
commit
11afd70979
2 changed files with 11 additions and 4 deletions
|
|
@ -1 +1,7 @@
|
|||
from pathlib import Path
|
||||
|
||||
__version__ = "0.1.0"
|
||||
|
||||
|
||||
def get_project_root() -> Path:
|
||||
return Path(__file__).parent
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ from jinja2 import BaseLoader
|
|||
from jinja2 import Environment as JinjaEnvironment
|
||||
from jinja2 import Template, TemplateNotFound
|
||||
|
||||
from ops_bot import get_project_root
|
||||
from ops_bot.util import markdown
|
||||
|
||||
|
||||
|
|
@ -111,13 +112,14 @@ class PluginTemplateLoader(BaseLoader):
|
|||
macros: str
|
||||
|
||||
def __init__(self, base: str, directory: str) -> None:
|
||||
self.directory = os.path.join("templates", base, directory)
|
||||
self.macros = sync_read_file(os.path.join("templates", base, "macros.html"))
|
||||
base_path = get_project_root() / ".." / "templates" / base
|
||||
self.directory = base_path / directory
|
||||
self.macros = sync_read_file(base_path / "macros.html")
|
||||
|
||||
def get_source(
|
||||
self, environment: Any, name: str
|
||||
) -> Tuple[str, str, Callable[[], bool]]:
|
||||
path = f"{os.path.join(self.directory, name)}.html"
|
||||
path = self.directory / f"{name}.html"
|
||||
try:
|
||||
tpl = sync_read_file(path)
|
||||
except KeyError:
|
||||
|
|
@ -137,7 +139,6 @@ class TemplateManager:
|
|||
_loader: PluginTemplateLoader
|
||||
|
||||
def __init__(self, base: str, directory: str) -> None:
|
||||
# self._loader = FileSystemLoader(os.path.join("templates/", base))
|
||||
self._loader = PluginTemplateLoader(base, directory)
|
||||
self._env = JinjaEnvironment( # nosec B701
|
||||
loader=self._loader,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue