Mercurial > genshi > mirror
changeset 651:badb73198fb1 trunk
The template engine plugin no longer adds the `default_doctype` when the `fragment` parameter is `True`. Thanks to dbrattli for the patch!
author | cmlenz |
---|---|
date | Thu, 08 Nov 2007 18:27:47 +0000 |
parents | 9ff8eccc6f1f |
children | 670a00fab913 |
files | ChangeLog genshi/template/plugin.py genshi/template/tests/plugin.py genshi/template/tests/templates/test_no_doctype.html |
diffstat | 4 files changed, 37 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -34,6 +34,8 @@ to "text", the included template is parsed as a text template using the new syntax (ticket #101). * Python code blocks inside match templates are now executed (ticket #155). + * The template engine plugin no longer adds the `default_doctype` when the + `fragment` parameter is `True`. Version 0.4.4
--- a/genshi/template/plugin.py +++ b/genshi/template/plugin.py @@ -97,7 +97,7 @@ return self.loader.load(templatename) - def _get_render_options(self, format=None): + def _get_render_options(self, format=None, fragment=False): if format is None: format = self.default_format kwargs = {'method': format} @@ -107,7 +107,7 @@ def render(self, info, format=None, fragment=False, template=None): """Render the template to a string using the provided info.""" - kwargs = self._get_render_options(format=format) + kwargs = self._get_render_options(format=format, fragment=fragment) return self.transform(info, template).render(**kwargs) def transform(self, info, template): @@ -140,10 +140,10 @@ raise ConfigurationError('Unknown output format %r' % format) self.default_format = format - def _get_render_options(self, format=None): + def _get_render_options(self, format=None, fragment=False): kwargs = super(MarkupTemplateEnginePlugin, - self)._get_render_options(format) - if self.default_doctype: + self)._get_render_options(format, fragment) + if self.default_doctype and not fragment: kwargs['doctype'] = self.default_doctype return kwargs
--- a/genshi/template/tests/plugin.py +++ b/genshi/template/tests/plugin.py @@ -145,6 +145,23 @@ </body> </html>""", output) + def test_render_fragment_with_doctype(self): + plugin = MarkupTemplateEnginePlugin(options={ + 'genshi.default_doctype': 'html-strict', + }) + tmpl = plugin.load_template(PACKAGE + '.templates.test_no_doctype') + output = plugin.render({'message': 'Hello'}, template=tmpl, + fragment=True) + self.assertEqual("""<html lang="en"> + <head> + <title>Test</title> + </head> + <body> + <h1>Test</h1> + <p>Hello</p> + </body> +</html>""", output) + def test_helper_functions(self): plugin = MarkupTemplateEnginePlugin() tmpl = plugin.load_template(PACKAGE + '.templates.functions')