#2287: [PATCH] No simple way to make TurboGears 2 produce HTML
-------------------------+--------------------------------------------------
 Reporter:  chrisz       |        Owner:        
     Type:  enhancement  |       Status:  new   
 Priority:  high         |    Milestone:  2.1a1 
Component:  TurboGears   |      Version:  2.0rc1
 Severity:  normal       |   Resolution:        
 Keywords:  html patch   |  
-------------------------+--------------------------------------------------
Old description:

> In TG 1.0, switching between HTML and XHTML output was the matter of only
> one config setting, but in TG 2.0 this has become very difficult. By
> default TG 2.0 produces XHTML (while TG 1.0 produced HTML by default) and
> there is no clean and simple way to use HTML in TG 2.0.
>
> Note that I'm not against using XHTML as the default, but there are many
> good reasons to produce HTML instead of XHTML, so people should at least
> be given the [http://www.htmlgoodies.com/beyond/xml/print.php/3669451
> choice].
>
> There are two problems:
>
>  1. Changing the output method of the default render function (using
> Genshi) is not as straightforward as it should be (as discussed
> [http://groups.google.com/group/turbogears/browse_thread/thread/7f65c32d4621a52e
> here]).
>  2. Even if you change the default Genshi renderer, the ressource
> injection of !ToscaWidgets will still use XHTML for CSS links, because it
> uses the string.Template rendering engine with a hardcoded XHTML template
> (as discussed [http://groups.google.de/group/toscawidgets-
> discuss/browse_thread/thread/91765d109965ad2d here]).
>
> My current solution is to add the following code to
> `config/environment.py`:
> {{{
> # Make Genshi render HTML (instead of XHTML) by default:
>
> _load_environment = load_environment
>
> def load_environment(*args):
>
>     _load_environment(*args)
>
>     from genshi.output import DocType, HTMLSerializer
>
>     render_genshi = base_config.render_functions.genshi
>
>     def render_genshi_html(*args, **kwargs):
>         return render_genshi(method='html', *args, **kwargs)
>
>     base_config.render_functions.genshi = render_genshi_html
>
> # Monkey-patch ToscaWidget so that it creates a valid HMTL link tag
> # instead of a XHTML tag when injecting resources:
>
> from tw.api import CSSLink
>
> CSSLink.template = CSSLink.template.replace('/>', '>')
> }}}
> This solves the problem, but it is really ugly and complicated. Something
> so basic should have a much simpler solution. I think this is an annoying
> step backward in TG2 compared with TG1.

New description:

 In TG 1.0, switching between HTML and XHTML output was the matter of only
 one config setting, but in TG 2.0 this has become very difficult. By
 default TG 2.0 produces XHTML (while TG 1.0 produced HTML by default) and
 there is no clean and simple way to use HTML in TG 2.0.

 Note that I'm not against using XHTML as the default, but there are many
 good reasons to produce HTML instead of XHTML, so people should at least
 be given the [http://www.htmlgoodies.com/beyond/xml/print.php/3669451
 choice].

 There are two problems:

  1. Changing the output method of the default render function (using
 Genshi) is not as straightforward as it should be (as discussed
 
[http://groups.google.com/group/turbogears/browse_thread/thread/7f65c32d4621a52e
 here]).
  2. Even if you change the default Genshi renderer, the ressource
 injection of !ToscaWidgets will still use XHTML for CSS links, because it
 uses the string.Template rendering engine with a hardcoded XHTML template
 (as discussed [http://groups.google.de/group/toscawidgets-
 discuss/browse_thread/thread/91765d109965ad2d here]).

 My current solution is to add the following code to
 `config/environment.py`:
 {{{
 # Make Genshi render HTML (instead of XHTML) by default:

 _load_environment = load_environment

 def load_environment(*args):

     _load_environment(*args)

     render_genshi = base_config.render_functions.genshi

     def render_genshi_html(*args, **kwargs):
         return render_genshi(method='html', *args, **kwargs)

     base_config.render_functions.genshi = render_genshi_html

 # Monkey-patch ToscaWidget so that it creates a valid HMTL link tag
 # instead of a XHTML tag when injecting resources:

 from tw.api import CSSLink

 CSSLink.template = CSSLink.template.replace('/>', '>')
 }}}
 This solves the problem, but it is really ugly and complicated. Something
 so basic should have a much simpler solution. I think this is an annoying
 step backward in TG2 compared with TG1.

Comment (by chrisz):

 Ok, I commited a [http://bitbucket.org/mramm/tg-21/changeset/36d34eb956e0/
 similar patch] now.

 However, there are still two open problems:

 First, the resource injection issue as mentioned above. To fix this, we
 need to work on [http://toscawidgets.org/trac/tw/ticket/40 TW ticket 40].

 Second, the doctype is not adapted when you change the method from xhtml
 to html, i.e. you need to set the correct doctype in all your templates,
 which is not only inconvenient, but also bad if you want to view the
 templates directly. To fix this, we need to add a custom Genshi renderer
 since passing a doctype is not supported by Pylons (see
 [http://pylonshq.com/project/pylonshq/ticket/61 Pylons ticket 613]).

-- 
Ticket URL: <http://trac.turbogears.org/ticket/2287#comment:6>
TurboGears <http://www.turbogears.org/>
TurboGears front-to-back web development

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "TurboGears Tickets" group.
This group is read-only. No posting by normal members allowed.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/turbogears-tickets?hl=en?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to