Exemplo n.º 1
0
    def render_macro(self, req, name, content):
        query_string = ''
        compact = False
        count = False
        argv = content.split(',')
        if len(argv) > 0:
            query_string = argv[0]
            if len(argv) > 1:
                format = argv[1].strip().lower()
                if format == 'compact':
                    compact = True
                elif format == 'count':
                    count = True

        query = Query.from_string(self.env, query_string)
        query.order = 'id'
        tickets = query.execute(req)
        if tickets:
            def ticket_anchor(ticket):
                return html.A('#%s' % ticket['id'],
                              class_=ticket['status'],
                              href=req.href.ticket(int(ticket['id'])),
                              title=shorten_line(ticket['summary']))
            if compact:
                alist = [ticket_anchor(ticket) for ticket in tickets]
                return html.SPAN(alist[0], *[(', ', a) for a in alist[1:]])
            elif count:
                cnt = len(tickets)
                return html.SPAN(cnt, title='%d tickets for which %s' % 
                                 (cnt, query_string))
            else:
                return html.DL([(html.DT(ticket_anchor(ticket)),
                                 html.DD(ticket['summary']))
                                for ticket in tickets], class_='wiki compact')
Exemplo n.º 2
0
class MacroListMacro(WikiMacroBase):
    """Displays a list of all installed Wiki macros, including documentation if
    available.
    
    Optionally, the name of a specific macro can be provided as an argument. In
    that case, only the documentation for that macro will be rendered.
    
    Note that this macro will not be able to display the documentation of
    macros if the `PythonOptimize` option is enabled for mod_python!
    """
    def render_macro(self, req, name, content):
        from trac.wiki.formatter import wiki_to_html, system_message
        wiki = WikiSystem(self.env)

        def get_macro_descr():
            for macro_provider in wiki.macro_providers:
                for macro_name in macro_provider.get_macros():
                    if content and macro_name != content:
                        continue
                    try:
                        descr = macro_provider.get_macro_description(
                            macro_name)
                        descr = wiki_to_html(descr or '', self.env, req)
                    except Exception, e:
                        descr = Markup(system_message(
                            "Error: Can't get description for macro %s" \
                            % macro_name, e))
                    yield (macro_name, descr)

        return html.DL([(html.DT(html.CODE('[[', macro_name, ']]'),
                                 id='%s-macro' % macro_name),
                         html.DD(description))
                        for macro_name, description in get_macro_descr()])
Exemplo n.º 3
0
class MacroListMacro(WikiMacroBase):
    u"""Affiche une liste de toutes les macros Wiki installées, en incluant leur
    éventuelle documentation.
    
    Il est également possible d'indiquer le nom d'une macro particulière comme 
    argument. Dans ce cas, seule la documentation de cette macro sera affichée.
    
    Si l'option `PythonOptimize` est activée pour mod_python, cette macro 
    ne sera pas capable d'afficher quelque documentation que ce soit sur les 
    autres macros. 
    """

    def render_macro(self, req, name, content):
        from trac.wiki.formatter import wiki_to_html, system_message
        wiki = WikiSystem(self.env)

        def get_macro_descr():
            for macro_provider in wiki.macro_providers:
                for macro_name in macro_provider.get_macros():
                    if content and macro_name != content:
                        continue
                    try:
                        descr = macro_provider.get_macro_description(macro_name)
                        descr = wiki_to_html(descr or '', self.env, req)
                    except Exception, e:
                        descr = Markup(system_message(
                            "Error: Can't get description for macro %s" \
                            % macro_name, e))
                    yield (macro_name, descr)

        return html.DL([(html.DT(html.CODE('[[',macro_name,']]'),
                                 id='%s-macro' % macro_name),
                         html.DD(description))
                        for macro_name, description in get_macro_descr()])