Changes between Initial Version and Version 2 of Ticket #10226
- Timestamp:
- Jun 17, 2011, 12:13:41 AM (13 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #10226 – Description
initial v2 6 6 PROBLEM 7 7 8 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.8 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 `ITemplateStreamFilter`s, 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. 9 9 10 10 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. … … 15 15 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. 16 16 17 This will require a new entry point, say, ITemplateDirectiveProvider.17 This will require a new entry point, say, `ITemplateDirectiveProvider`. 18 18 19 19 The interface is simple, it basically requires a single method: 20 20 {{{#!python 21 21 get_template_directives() 22 23 which will return both the namespace and a factory derived from DirectiveFactoryas a tuple, or multiple such tuples in case that it provides multiple namespaces and directives belonging to these namespaces.22 }}} 23 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. 24 24 25 25 Example: 26 27 class !MyDirectivesProvider(Component):26 {{{#!python 27 class MyDirectivesProvider(Component): 28 28 implements(ITemplateDirectiveProvider) 29 29 30 30 def get_template_directives(): 31 yield (' !http://some.namespace.here', !MyDirectiveFactory())32 33 It will also require a slight modification to trac.web.chromewhich will a) query for any extensions to the extension point, e.g.34 31 yield ('http://some.namespace.here', MyDirectiveFactory()) 32 }}} 33 It will also require a slight modification to `trac.web.chrome` which will a) query for any extensions to the extension point, e.g. 34 {{{#!python 35 35 directive_providers = ExtensionPoint(ITemplateDirectiveProvider) 36 36 }}} 37 37 and, b) will add the directives and the namespaces provided by those plugins upon load of a given template in 38 38 {{{#!python 39 39 def load_template(...): 40 40 ... … … 42 42 for namespace, factory in provider.get_template_directives(): 43 43 template.add_directives(namespace, factory) 44 44 }}} 45 45 46 46 RATIONALE 47 47 48 While the ITemplateStreamFilterstill 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.48 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. 49 49 Subsequently, processing these custom directives will be a one time operation while Genshi processes the event stream internally. 50 50 51 51 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 [wiki:TracDev/Proposals/PortalTrac]. 52 52 53 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 IRequestHandleretc.53 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.