Git Browser
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

78 lines
2.5 KiB

# -*- coding: utf-8 -*-
from django import template
from django.contrib.humanize.templatetags.humanize import naturaltime
from django.template.base import TemplateSyntaxError
from django.template.defaultfilters import date, slugify
from django.template.loader import render_to_string
from django.utils.html import linebreaks
from django.utils.safestring import mark_safe
from gitbrowser.utils.linking import Autolinker
register = template.Library()
def time_tag(datetime, label=None, itemprop=""):
if not datetime:
return ""
s = '<time datetime="%s" title="%s"%s>%s</time>' % (
date(datetime, 'c'),
(' itemprop="%s"' % itemprop) if itemprop else "",
label or naturaltime(datetime))
return mark_safe(s)
def author_tag(author, with_avatar=True, avatar_size=16, itemprop=None):
itemprops = itemprop or ['author']
return mark_safe(render_to_string('templatetags/author_tag.html', {
'email_slug': slugify(,
'itemprops': ('itemprop="%s" ' % ' '.join(itemprops)) if itemprops else '',
'avatar': with_avatar,
'avatar_size': avatar_size,
def do_bootstrap_tab(parser, token):
tag_name, tab_name = token.split_contents()
if not (tab_name[0] == tab_name[-1] and tab_name[0] in ('"', "'")):
raise template.TemplateSyntaxError("%r tag's argument should be in quotes" % tag_name)
except ValueError:
raise TemplateSyntaxError("%r tag takes exact two parameter" % token.contents.split()[0])
nodelist = parser.parse(('endbootstrap_tab',))
return BootstrapTabNode(nodelist, tab_name[1:-1])
class BootstrapTabNode(template.Node):
def __init__(self, nodelist, tabname):
self.nodelist = nodelist
self.tabname = tabname
def render(self, context):
output = self.nodelist.render(context)
css = ' class="active"' if context.get('current_tab', None) == self.tabname else ""
return '<li role="presentation"%s>' % css + output + '</li>'
def clone_url_selector(repository):
return {
'urls': repository.clone_urls
def autolink(context, message):
repository = context.get('repository', None)
return linebreaks(Autolinker().link(message, repository))