Can macros and ITemplateStreamFilters communicate?

17 views
Skip to first unread message

Manuel Holtgrewe

unread,
Jul 4, 2012, 5:12:08 AM7/4/12
to trac...@googlegroups.com
Dear all,

I would like to write a plugin that does the following:

1. Provide a Macro [[NarrowPage()]] that marks the current Wiki page as "narrow".
2. A ITemplateStreamFilter Component that looks for a "narrow" mark on the current page and adds a "narrow" class to div#content.

I have already figured out how to do (2) but I have so far not found a way for the Macro to communicate with the ITemplateStreamFilter.

Is this possible at all?

Cheers,
Manuel

Steffen Hoffmann

unread,
Jul 4, 2012, 7:34:04 PM7/4/12
to trac...@googlegroups.com
You could attach an additional req.args['narrow'] to formatter.req on
macro execution time, that should be available later on in req object
passed in filter_stream method. But I see, that using Request object is
or at least is planned to be depreciated according to the wiki docs [1].

So a more sustainable way leaving the req alone would be to add a
minimal, unique HTML snipped like
<div id="narrow_marker"></div>
and create a matching XPATH filter like
xpath_match = "//div[@id='narrow_marker']"
to
* find it (and possibly remove it)
* finally add the 'narrow' class to div#content
as you already know how to do by a secondary filter expression, that
should be triggered by the first one.

Sincerely,

Steffen Hoffmann


[1]
http://trac.edgewall.org/wiki/TracDev/PluginDevelopment/ExtensionPoints/trac.wiki.api.IWikiMacroProvider#Usage

RjOllos

unread,
Jul 4, 2012, 8:44:05 PM7/4/12
to trac...@googlegroups.com
I think that Steffen's suggestion is correct if you are to continue implementing this by working with ITemplateStreamFilter.

However, I did some experimenting, and from the simple description you provided and assuming you don't need to do something more complex, I think this can be implemented without messing with ITemplateStreamFilter. You can just make a macro that returnd an empty string, and add a stylesheet to the page in `expand_macro`.

I took that approach in the attached example plugin. It allows [[NarrowContent]] to be added to the page, and results in:


narrowmacro.zip

Manuel Holtgrewe

unread,
Jul 5, 2012, 4:13:58 AM7/5/12
to trac...@googlegroups.com
Thanks to both of you! This solves my problem.

RjOllos

unread,
Jul 21, 2012, 3:27:56 PM7/21/12
to trac...@googlegroups.com
On Thursday, July 5, 2012 4:13:58 AM UTC-4, Manuel Holtgrewe wrote:
Thanks to both of you! This solves my problem.

I came across #10626 (1) today, which points to (2), which has little button that narrows/expands the widths of the page content. Thought it might be interesting to you.

(1) http://trac.edgewall.org/ticket/10626
(2) http://code.optaros.com/trac/oforge/
Reply all
Reply to author
Forward
0 new messages