source: foldedrepositoryindexplugin/folded_repository_index/web_ui.py @ 0:79331938322d

Last change on this file since 0:79331938322d was 0:79331938322d, checked in by Tobias Föhst <foehst@…>, 6 years ago

Initial import

File size: 1.8 KB
Line 
1from trac.core import *
2from trac.web import IRequestFilter
3from trac.web.api import ITemplateStreamFilter
4from trac.web.chrome import ITemplateProvider, \
5                            add_script, add_script_data
6
7from genshi.filters import Transformer
8
9import os
10import re
11
12class FoldedRepositoryIndex(Component):
13    """Adds folding by prefix to repository index.
14
15    Repositories are collected into folded groups by mapping their names via
16    regular expressions to custom labels. This mapping is defined in the
17    `[folded-repository-index]` section of the [wiki:TracIni trac.ini] configuration
18    file.
19
20    Example:
21    {{{
22    [folded-repository-index]
23    ^finroc_ = Finroc
24    ^paper_(\d+)_ = Papers $1
25    }}}
26    """
27
28    implements(IRequestFilter, ITemplateProvider, ITemplateStreamFilter)
29
30    ### IRequestFilter methods
31    def pre_process_request(self, req, handler):
32        return handler
33
34    def post_process_request(self, req, template, data, content_type):
35        match = re.match(r'^/browser/?$', req.path_info)
36        if match:
37            config = self.config.options('folded-repository-index')
38            add_script_data(req, { 'fri_config' : dict(config) })
39            add_script(req, 'fri/folded_repository_index.js')
40        return template, data, content_type
41
42    ### ITemplateProvider methods
43    def get_templates_dirs(self):
44        return []
45
46    def get_htdocs_dirs(self):
47        from pkg_resources import resource_filename
48        return [('fri', resource_filename(__name__, 'htdocs'))]
49
50    ### ITemplateStreamFilter methods
51    def filter_stream(self, req, method, filename, stream, data):
52        match = re.match(r'^/browser/?$', req.path_info)
53        if not match:
54            return stream
55
56        filter = Transformer('//script[@src="/chrome/common/js/expand_dir.js"]')
57        return stream | filter.remove()
Note: See TracBrowser for help on using the repository browser.