mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-10-29 17:42:12 +08:00
Move default templates to lib/galaxy/config
This commit is contained in:
@@ -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,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)
|
||||
|
||||
Reference in New Issue
Block a user