示例#1
0
 def test_run_html_formatter(self):
     wiki_content = "!WikiSyntax"
     page = self.create_wiki("Dummy wiki", wiki_content)
     from trac.mimeview.api import RenderingContext
     context = RenderingContext(
         page.resource,
         href=Href('/'),
         perm=MockPerm(),
     )
     context.req = None  # 1.0 FIXME .req shouldn't be required by formatter
     format_to_html(self.env, context, wiki_content)
示例#2
0
 def test_run_html_formatter(self):
     wiki_content = "!WikiSyntax"
     page = self.create_wiki("Dummy wiki", wiki_content)
     from trac.mimeview.api import RenderingContext
     context = RenderingContext(
         page.resource,
         href=Href('/'),
         perm=MockPerm(),
     )
     context.req = None # 1.0 FIXME .req shouldn't be required by formatter
     format_to_html(self.env, context, wiki_content)
示例#3
0
 def expand_macro(self, formatter, name, content, args=None):
     style_args = {'fg': 'color', 'bg': 'background-color',
                   'size': 'font-size'}
     style_values = {'color': '', 'background-color': '', 'font-size': ''}
     space_start = ''
     space_end = ''
     if args:
         text = content
         for k in args.keys():
             style = style_args[k] if k in style_args else k
             style_values[style] = args.get(k)
         html = format_to_html(self.env, formatter.context, text)
     else:
         args = content.split(',')
         text = ','.join(args[:-1])
         args = args[-1].split('/') + ['']*3
         style_values['color'] = args.pop(0).strip()
         # background color is optional
         arg = args.pop(0).strip()
         if len(arg) > 0 and arg[0].isdigit():
             style_values['font-size'] = arg
         else:
             style_values['background-color'] = arg
             style_values['font-size'] = args.pop(0).strip()
         html = format_to_oneliner(self.env, formatter.context, text)
         if text.startswith(u' '):
             space_start = Markup('&nbsp')
         if text.endswith(u' '):
             space_end = Markup('&nbsp')
     if style_values['font-size'].isdigit():
         style_values['font-size'] += '%'
     style = ';'.join('%s:%s' % (k, v) for (k, v) in
                      style_values.iteritems() if v)
     return tag.span(space_start, html, space_end, style=style)
示例#4
0
 def expand_macro(self, formatter, name, content, args=None):
     style_args = {"fg": "color", "bg": "background-color", "size": "font-size"}
     style_values = {"color": "", "background-color": "", "font-size": ""}
     space_start = ""
     space_end = ""
     if args:
         text = content
         for k in args.keys():
             style = style_args[k] if k in style_args else k
             style_values[style] = args.get(k)
         html = format_to_html(self.env, formatter.context, text)
     else:
         args = content.split(",")
         text = ",".join(args[:-1])
         args = args[-1].split("/") + [""] * 3
         style_values["color"] = args.pop(0).strip()
         # background color is optional
         arg = args.pop(0).strip()
         if len(arg) > 0 and arg[0].isdigit():
             style_values["font-size"] = arg
         else:
             style_values["background-color"] = arg
             style_values["font-size"] = args.pop(0).strip()
         html = format_to_oneliner(self.env, formatter.context, text)
         if text.startswith(u" "):
             space_start = Markup("&nbsp")
         if text.endswith(u" "):
             space_end = Markup("&nbsp")
     if style_values["font-size"].isdigit():
         style_values["font-size"] = "%s%%" % style_values["font-size"]
     style = ";".join("%s:%s" % (k, v) for (k, v) in style_values.iteritems() if v)
     return tag.span(space_start, html, space_end, style=style)
    def expand_macro(self, formatter, name, arg_content):

        cursor = self.env.get_db_cnx().cursor()

        query = "SELECT name, due, completed, description from milestone order by due;"
        cursor.execute(query)

        miles = [mile for mile in cursor]

        content = []

        init = time.time()
        last = init

        tblMode = False
        if arg_content:
            tblMode = True
            content.append(
                '|| Milestone || Due || Days from now || Days from Previous || Completed || Description ||'
            )

        for name, due, completed, descrip in miles:

            d = date.fromtimestamp(due)
            dd = d.strftime('%b %d, %Y')
            dc = ''
            if completed:
                d = date.fromtimestamp(completed)
                dc = d.strftime('%b %d, %Y')
            dl = int((due - init) / 86400)
            dp = int((due - last) / 86400)

            if not tblMode:
                dt = " '''%s'''" % name
                dt += " ''due %s [in %d days, for %d days]" % (dd, dl, dp)
                if completed:
                    dt += '; completed %s' % dc
                dt += "''::"

                content.append(dt)
                if descrip != None and descrip.strip() != '':
                    content.append('   %s' % descrip)
            else:
                dt = '||%s||%s||%d||%d||%s||%s||' % (name, dd, dl, dp, dc,
                                                     descrip)
                content.append(dt)

            last = due

        content = '\n'.join(content)

        content = format_to_html(self.env, formatter.context, content)

        content = '<div class="milestone-list">%s</div>' % content

        # to avoid things like the above it might be nicer to use
        # Genshi tag() construction.

        return content
    def expand_macro(self, formatter, name, arg_content):

        cursor = self.env.get_db_cnx().cursor()

        query = "SELECT name, due, completed, description from milestone order by due;"
        cursor.execute(query)

        miles = [mile for mile in cursor]

        content = []

        init = time.time()
        last = init

        tblMode = False
        if arg_content:
            tblMode = True
            content.append('|| Milestone || Due || Days from now || Days from Previous || Completed || Description ||')

        for name, due, completed, descrip in miles:

            d = date.fromtimestamp(due)
            dd = d.strftime('%b %d, %Y')
            dc = ''
            if completed:
                d = date.fromtimestamp(completed)
                dc = d.strftime('%b %d, %Y')
            dl = int((due - init) / 86400)
            dp = int((due - last) / 86400)

            if not tblMode:
                dt = " '''%s'''" % name
                dt += " ''due %s [in %d days, for %d days]" % (dd, dl, dp)
                if completed:
                    dt += '; completed %s' % dc
                dt += "''::"

                content.append(dt)
                if descrip != None and descrip.strip() != '':
                    content.append('   %s' % descrip)
            else:
                dt = '||%s||%s||%d||%d||%s||%s||' % (name, dd, dl, dp, dc, descrip)
                content.append(dt)

            last = due

        content = '\n'.join(content)

        content = format_to_html(self.env, formatter.context, content)

        content = '<div class="milestone-list">%s</div>' % content

        # to avoid things like the above it might be nicer to use
        # Genshi tag() construction.

        return content
