|
List Info
Thread: for setting doctype from web frameworks such as TurboGears
|
|
| for setting doctype from web frameworks
such as TurboGears |

|
2007-10-11 11:36:24 |
Hi,
Currently it looks like it's only possible to set the
doctype for
Genshi templates from web frameworks using the Genshi
plugin, by using
the genshi.default_doctype, or by setting it as the first
line in the
template itself <!DOCTYPE ... Sometimes however you might
want to
render a template in different formats html, xhtml, xml
using
different expose decorators. In TurboGears theres a
possibility for
using a mapping dict for sending options directly to the
render
engine:
def expose(template=None, validators=None, allow_json=None,
html=None,
format=None, content_type=None, inputform=None,
fragment=False,
as_format="default", mapping=None,
accept_format=None):
"""Exposes a method to the web.
keyparam mapping mapping with options that are sent
to the
template
engine
...
However this mapping dict is currently not used by the
genshi plugin.
Here's a patch to fix the problem:
/genshi/genshi/template [dag]: svn diff plugin.py
Index: plugin.py
============================================================
=======
--- plugin.py (revision 766)
+++ plugin.py (working copy)
 -105,9
+105,10 
kwargs['encoding'] = self.default_encoding
return kwargs
- def render(self, info, format=None, fragment=False,
template=None):
+ def render(self, info, format=None, fragment=False,
template=None, mapping=None):
"""Render the template to a string
using the provided
info."""
kwargs = self._get_render_options(format=format)
+ kwargs.update(mapping or {})
return self.transform(info,
template).render(**kwargs)
def transform(self, info, template):
This patch makes it possible to expose functions like this:
expose(template="templates.test",
as_format="xhtml",
format="xhtml", fragment=True, mapping={'doctype'
: 'xhtml'})
expose(template="templates.signup")
def index(self):
....
Thus making it possible to render a page as both html and
xhtml if
default_doctype is set to html. Hope it's possible to get
this patch
or a variant of it into trunk.
Cheers
-- 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
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: for setting doctype from web
frameworks such as TurboGears |

|
2007-10-12 11:00:08 |
Am 11.10.2007 um 18:36 schrieb dbrattli:
> Currently it looks like it's only possible to set the
doctype for
> Genshi templates from web frameworks using the Genshi
plugin, by using
> the genshi.default_doctype, or by setting it as the
first line in the
> template itself <!DOCTYPE ... Sometimes however you
might want to
> render a template in different formats html, xhtml, xml
using
> different expose decorators. In TurboGears theres a
possibility for
> using a mapping dict for sending options directly to
the render
> engine:
>
> def expose(template=None, validators=None,
allow_json=None, html=None,
> format=None, content_type=None,
inputform=None,
> fragment=False,
> as_format="default", mapping=None,
accept_format=None):
> """Exposes a method to the web.
>
> keyparam mapping mapping with options that are sent
to the
> template
> engine
> ...
>
> However this mapping dict is currently not used by the
genshi plugin.
> Here's a patch to fix the problem:
I thought that is what the "format" parameter is
for, which IIRC is
actually honored by the plugin. What am I missing?
Cheers,
Chris
--
Christopher Lenz
cmlenz at gmx.de
http://www.cmlenz.net/
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: for setting doctype from web
frameworks such as TurboGears |

|
2007-10-12 11:33:36 |
Hi,
Setting the "format" parameter partly solves the
problem. Since my app
mostly publishes html pages, my defaults are:
genshi.default_doctype = "html-transitional"
The pages are served like this:
expose()
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://
www.w3.org/TR/html4/loose.dtd">
<html>
Setting the "format" parameter to xhtml gives me
documents with
incorrect doctype.
expose(as_format="xhtml",
format="xhtml")
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://
www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.
org/1999/xhtml">
Setting both the "format" and "doctype"
gives me:
expose(as_format="xhtml",
format="xhtml", mapping={'doctype' :
'xhtml'})
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Strict//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.
org/1999/xhtml">
So maybe it's a bug with Genshi that it gives the wrong
doctype when
using the "format" parameter? One other thing is
that setting
"fragment" to True does not seem to remove the
doctype from the html
(it was however a mistake that I included the fragment
parameter in my
first posting).
-- Dag
On Oct 12, 6:00 pm, Christopher Lenz <cml... gmx.de> wrote:
> Am 11.10.2007 um 18:36 schrieb dbrattli:
>
>
>
> > Currently it looks like it's only possible to set
the doctype for
> > Genshi templates from web frameworks using the
Genshi plugin, by using
> > the genshi.default_doctype, or by setting it as
the first line in the
> > template itself <!DOCTYPE ... Sometimes however
you might want to
> > render a template in different formats html,
xhtml, xml using
> > different expose decorators. In TurboGears theres
a possibility for
> > using a mapping dict for sending options directly
to the render
> > engine:
>
> > def expose(template=None, validators=None,
allow_json=None, html=None,
> > format=None, content_type=None,
inputform=None,
> > fragment=False,
> > as_format="default",
mapping=None, accept_format=None):
> > """Exposes a method to the
web.
>
> > keyparam mapping mapping with options that
are sent to the
> > template
> > engine
> > ...
>
> > However this mapping dict is currently not used by
the genshi plugin.
> > Here's a patch to fix the problem:
>
> I thought that is what the "format" parameter
is for, which IIRC is
> actually honored by the plugin. What am I missing?
>
> Cheers,
> Chris
> --
> Christopher Lenz
> cmlenz at gmx.de
> http://www.cmlenz.net/
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
|
|
[1-3]
|
|