File: navadd.py

package info (click to toggle)
trac-navadd 0.3%2Bsvn13554-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 60 kB
  • ctags: 13
  • sloc: python: 37; makefile: 2
file content (45 lines) | stat: -rw-r--r-- 1,514 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# -*- coding: utf-8 -*-
#
# Copyright (C) 2006 Michael Renzmann <mrenzmann@otaku42.de>
# All rights reserved.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution.

from genshi.builder import tag

from trac.config import ListOption
from trac.core import Component, ExtensionPoint, implements
from trac.web.chrome import INavigationContributor


class NavAdd(Component):
    """ Allows to add items to main and meta navigation bar"""
    implements(INavigationContributor)

    nav_items = ListOption('navadd', 'add_items',
                           doc="Items that will be added to the navigation")

    # INavigationContributor methods
    def get_active_navigation_item(self, req):
        return ''

    def get_navigation_items(self, req):
        items = []
        for name in self.nav_items:
            title = self.env.config.get('navadd', '%s.title' % name)
            href = self.env.config.get('navadd', '%s.url' % name)
            perm = self.env.config.get('navadd', '%s.perm' % name)
            target = self.env.config.get('navadd', '%s.target' % name)

            if perm and not req.perm.has_permission(perm):
                continue

            if target not in ('mainnav', 'metanav'):
                target = 'mainnav'

            if not href.startswith(('http://', 'https://', '/')):
                href = req.href + href
            items.append((target, name, tag.a(title, href=href)))

        return items