示例#7
0
    def expand_macro(self, formatter, name, pattern):

        cursor = self.env.get_db_cnx().cursor()

        query = "SELECT name, description from component order by name;"
        cursor.execute(query)

        comps = [comp for comp in cursor]

        # get a distinct list of all components for which there are tickets
        query = "SELECT component from ticket group by component;"
        cursor.execute(query)
        tickets = [page[0] for page in cursor]

        content = []

        for name, descrip in comps:
            if pattern and not re.match(pattern, name): continue

            # Get number of tickets
            count = 0
            query = "SELECT count(id) FROM ticket WHERE component='%s'" % name
            cursor.execute(query)
            for count, in cursor:
                break

            p = re.compile(' ')
            wiki_str = p.sub('', name)
            ticket_str = p.sub('+', name)
            dt = ' [wiki:%s %s]' % (wiki_str, name)
            if name in tickets:
                dt += ' ([query:component=%s %d tickets])' % (ticket_str,
                                                              count)
            dt += '::'
            content.append(dt)
            if descrip != None and descrip.strip() != '':
                content.append('   %s' % descrip)

        content = '\n'.join(content)

        content = format_to_html(self.env, formatter.context, content)
        p = re.compile('%2B')
        content = p.sub('+', content)
        content = '<div class="component-list">%s</div>' % content

        # to avoid things like the above it might be nicer to use
        # Genshi tag() construction, but this way the wiki formatter
        # gets to deal with '[query:component=%s tickets]' etc.
        # if going the Genshi route you'd replace that with something
        # like req.href.query(component="mycomp", status="open")

        return content
