Why not delaying head until after body is generated - just cache it and render when body is done and anyone have added to head whatever one needs?
-----éÓÈÏÄÎÏÅ ÓÏÏÂÝÅÎÉÅ----- ïÔ: "Christopher Lenz" <[EMAIL PROTECTED]> ëÏÍÕ: [email protected] ïÔÐÒÁ×ÌÅÎÏ: 20.10.06 21:17 ôÅÍÁ: [Trac-dev] Moving wiki_to_html into the templates Hey all, Back when I was involved with porting DrProject (a Trac clone for academic use) to use the Kid template language, one thing that I found to be beneficial to reducing general code complexity/volume was that we moved the generation of wiki output into the templates. I.e. instead of having the controller prepare the HTML formatted wiki text, it'd just pass the wiki text itself, and the template would invoke wiki_to_html() on that where necessary. Christian has attempted to do the same for Trac when Genshi was still on a branch[1], but we found one problem: macros and processors in wiki text are executed relatively late in the process, i.e. when the page is already being generated. At that point, it is too late to add things like style sheets to the <head> of the page, so that for example the PatchRenderer wasn't able to tell Trac that it needed the "diff.css" stylesheet to be rendered properly. At that point Trac would already have rendered the <head> element, so obviously we can't add anything to it. There is no 100% clean way to get around that problem, unfortunately. But I think I found an approach that's good enough. The approach requires javascript to load stylesheets after the fact, in particular the $.loadStyleSheet method I've added to trac.js: <http://trac.edgewall.org/browser/trunk/htdocs/js/trac.js#L36> A macro/processor such as the PatchRenderer would call add_stylesheet () as it used to, however, that function would now have a return value: if req.environ.get('trac.chrome.rendering'): # The template is already being rendered, so return a javascript # snippet that can be used to load the stylesheet from the HTML body return tag.script(type='text/javascript')( '$.loadStyleSheet("%s", "%s")' % (link, mimetype) ) And note that it only returns that if that particular stylesheet wasn't already included in some way. In my current implementation, the macro/processor would be responsible for checking whether the function returned a value, and inserting that to its output stream in some way. But I'm going to investigate whether Trac could just put any requried $.loadStyleSheet () calls in the footer, meaning the return value wouldn't even be needed, i.e. the implementation of add_stylesheet() might end similar to the following: if req.environ.get('trac.chrome.rendering'): req.environ['trac.chrome.extrastyles'].append(href) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Trac Development" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/trac-dev -~----------~----~----~----~------~----~------~--~---
