Mercurial > libervia-web
changeset 1258:92ff09cdd6dd
server: gather themes data:
- the new LiberviaRootResource's `site_themes` attribute is a set of available themes for
a site, it is set a template variable for pages.
- if `browser_meta` are available for a theme, the metadata are merged with pages root
`_browser` data
- if python files are found in `browser_path`, they are added to be handled by brython
task.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 03 May 2020 19:28:14 +0200 |
parents | 1ec41ac1e7cf |
children | 0b269d4a46a3 |
files | libervia/server/pages.py libervia/server/server.py |
diffstat | 2 files changed, 28 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/libervia/server/pages.py Sun May 03 18:25:11 2020 +0200 +++ b/libervia/server/pages.py Sun May 03 19:28:14 2020 +0200 @@ -1332,6 +1332,7 @@ return self.host.renderer.render( self.template, + site_themes=self.vhost_root.site_themes, page_url=self.getURL(), media_path=f"/{C.MEDIA_DIR}", cache_path=session_data.cache_dir,
--- a/libervia/server/server.py Sun May 03 18:25:11 2020 +0200 +++ b/libervia/server/server.py Sun May 03 19:28:14 2020 +0200 @@ -50,6 +50,7 @@ from sat.tools.common import regex from sat.tools.common import template from sat.tools.common import uri as common_uri +from sat.tools.common.utils import recursive_update import libervia from libervia.server import websockets from libervia.server.pages import LiberviaPage @@ -184,10 +185,36 @@ self.host_name = host_name self.site_name = site_name self.site_path = Path(site_path) + self.site_themes = set() self.named_pages = {} self.browser_modules = {} # template dynamic data used in all pages self.dyn_data_common = {"scripts": []} + for theme, data in host.renderer.getThemesData(site_name).items(): + # we check themes for browser metadata, and merge them here if found + self.site_themes.add(theme) + browser_meta = data.get('browser_meta') + if browser_meta is not None: + log.debug(f"merging browser metadata from theme {theme}: {browser_meta}") + recursive_update(self.browser_modules, browser_meta) + browser_path = data.get('browser_path') + if browser_path is not None: + self.browser_modules.setdefault('themes_browser_paths', set()).add( + browser_path) + try: + next(browser_path.glob("*.py")) + except StopIteration: + pass + else: + log.debug(f"found brython script(s) for theme {theme}") + self.browser_modules.setdefault('brython', []).append( + { + "path": browser_path, + "url_hash": None, + "url_prefix": f"__t_{theme}" + } + ) + self.uri_callbacks = {} self.pages_redirects = {} self.cached_urls = {}