示例#8
0
    def expand_macro(self, formatter, name, pattern):

        cursor = self.env.get_db_cnx().cursor()

        query = "SELECT name, description from component order by name;"
        cursor.execute(query)

        comps = [comp for comp in cursor]

        # get a distinct list of all components for which there are tickets
        query = "SELECT component from ticket group by component;"
        cursor.execute(query)
        tickets = [page[0] for page in cursor]

        content = []

        for name, descrip in comps:
            if pattern and not re.match(pattern, name): continue
            
            # Get number of tickets
            count = 0
            query = "SELECT count(id) FROM ticket WHERE component='%s'" % name
            cursor.execute(query)
            for count, in cursor:
                break
            
            p = re.compile(' ')
            wiki_str = p.sub('',name)
            ticket_str = p.sub('+',name)
            dt = ' [wiki:%s %s]' % (wiki_str, name)
            if name in tickets:
                dt += ' ([query:component=%s %d tickets])' % (ticket_str, count)
            dt += '::'
            content.append(dt)
            if descrip != None and descrip.strip() != '':
                content.append('   %s' % descrip)

        content = '\n'.join(content)

        content = format_to_html(self.env, formatter.context, content)
        p = re.compile('%2B')
        content = p.sub('+',content)
        content = '<div class="component-list">%s</div>' % content

        # to avoid things like the above it might be nicer to use
        # Genshi tag() construction, but this way the wiki formatter
        # gets to deal with '[query:component=%s tickets]' etc.
        # if going the Genshi route you'd replace that with something
        # like req.href.query(component="mycomp", status="open")

        return content
示例#9
0
    def expand_macro(self, formatter, name, pattern):
        with self.env.db_query as db:
            cursor = db.cursor()
            cursor.execute(
                "SELECT name, description from component order by name;")

            comps = [comp for comp in cursor]

            # get a distinct list of all components for which there are tickets
            query = "SELECT component from ticket group by component;"
            cursor.execute(query)
            tickets = [page[0] for page in cursor]

            content = []

            for name, descrip in comps:
                if pattern and not re.match(pattern, name): continue

                # Get number of tickets
                count = 0
                query = "SELECT count(id) FROM ticket WHERE component='%s'" % name
                cursor.execute(query)
                for count, in cursor:
                    break

                p = re.compile(' ')
                wiki_str = p.sub('', name)
                ticket_str = p.sub('+', name)
                dt = ' [wiki:%s %s]' % (wiki_str, name)
                if name in tickets:
                    dt += ' ([query:component=%s %d tickets])' % (
                        ticket_str.replace('&', '\&'), count)
                dt += '::'
                content.append(dt)
                if descrip != None and descrip.strip() != '':
                    content.append('   %s' % descrip)

            content = '\n'.join(content)
            content = format_to_html(self.env, formatter.context, content)
            p = re.compile('%2B')
            content = p.sub('+', content)
            content = '<div class="component-list">%s</div>' % content
            return content
示例#10
0
    def expand_macro(self, formatter, name, args):

        cursor = self.env.get_db_cnx().cursor()

        query = "SELECT id_project, name, description from smp_project order by name;"
        cursor.execute(query)

        projs = [proj for proj in cursor]

        # get a distinct list of all projects for which there are tickets
        query = "SELECT value from ticket_custom WHERE name='project'"
        cursor.execute(query)
        tickets = [page[0] for page in cursor]

        content = []

        for id_project, name, descrip in projs:

            # Get number of tickets
            count = 0
            query = "SELECT count(ticket) FROM ticket_custom WHERE value='%s' AND name='project'" % name
            cursor.execute(query)
            for (count,) in cursor:
                break

            p = re.compile(" ")
            dt = ' [wiki:"%s" %s]' % (name, name)
            if name in tickets:
                dt += ' ([query:"project=%s" %d tickets])' % (name, count)
            dt += "::"
            content.append(dt)
            if descrip != None and descrip.strip() != "":
                content.append("   %s" % descrip)

        content = "\n".join(content)

        content = format_to_html(self.env, formatter.context, content)
        p = re.compile("%2B")
        content = p.sub("+", content)
        content = '<div class="component-list">%s</div>' % content

        return content
示例#11
0
        def to_html(text):
            """
            Format the parsed text from the rows into HTML.
            """
            if not text:
                return ''

            # simple check to determine whether format_to_html or 
            # format_to_oneliner should be used. If there are multiple
            # lines, use format_to_html, otherwise use format_to_oneliner

            stripped_text = text.strip()
            splitlines = stripped_text.splitlines()

            if len(splitlines) > 1:
                formatted_text = format_to_html(self.env, formatter.context, text)
            else:
                formatted_text = '<br />'.join( [format_to_oneliner(self.env, formatter.context, line) \
                    for line in text.splitlines()] ) 
            return Markup( formatted_text )
