On Thu, Aug 15, 2013 at 4:33 AM, Antonia Horincar <
[email protected]> wrote:

> Hi,
>
> I have almost finished implementing the embedding feature for tickets,
> milestones, products and queries, and I'm trying to figure out what should
> I work on next. That's why I read again what you said about the
> ITemplateStreamFilter interface. I'm not sure anymore that I understood
> what this interface does. Can you tell me more about its role?
>
> Thanks,
> Antonia


ITemplateStreamFilter allows you to modify the HTML template before it is
rendered in the browser. You can utilize a Genshi stream filter, which
works with XPath expressions, to locate the HTML code of interest and then
add, delete or modify it. For example, you could find a `div` with a
certain value for the `id` attribute and place a submit button after it.

http://genshi.edgewall.org/wiki/Documentation/filters.html#transformer

I found it to be one of the most challenging aspects of Trac to work with.
I'm still not sure how to efficiently debug the code, so I find myself
making educated guesses as to why my stream filter isn't finding a match in
the template (as opposed to being able to inspect the state of things in a
debugger).

I'd recommend checking out the entire trac-hacks repository and grep'ping
for `ITemplateStreamFilter` to see some examples of how it can be used.
IIRC, the code in TicketDeletePlugin (deprecated with Trac 0.12) is half
decent. There are also a few examples in the Trac codebase. Reading the
Genshi docs is also a good place to start.

One advantage to using ITemplateStreamFilter is that your plugin can
function the same in a browser with JavaScript disabled. This isn't very
important for Bloodhound since it was decided early on that Bloodhound
would require JavaScript, and I haven't seen any attention paid to making
Bloodhound work effectively without JavaScript. The Trac devs have
expressed concern about the performance of ITemplateStreamFilter and seem
to be opting to use JavaScript, in general:

http://trac.edgewall.org/ticket/11014#comment:3

Reply via email to