TurboGears / tg2

Python web framework with full-stack layer implemented on top of a microframework core with support for SQL DBMS, MongoDB and Pluggable Applications
http://www.turbogears.org/
Other
806 stars 78 forks source link

kajiki templating #77

Open alexbodn opened 8 years ago

alexbodn commented 8 years ago

hello friends, and a big thank for turbogears. i've made and being maintaining a tg 2.1.5 app, that is currently in upgrading process to html5/kajiki. please allow me to give back, and implement my patches for code and documentation. indeed, upgrading to tg 2.3 would be good too, but my tg is quite patched and extended, that would need some more work.

  1. output validation: the @expose should have content_type='application/xhtml+xml' i see in the tg 23 code this is the engines variables, but i have no app to try it myself. the output may be validated at https://html5.validator.nu it's been done before the actual render, see below.
  2. parameters: KajikiRenderer.call should also take **kwargs, that will be received as the render_params passed to @expose. in render_template, i did the following to produce a DOCTYPEless output, by the genshi parameter doctype=None. if you have a better way, go ahead, please.
        load_parms = dict()                                                     
        if 'doctype' in kwargs and kwargs['doctype'] is None:                   
            load_parms['is_fragment'] = True                                    
        template = template_vars['app_globals'].kajiki_loader.load(             
            template_name, **load_parms)                                        
        response.headers['Content-Type'] = \                                    
            'application/xhtml+xml; charset=%s' % response.charset              
  1. tw2. as my kajiki widgets and other kajiki templates share the same kajiki modules, i made a small patch to add_tosca2_middleware, so that the template path will be the same in imports.
        self.custom_tw2_config.update(                                          
            paths_templates=self.paths.templates,.                              
        )                                                                       
        default_tw2_config.update(self.custom_tw2_config)                       

this would need a patch that i've already submitted in tw2.core.

  1. the migration documentation at http://turbogears.readthedocs.io/en/latest/turbogears/kajiki-xml-templates.html my aim is at html5, hence all templates should be <!DOCTYPE html> this will even be nice for code editors. tw2 widgets do not add the doctype, and regular @expose may have render_params=dict(doctype=None.) to have no doctype. all templates should have xmlns="http://www.w3.org/1999/xhtml" in their . regular templates extended by py:extends should have py:strip="1". if a py:block is been defined within a tag, that tag should not be py:strip="1", but py:if="0".

hope that helps, alex

amol- commented 8 years ago

the @expose should have content_type='application/xhtml+xml'

Newly quickstarted 2.3 apps come configured in a HTML5 way, so they serve as text/html. Making xhtml the default would force the majority of users to change this.

KajikiRenderer.call should also take **kwargs, that will be received as the render_params passed to @expose.

That's actually already supported in 2.3, but was undocumented, has been documented in an August commit still unreleased :)

my kajiki widgets and other kajiki templates share the same kajiki modules, i made a small patch to add_tosca2_middleware, so that the template path will be the same in imports.

That looks useful, I'll try to check Tw2 integration as soon as the tw2 patch is approved.

alexbodn commented 8 years ago

the far i could understand, the content type would be needed to validate as xhtml 5. this is the format requested from the template designer.

i saw your submits on tw2.core ;) .