Edgewall Software

Changes between Version 1 and Version 2 of TracDev/PortingFromClearSilverToGenshi


Ignore:
Timestamp:
Jul 9, 2007, 12:02:59 PM (17 years ago)
Author:
osimons <simon-code@…>
Comment:

Added a section for getting insight into the objects and methods available in the Python rendering context.

Legend:

Unmodified
Added
Removed
Modified
  • TracDev/PortingFromClearSilverToGenshi

    v1 v2  
    251251 - Implementing [source:sandbox/genshi/trac/ticket/query.py@3725#L740 Ticket Query] macro (''table'' mode)
    252252 - Sending [source:sandbox/genshi/trac/notification.py@3725#L99 notification] e-mails
     253
     254== Debugging ==
     255
     256Genshi is very different from ClearSilver. For ClearSilver the possibilities was essentially defined by the syntax + the HDF dataset that was available. Genshi evaluates Python, and operates in a Python context that makes a large number of objects directly available for use. However, doing `?hdfdump=1` on a Genshi template will only show a fraction of this content - whatever is added to the dictionary returned from the request handler and post-processors. Where is the project name? Where is the chrome links? Permissions?
     257
     258Here is a starting point for getting insight into the context, and help debugging your own templates. It is an example `site.html` file that can be added to global or project 'templates' folder, and which adds a debug output to all pages viewed. If you already have a `site.html`, just add the `<body py:match=...` element to the bottom of your own file. It contains massive amounts of information; use, trim, add to, and re-style to suit your particular needs:
     259
     260{{{
     261#!xml
     262<html xmlns="http://www.w3.org/1999/xhtml"
     263       xmlns:py="http://genshi.edgewall.org/"
     264       xmlns:xi="http://www.w3.org/2001/XInclude"
     265       py:strip="">
     266
     267  <!--! A new debug information <div> at the bottom of all pages -->
     268  <body py:match="body" py:attrs="select('@*')">
     269    ${select('*')}
     270    <div id="debug"
     271         style="width: 100%; margin: 5px; border: 2px solid green; padding: 10px; font-family: courier;">
     272      <p style="font-size: 1.15em;"><strong>Debug output - showing information from the rendering context,
     273        and edit <code>site.html</code> to test own expressions:</strong></p>
     274      <p>Checking some href information:<br />
     275         req.base_path: $req.base_path<br />
     276         req.href(): ${req.href()}<br />
     277         req.base_url: $req.base_url<br />
     278         req.abs_href(): ${req.abs_href()}<br />
     279      </p>
     280      <p>Try using reg.hef(): ${req.href('wiki')}</p>
     281      <p>context.env.path: ${pprint(defined('context') and context.env.path or 'not defined')}</p>
     282      <p>req.args: ${pprint(req.args)}</p>
     283      <p>Test fetching an element: ${select('div[@id="mainnav"]')}</p>
     284      <div style="text-indent: -30px; padding-left: 30px;">
     285        <!--! Some potentially very long lists... -->
     286        <p style="">perm for ${perm.username}: ${pprint(perm.permissions())}</p> 
     287        <p>project: ${pprint(project)}</p> 
     288        <p>trac: ${pprint(trac or 'not defined')}</p>
     289        <p>context members: ${pprint(defined('context') and dir(context) or 'not defined')}</p>
     290        <p>context.__dict__: ${pprint(defined('context') and context.__dict__ or 'not defined')}</p> 
     291        <p><strong>req.environ:</strong>
     292          <div py:for="item in sorted(req.environ.keys())">
     293              ${item}: ${pprint(req.environ[item])}</div></p>
     294        <p><strong>req members:</strong> ${pprint(dir(req))}</p>
     295        <p><strong>req __dict__:</strong>
     296          <div py:for="item in sorted(req.__dict__.keys())">
     297              ${item}: ${pprint(req.__dict__[item])}</div></p>
     298        <p><strong>all objects from locals():</strong>
     299          <div py:for="item in sorted(locals()['data'].keys())">
     300              ${item}: ${pprint(locals()['data'][item])}</div></p>
     301        <p><strong>__builtins__:</strong>
     302          <div py:for="key in sorted(globals()['__builtins__'].keys())">
     303              ${key}: ${pprint(globals()['__builtins__'][key])}</div></p>
     304      </div>
     305    </div>
     306  </body>
     307
     308</html>
     309}}}
     310