comparison frontends/src/jp/output_template.py @ 2169:f472179305a1

tools(templates): workflow improvments: - template theme can be specified in parenthesis: (some_theme)path/to/template.html. Withtout parenthesis, "default" is used - static content are supposed to be in [theme]/static, error pages in [theme]/error/[err_code].html - default page are used in some case (2 for now): if error page with specified code doesn't exists, a base page is used, and if a page doesn't exist for a theme, the same one for default theme is looked for - CSS files are automatically found for HTML pages - CSS files can be split, the'll be added in the template according to the page requested. - theme CSS file is looked for, and if not found the default theme equivalent is looked for. - each element of a path can be associated to a CSS file, and styles.css is always there. For instance if blog/articles.html is requested, the following CSS can be included: "styles.css", "blog.css", "blog_article.css". They all must be in /static - if the automatic finding of CSS files is not wanted, css_files arguments can be used instead, with full relative path (i.e. including theme) - CSS files can be merged and included inline with css_inline argument - root_path can be specified, it will be used as a prefix for static files - requested theme (which may differ from actual theme, e.g. if the template is not found and default one is used instead) is available in template with "theme" variable - added getThemeAndRoot method to retrieve theme and theme root path from template
author Goffi <goffi@goffi.org>
date Sun, 05 Mar 2017 23:41:10 +0100
parents 75667727c500
children 4ec72927a222
comparison
equal deleted inserted replaced
2168:255830fdb80b 2169:f472179305a1
100 self.host.disp(_(u"Browser opening requested.\nTemporary files are put in the following directory, " 100 self.host.disp(_(u"Browser opening requested.\nTemporary files are put in the following directory, "
101 u"you'll have to delete it yourself once finished viewing: {}").format(tmp_dir)) 101 u"you'll have to delete it yourself once finished viewing: {}").format(tmp_dir))
102 tmp_file = os.path.join(tmp_dir, template_name) 102 tmp_file = os.path.join(tmp_dir, template_name)
103 with open(tmp_file, 'w') as f: 103 with open(tmp_file, 'w') as f:
104 f.write(rendered.encode('utf-8')) 104 f.write(rendered.encode('utf-8'))
105 static_dir = self.renderer.getStaticDir(template_path) 105 theme, theme_root_path = self.renderer.getThemeAndRoot(template_path)
106 static_dir = os.path.join(theme_root_path, C.TEMPLATE_STATIC_DIR)
106 if os.path.exists(static_dir): 107 if os.path.exists(static_dir):
107 import shutil 108 import shutil
108 shutil.copytree(static_dir, os.path.join(tmp_dir, u'static')) 109 shutil.copytree(static_dir, os.path.join(tmp_dir, theme, C.TEMPLATE_STATIC_DIR))
109 webbrowser.open(tmp_file) 110 webbrowser.open(tmp_file)
110 else: 111 else:
111 self.host.disp(rendered) 112 self.host.disp(rendered)