示例#12
0
    def expand_macro(self, formatter, name, content, args=None):
        class_list = ['wikiextras', 'box']
        style_list = []

        #noinspection PyArgumentList
        if not Icons(self.env).shadowless:
            class_list.append('shadow')

        class_arg = args.get('class', '')
        if class_arg:
            class_list.append(class_arg)

        align = 'right' if name in ['newsbox', 'rbox'] else \
                'center' if name=='imagebox' else ''
        align = args.get('align', align)
        if align:
            class_list.append(align)

        type = 'news' if name=='newsbox' else \
               'image' if name=='imagebox' else \
               self._get_type(args.get('type'))
        if type in self.types:
            td = self.types[type]  # type data
            if td[1]:  #icon
                class_list += ['icon', td[1]]
            else:
                class_list.append(type)
            bg = self.urgency_bg.get(td[0])
            if bg:
                class_list.append(bg)
            del td
        elif type:
            class_list.append(type)

        style = args.get('style', '')
        if style:
            style_list.append(style)

        width = args.get('width', '')
        if width:
            if width.isdigit():
                width += 'px'
            if self._has_icon(type):
                # compensate for icon width
                if width.endswith('px'):
                    width = '%dpx' % (int(width[:-2]) - 37)
            style_list.append('width:' + width)
        elif align == 'center':
            style_list.append('width:0')  # for the table below

        html = format_to_html(self.env, formatter.context, content)
        class_ = ' '.join(class_list)
        style = ';'.join(style_list)

        if align == 'center':
            return tag.table(tag.tr(tag.td(),
                                    tag.td(html, class_=class_, style=style),
                                    tag.td()),
                             class_='wikiextras center-box')
        else:
            return tag.div(html, class_=class_, style=style)
示例#13
0
    def expand_macro(self, formatter, name, content, args=None):
        class_list = ['wikiextras', 'box']
        style_list = []
        if args is None:
            content, args = parse_args(content)

        #noinspection PyArgumentList
        if not Icons(self.env).shadowless:
            class_list.append('shadow')

        class_arg = args.get('class', '')
        if class_arg:
            class_list.append(class_arg)

        align = 'right' if name in ['newsbox', 'rbox'] else \
                'center' if name=='imagebox' else ''
        align = args.get('align', align)
        if align:
            class_list.append(align)

        if name == 'newsbox':
            type = 'news'
        elif name == 'imagebox':
            type = 'image'
        else:
            type = args.get('type')
            if not type:
                for flag, value in args.iteritems():
                    if value is True:
                        type = flag
                        break
            type = self._get_type(type)
        if type in self.types:
            td = self.types[type]  # type data
            if td[1]:  #icon
                class_list += ['icon', td[1]]
            else:
                class_list.append(type)
            bg = self.urgency_bg.get(td[0])
            if bg:
                class_list.append(bg)
            del td
        elif type:
            class_list.append(type)

        style = args.get('style', '')
        if style:
            style_list.append(style)

        width = args.get('width', '')
        if width:
            if width.isdigit():
                width = '%spx' % width
            if width.endswith('px'):
                # compensate for padding
                if self._has_icon(type):
                    width = '%dpx' % (int(width[:-2]) - 57)
                else:
                    width = '%dpx' % (int(width[:-2]) - 22)
            style_list.append('width:%s' % width)

        html = format_to_html(self.env, formatter.context, content)
        class_ = ' '.join(class_list)
        style = ';'.join(style_list)

        return tag.div(html, class_=class_, style=style)
示例#14
0
 def expand_macro(self, formatter, name, content, args=None):
     help_file = resource_filename(__name__, 'doc/WikiIcons')
     fd = open(help_file, 'r')
     wiki_text = fd.read()
     fd.close()
     return format_to_html(self.env, formatter.context, wiki_text)
示例#15
0
    def expand_macro(self, formatter, name, content, args=None):
        class_list = ['wikiextras', 'box']
        style_list = []

        #noinspection PyArgumentList
        if not Icons(self.env).shadowless:
            class_list.append('shadow')

        class_arg = args.get('class', '')
        if class_arg:
            class_list.append(class_arg)

        align = 'right' if name in ['newsbox', 'rbox'] else \
                'center' if name=='imagebox' else ''
        align = args.get('align', align)
        if align:
            class_list.append(align)

        type = 'news' if name=='newsbox' else \
               'image' if name=='imagebox' else \
               self._get_type(args.get('type'))
        if type in self.types:
            td = self.types[type] # type data
            if td[1]: #icon
                class_list += ['icon', td[1]]
            else:
                class_list.append(type)
            bg = self.urgency_bg.get(td[0])
            if bg:
                class_list.append(bg)
            del td
        elif type:
            class_list.append(type)

        style = args.get('style', '')
        if style:
            style_list.append(style)

        width = args.get('width', '')
        if width:
            if width.isdigit():
                width += 'px'
            if width.endswith('px'):
                # compensate for padding
                if self._has_icon(type):
                    width = '%dpx' % (int(width[:-2]) - 57)
                else:
                    width = '%dpx' % (int(width[:-2]) - 22)
            style_list.append('width:' + width)
        elif align=='center':
            style_list.append('width:0') # for the table below

        html = format_to_html(self.env, formatter.context, content)
        class_ = ' '.join(class_list)
        style = ';'.join(style_list)

        if align=='center':
            return tag.table(tag.tr(tag.td(),
                                    tag.td(html, class_=class_, style=style),
                                    tag.td()),
                             class_='wikiextras center-box')
        else:
            return tag.div(html, class_=class_, style=style)
