Hi,
Currently the Genshi plugin ignores the fragment parameter
to
render(). This is usually not a problem, but if one set the
default_doctype config option, then the doc_type is
prepended to the
output even if the template does not contain any doctype.
I'm using Genshi with TurboGears and ToscaWidgets. For my TG
project I
want to write templates as XHTML and render them as HTML.
Thus I set
the default doctype to 'html-transitional'. But for my
widgets I need
to return html fragments for ajax calls, and for them I
don't want to
have the doctype present in the HTML, since injecting HTML
into a DOM
tree with a doctype present gives me errors.
This patch makes the Genshi plugin ignore the default
doctype when
fragment is set to True. With this patch Genshi will still
render the
doctype if it's present in the template, but I don't think
that should
be a big problem since one should not have a doctype in the
template
when wanting to render html fragments. A better solution
could also
made sure that the doctype is removed from the output if
present in
the template when fragment is set to True (this is what Kid
does), but
I couldn't find out how to do this. But I still think this
patch makes
the plugin behave much better than before.
Index: plugin.py
============================================================
=======
--- plugin.py (revision 766)
+++ plugin.py (working copy)
 -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:
+ if self.default_doctype and not fragment:
kwargs['doctype'] = self.default_doctype
return kwargs
Kind regards
-- Dag
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Genshi" group.
To post to this group, send email to genshi googlegroups.com
To unsubscribe from this group, send email to
genshi-unsubscribe googlegroups.com
For more options, visit this group at http://gr
oups.google.com/group/genshi?hl=en
-~----------~----~----~----~------~----~------~--~---
|