Beispiel #1
0
def annotate_content(context, filenode, **options):
    """
    Usage::

       {% annotate_content filenode cssclass="code-highlight" %}
    """
    def annotate_changeset(changeset):
        template_name = "projector/project/repository/"\
                        "annotate_changeset_cell.html"

        context['line_changeset'] = changeset
        out = render_to_string(template_name, context)
        return out

    order = ['annotate', 'ls', 'code']
    headers = {}
    try:
        return annotate_highlight(
            filenode,
            order=order,
            headers=headers,
            annotate_from_changeset_func=annotate_changeset,
            **options)
    except VCSError:
        raise Http404
Beispiel #2
0
def annotate_content(context, filenode, **options):
    """
    Usage::

       {% annotate_content filenode cssclass="code-highlight" %}
    """
    def annotate_changeset(changeset):
        template_name = "projector/project/repository/"\
                        "annotate_changeset_cell.html"

        context['line_changeset'] = changeset
        out = render_to_string(template_name, context)
        return out

    order = ['annotate', 'ls', 'code']
    headers = {}
    try:
        return annotate_highlight(filenode, order=order, headers=headers,
            annotate_from_changeset_func=annotate_changeset, **options)
    except VCSError:
        raise Http404
Beispiel #3
0
def render_file(file_):
    """
    Calls vcs util to output pygments highlighted file
    """

    return annotate.annotate_highlight(file_, order=('ls', 'code'))
Beispiel #4
0
def pygmentize_annotation(repo_name, filenode, **kwargs):
    """pygmentize function for annotation

    :param filenode:
    """

    color_dict = {}
    def gen_color(n=10000):
        """generator for getting n of evenly distributed colors using
        hsv color and golden ratio. It always return same order of colors

        :returns: RGB tuple
        """

        def hsv_to_rgb(h, s, v):
            if s == 0.0: return v, v, v
            i = int(h * 6.0) # XXX assume int() truncates!
            f = (h * 6.0) - i
            p = v * (1.0 - s)
            q = v * (1.0 - s * f)
            t = v * (1.0 - s * (1.0 - f))
            i = i % 6
            if i == 0: return v, t, p
            if i == 1: return q, v, p
            if i == 2: return p, v, t
            if i == 3: return p, q, v
            if i == 4: return t, p, v
            if i == 5: return v, p, q

        golden_ratio = 0.618033988749895
        h = 0.22717784590367374

        for _ in xrange(n):
            h += golden_ratio
            h %= 1
            HSV_tuple = [h, 0.95, 0.95]
            RGB_tuple = hsv_to_rgb(*HSV_tuple)
            yield map(lambda x:str(int(x * 256)), RGB_tuple)

    cgenerator = gen_color()

    def get_color_string(cs):
        if color_dict.has_key(cs):
            col = color_dict[cs]
        else:
            col = color_dict[cs] = cgenerator.next()
        return "color: rgb(%s)! important;" % (', '.join(col))

    def url_func(repo_name):

        def _url_func(changeset):
            author = changeset.author
            date = changeset.date
            message = tooltip(changeset.message)

            tooltip_html = ("<div style='font-size:0.8em'><b>Author:</b>"
                            " %s<br/><b>Date:</b> %s</b><br/><b>Message:"
                            "</b> %s<br/></div>")

            tooltip_html = tooltip_html % (author, date, message)
            lnk_format = '%5s:%s' % ('r%s' % changeset.revision,
                                     short_id(changeset.raw_id))
            uri = link_to(
                    lnk_format,
                    url('changeset_home', repo_name=repo_name,
                        revision=changeset.raw_id),
                    style=get_color_string(changeset.raw_id),
                    class_='tooltip',
                    title=tooltip_html
                  )

            uri += '\n'
            return uri
        return _url_func

    return literal(annotate_highlight(filenode, url_func(repo_name), **kwargs))
Beispiel #5
0
def render_file(file_):
    """
    Calls vcs util to output pygments highlighted file
    """

    return annotate.annotate_highlight(file_, order=('ls', 'code'))