Edgewall Software
Modify

Opened 14 years ago

Closed 12 years ago

#10226 closed enhancement (wontfix)

Add extension point for genshi directive factories

Reported by: Carsten Klein <carsten.klein@…> Owned by:
Priority: normal Milestone:
Component: rendering Version:
Severity: normal Keywords:
Cc: leho@… Branch:
Release Notes:
API Changes:
Internal Changes:

Description (last modified by Remy Blank)

Note that this is based on the research done for http://genshi.edgewall.org/ticket/395

PROBLEM

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.

SOLUTION

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, ITemplateDirectiveProvider.

The interface is simple, it basically requires a single method:

get_template_directives()

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.

Example:

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) 

RATIONALE

While the 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 IRequestHandler etc.

Attachments (0)

Change History (6)

comment:1 by Carsten Klein <carsten.klein@…>, 14 years ago

I thought i had them all changed, but DirectiveFactory and ExtensionPoint are still valid links… please escape those, thanks!

comment:2 by Remy Blank, 14 years ago

Description: modified (diff)

comment:3 by Carsten Klein <carsten.klein@…>, 13 years ago

I will provide a sample directive + provider incl. also the required patches the chrome/api ASAP.

The sample directive will be a hello world sort of thing so that you can test this out when applying the patch. It will register itself using the standard entry points.

comment:4 by lkraav <leho@…>, 13 years ago

Cc: leho@… added

comment:5 by anonymous, 12 years ago

This has been a while and I moved on to other projects… Since this also requires major changes to genshi, which currently uses a hard coded resolution method and execution order for its built in directives, it was kind of hard to get the prototype to a level that I would call ready for evaluation. The prototype still exists and I will have a look at it as soon as I find the time.

comment:6 by Christian Boos, 12 years ago

Resolution: wontfix
Status: newclosed

Same here. We don't expect to put more work related to Genshi enhancements.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The ticket will remain with no owner.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from (none) to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.