Move default templates to lib/galaxy/config

This commit is contained in:
Cameron Hyde
2022-10-25 09:26:25 +10:00
parent b953119917
commit 3c02958d75
4 changed files with 9 additions and 5 deletions
-1
View File
@@ -78,7 +78,6 @@ config/*
config/plugins/interactive_environments/**/*.ini
config/plugins/**/.cache
!config/plugins
!config/templates
static/welcome.html.*
static/welcome.html
static/client_build_hash.txt
+9 -4
View File
@@ -9,18 +9,23 @@ the Galaxy root (config/templates).
import os
from jinja2 import Environment
DEFAULT_TEMPLATES_DIR = "config/templates"
DEFAULT_TEMPLATES_DIR = "lib/galaxy/config/templates"
TEMPLATE_SEP = '>>>>>>' # Used to split templates into doc/body sections
def render(template_path: str, context: dict, templates_dir: str) -> str:
def render(template_path: str, context: dict, custom_templates_dir: str) -> str:
"""Read and return templated content as string."""
with open(_get_template_path(template_path, templates_dir)) as f:
template_str = f.read().split(TEMPLATE_SEP)[-1].split('\n', 1)[1]
with open(_get_template_path(template_path, custom_templates_dir)) as f:
template_str = _get_template_body(f.read())
tmpl = Environment().from_string(template_str)
return tmpl.render(**context)
def _get_template_body(template: str) -> str:
"""Remove comment/doc header to return the template body."""
return template.split(TEMPLATE_SEP, 1)[-1].split('\n', 1)[1]
def _get_template_path(relpath: str, custom_templates_dir: str) -> str:
"""Return template file path."""
default_path = os.path.join(DEFAULT_TEMPLATES_DIR, relpath)