Edgewall Software

Changes between Version 2 and Version 3 of TracDev/ApiChanges/0.10


Ignore:
Timestamp:
Aug 30, 2006, 3:49:55 PM (18 years ago)
Author:
Christian Boos
Comment:

Introduce the new trac.util.html.Element API

Legend:

Unmodified
Added
Removed
Modified
  • TracDev/ApiChanges/0.10

    v2 v3  
    33
    44This page is aimed to help plugin developers to port their 0.9 plugin to Trac 0.10.
     5Most of the initial examples are coming from the migration of the [trachacks:DoxygenPlugin] (#TH662).
    56
    67== General Changes ==
     
    4546By using the [WikiMacros#TracIni-macro TracIni(doxygen)] macro, you'll get the documentation for all your settings.
    4647
     48=== New API for Generating HTML fragments ===
     49
     50Since Trac [milestone:0.9.3], the generation of HTML using ClearSilver has been modified so that by default, every string content will get HTML-escaped (e.g. "<br />" replaced by "&lt;br /&gt;").
     51Most plugin developers discovered this change the hard way ;)
     52The recommended way for avoiding this escaping was to wrap the strings containing markup in a `Markup` instance.
     53While this is still valid in 0.10, you should note that `Markup` is now defined in the `trac.util.html` module, though importing from `trac.util` will still work.
     54
     55More importantly, there's now a new way to programmatically generate markup content, using the `html` object, also defined in that `trac.util.html` module.
     56That object will dynamically generate `Element` objects, that can be nested.
     57The way to use it is:
     58{{{
     59  html.<elementname>(*other_elements_or_strings, **attributes)
     60}}}
     61
     62Example: (from the [trachacks:DoxygenPlugin])
     63{{{
     64#!diff
     65--- a/doxygentrac/doxygentrac.py        Tue Aug 29 14:05:15 2006 +0200
     66+++ b/doxygentrac/doxygentrac.py        Wed Aug 30 14:35:12 2006 +0200
     67@@ -40,43 +69,36 @@ class DoxygenPlugin(Component):
     68 
     69     def get_active_navigation_item(self, req):
     70         return 'doxygen'
     71+
     72     def get_navigation_items(self, req):
     73         if req.perm.has_permission('DOXYGEN_VIEW'):
     74-            # Get config variables.
     75-            title = self.env.config.get('doxygen', 'title', 'Doxygen')
     76-
     77             # Return mainnav buttons.
     78-            yield 'mainnav', 'doxygen', Markup('<a href="%s">%s</a>' % \
     79-              (self.env.href.doxygen() + '/', title))
     80+            yield 'mainnav', 'doxygen', \
     81+                  html.a(self.title, href=req.href.doxygen())
     82}}}
     83
     84For more details, refer to the [source:trunk/trac/util/html.py@head#L324 Element] docstring.
     85
    4786
    4887== Interface Changes ==
     
    5291The `get_search_results(self, req, terms, filters)` now takes a list of `terms` instead of the full `query`, as it used to do for its second argument.
    5392
    54 Example: [trachacks:DoxygenPlugin]
     93Example: (from the [trachacks:DoxygenPlugin])
    5594{{{
    5695#!diff