Modify

Opened 11 years ago

Last modified 10 years ago

#264 new enhancement

Implement IRequestFilter, allows integration of TOC in templates

Reported by: mrenzmann@… Owned by: moschny
Priority: normal Milestone:
Component: trac.tracnav Version:
Severity: normal Keywords:
Cc:

Description

The attached patch implements IRequestFilter methods. The idea behind that is being able to use the generated TOC within a .cs-template (where you can't call a macro). The TOC content is added to the template variable tracnavplugin.toc.

Example:

I use the following snippet in a test installation, template wiki.cs:

...
<div id="content" class="wiki">

 <?cs if tracnavplugin.toc && wiki.action == "view" ?>
 <div class="tracnav-toc"><?cs var:tracnavplugin.toc ?></div>
 <?cs /if ?>

 <?cs if wiki.action == "delete" =><?cs
...

The patch should apply cleanly against current trunk. The modification works for Trac 0.10 only, since IRequestFilter are not available in previous Trac releases afaik.

Attachments (2)

irequestfilter.diff (1.7 KB) - added by anonymous 11 years ago.
Patch to add IRequestFilter to TracNav plugin
irequestfilter-2.diff (3.3 KB) - added by mrenzmann@… 10 years ago.
Revised version of the IRequestFilter patch

Download all attachments as: .zip

Change History (8)

Changed 11 years ago by anonymous

Patch to add IRequestFilter to TracNav plugin

comment:1 follow-up: Changed 10 years ago by moschny

I am yet to be convinced of the usefulness of the proposed feature. What is the main reason for referencing the toc from within the cs template?

If you want to include the toc on every page, you could use the WikiInclude plugin instead.

Your proposal has some drawbacks:

  • The toc is generated for every wiki page, regardless of whether it is used or not.
  • You can't pass arguments to the macro, so you are limited to the default name for the wiki page containing the toc.
  • The patch will not work with 0.11 where Clearsilver will be replaced by Genshi.

comment:2 in reply to: ↑ 1 Changed 10 years ago by mrenzmann@…

Replying to moschny:

I am yet to be convinced of the usefulness of the proposed feature. What is the main reason for referencing the toc from within the cs template?

Well, my reasons for this patch are simple: I want to have a navigation pane (similar to the one on teo or the licq website), without having to hardcode the actual content of the navigation pane in the templates or manually placing the macro call on each wiki page. Since macros can't be used in templates, I had the idea of adding the IRequestFilter functionality to circumvent the limitation.

If you want to include the toc on every page, you could use the WikiInclude plugin instead.

I don't agree. It's yet another macro, suffering from the same issues described above.

  • The toc is generated for every wiki page, regardless of whether it is used or not.

For my particular situation this is no problem, since I want to show the TOC on every wiki page. However, I already added a trac.ini knob to turn the IRequestFilter functionality off if it is not needed. I'll provide an updated patch when I'm in the office later.

  • You can't pass arguments to the macro, so you are limited to the default name for the wiki page containing the toc.

This has also been fixed. The wiki pages used for the TOC can be defined in trac.ini.

  • The patch will not work with 0.11 where Clearsilver will be replaced by Genshi.

I didn't look at 0.11 yet, and I have no idea about the differences between Genshi and Clearsilver. On the other hand I don't claim that this patch implements a perfect solution. It's working for my purposes, and since it could be useful for others as well I contribute it here.

However, I'm open for suggestions to adjust the modification such that it will be usable with Trac 0.11/Genshi.

Changed 10 years ago by mrenzmann@…

Revised version of the IRequestFilter patch

comment:3 follow-up: Changed 10 years ago by mrenzmann@…

irequestfilter-2.diff is a revised version of the patch as mentioned in my previous comment. Changes:

The name of the pages used for generating the TOC can be set in trac.ini (section tracnav, keyword tocpages).

The request filter functionality has to be enabled in trac.ini (section tracnav, keyword request_filter). Set that to enabled to make use of the request filter stuff.

The first patch hardcoded the request match such that the TOC is only added for requests to the wiki handler. The matches are now configured in trac.ini (section tracnav, keyword match), which allows for example to have the TOC visible when displaying tickets, too. Matching also works for Trac setups that don't have the wiki set as default handler.
The keyword takes a comma-separated list and currently only matches the beginning of the request. This could be enhanced to allow regular expressions instead for additional flexibility.

comment:4 in reply to: ↑ 3 ; follow-up: Changed 10 years ago by schodet

Replying to mrenzmann@otaku42.de:

The first patch hardcoded the request match such that the TOC is only added for requests to the wiki handler. The matches are now configured in trac.ini (section tracnav, keyword match), which allows for example to have the TOC visible when displaying tickets, too. Matching also works for Trac setups that don't have the wiki set as default handler.
The keyword takes a comma-separated list and currently only matches the beginning of the request. This could be enhanced to allow regular expressions instead for additional flexibility.

This does not work if the url is not terminated with a slash, I tried to add a test " or req.path_info == ''" but it does not seems to work.

comment:5 in reply to: ↑ 4 ; follow-up: Changed 10 years ago by mrenzmann@…

Replying to schodet:

This does not work if the url is not terminated with a slash, I tried to add a test " or req.path_info == ''" but it does not seems to work.

I don't understand what you mean here. Which URL has to be terminated with a slash, that given as match in the configuration file, or that of the request?

comment:6 in reply to: ↑ 5 Changed 10 years ago by schodet

Replying to mrenzmann@otaku42.de:

Replying to schodet:

This does not work if the url is not terminated with a slash, I tried to add a test " or req.path_info == ''" but it does not seems to work.

I don't understand what you mean here. Which URL has to be terminated with a slash, that given as match in the configuration file, or that of the request?

that of the request.

If I go to http://my-server/trac, I do not see the TOC. If I go to http://my-server/trac/, I see it. I had modified line 344 of irequestfilter-2.diff with no success.

Add Comment

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The owner will remain moschny.
as The resolution will be set. Next status will be 'closed'.
to The owner will be changed from moschny to the specified user. Next status will be 'new'.
The owner will be changed from moschny to anonymous. Next status will be 'assigned'.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.