示例#16
0
    def expand_macro(self, formatter, name, project_filter):

        cursor = self.env.get_db_cnx().cursor()

        query = "SELECT name, description from component order by name;"
        cursor.execute(query)

        comps = [comp for comp in cursor]

        # get a distinct list of all components for which there are tickets
        query = "SELECT component from ticket group by component;"
        cursor.execute(query)
        tickets = [page[0] for page in cursor]

        content = []

        components = []
        if project_filter:
            query = """SELECT
                        m.component AS component
                   FROM
                        smp_project AS p,
                        smp_component_project AS m
                   WHERE
                        p.name = %s AND
                        p.id_project = m.id_project"""
            cursor.execute(query, [project_filter])
            components = [x[0] for x in cursor.fetchall()]

        for name, descrip in comps:
            if project_filter and not name in components:
                continue

            # Get number of tickets
            count = 0
            query = "SELECT count(id) FROM ticket WHERE component='%s'" % name
            cursor.execute(query)
            for (count,) in cursor:
                break

            p = re.compile(" ")
            ticket_str = p.sub("+", name)
            dt = ' [wiki:"%s" %s]' % (name, name)
            if name in tickets:
                dt += " ([query:component=%s %d tickets])" % (ticket_str, count)
            dt += "::"
            content.append(dt)
            if descrip != None and descrip.strip() != "":
                content.append("   %s" % descrip)

        content = "\n".join(content)

        content = format_to_html(self.env, formatter.context, content)
        p = re.compile("%2B")
        content = p.sub("+", content)
        content = '<div class="component-list">%s</div>' % content

        # to avoid things like the above it might be nicer to use
        # Genshi tag() construction, but this way the wiki formatter
        # gets to deal with '[query:component=%s tickets]' etc.
        # if going the Genshi route you'd replace that with something
        # like req.href.query(component="mycomp", status="open")

        return content
示例#17
0
 def expand_macro(self, formatter, name, content, args=None):
     help_file = resource_filename(__name__, 'doc/WikiIcons')
     fd = open(help_file, 'r')
     wiki_text = fd.read()
     fd.close()
     return format_to_html(self.env, formatter.context, wiki_text)
示例#18
0
    def expand_macro(self, formatter, name, content, args=None):
        class_list = ['wikiextras', 'box']
        style_list = []
        if args is None:
            content, args = parse_args(content)

        #noinspection PyArgumentList
        if not Icons(self.env).shadowless:
            class_list.append('shadow')

        class_arg = args.get('class', '')
        if class_arg:
            class_list.append(class_arg)

        align = 'right' if name in ['newsbox', 'rbox'] else \
                'center' if name=='imagebox' else ''
        align = args.get('align', align)
        if align:
            class_list.append(align)

        if name == 'newsbox':
            type = 'news'
        elif name == 'imagebox':
            type = 'image'
        else:
            type = args.get('type')
            if not type:
                for flag, value in args.iteritems():
                    if value is True:
                        type = flag
                        break
            type = self._get_type(type)
        if type in self.types:
            td = self.types[type] # type data
            if td[1]: #icon
                class_list += ['icon', td[1]]
            else:
                class_list.append(type)
            bg = self.urgency_bg.get(td[0])
            if bg:
                class_list.append(bg)
            del td
        elif type:
            class_list.append(type)

        style = args.get('style', '')
        if style:
            style_list.append(style)

        width = args.get('width', '')
        if width:
            if width.isdigit():
                width = '%spx' % width
            if width.endswith('px'):
                # compensate for padding
                if self._has_icon(type):
                    width = '%dpx' % (int(width[:-2]) - 57)
                else:
                    width = '%dpx' % (int(width[:-2]) - 22)
            style_list.append('width:%s' % width)

        html = format_to_html(self.env, formatter.context, content)
        class_ = ' '.join(class_list)
        style = ';'.join(style_list)

        return tag.div(html, class_=class_, style=style)