Add extension point for genshi directive factories
|Reported by:||Owned by:|
Description (last modified by )
Note that this is based on the research done for http://genshi.edgewall.org/ticket/395
Currently, we are able to extend Trac at the response/template stream processing level only. At the response processing level, we are able to introduce custom
ITemplateStreamFilters, however, none of these have the power of actually introducing new directives to the Genshi template engine. As such, they will not be evaluated during rendering of the template, but instead will have to process all of the generated stream multiple times. In the end, this will lead to minor to massive performance decrease depending on the number of filters in your system.
Of course, one can still implement custom Python macros that will be evaluated during request processing, however, these will not provide for the power inherent to custom directives. Besides that, these macros are not be Trac components and thus they cannot participate in the overall benefits provided by Trac's component system.
I would like to propose that we add an extension point for plugging in additional directive factories that would provide extra functionality at the template level.
This will require a new entry point, say,
The interface is simple, it basically requires a single method:
which will return both the namespace and a factory derived from
DirectiveFactory as a tuple, or multiple such tuples in case that it provides multiple namespaces and directives belonging to these namespaces.
class MyDirectivesProvider(Component): implements(ITemplateDirectiveProvider) def get_template_directives(): yield ('http://some.namespace.here', MyDirectiveFactory())
It will also require a slight modification to
trac.web.chrome which will a) query for any extensions to the extension point, e.g.
directive_providers = ExtensionPoint(ITemplateDirectiveProvider)
and, b) will add the directives and the namespaces provided by those plugins upon load of a given template in
def load_template(...): ... for provider in self.directive_providers: for namespace, factory in provider.get_template_directives(): template.add_directives(namespace, factory)
ITemplateStreamFilter still has its purpose as a post processing mechanism at the markup stream level, by introducing new template level directives, one can easily introduce much more complex concepts into Trac, that will be executed and evaluated during template processing.
Subsequently, processing these custom directives will be a one time operation while Genshi processes the event stream internally.
For a more sophisticated example of what can be done by introducing custom directives to the Genshi template, see for example the proposal for portlets over at TracDev/Proposals/PortalTrac.
There, you have the
IPortlet extension point, which in turn is evaluated by a template directive
<p:portlet ... />. The component extending upon
IPortlet is able to implement arbitrary extension points and thus can serve both as a content provider for template rendering purposes, and it also can serve as an