# HG changeset patch # User Goffi # Date 1514935416 -3600 # Node ID bb0bbcc80fc8a0c7e1551c40d56f1f010e8391e8 # Parent 8788c217a49e54f6d1f6d4fd4d06b1f09d6b5906 template: boolean attribute can now be specified when importing a script, and default to "defer" diff -r 8788c217a49e -r bb0bbcc80fc8 src/tools/common/template.py --- a/src/tools/common/template.py Wed Jan 03 00:21:21 2018 +0100 +++ b/src/tools/common/template.py Wed Jan 03 00:23:36 2018 +0100 @@ -155,17 +155,20 @@ self.scripts = [] # we don't use a set because order may be important dummy, self.theme, self.is_default_theme = renderer.getThemeData(template_path) - def include(self, library_name): + def include(self, library_name, attribute='defer'): """Mark that a script need to be imported. Must be used before base.html is extended, as ' - for library in self.scripts: + tpl = u'' + for library, attribute in self.scripts: path = self.renderer.getStaticPath(library, self.template_root_dir, self.theme, self.is_default_theme, '.js') if path is None: log.warning(_(u"Can't find {}.js javascript library").format(library)) continue path = os.path.join(self.root_path, path) - scripts.append(tpl.format(src=quoteattr(path))) + scripts.append(tpl.format( + src = quoteattr(path), + attribute = attribute, + )) return safe(u'\n'.join(scripts))