X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=apps%2Fpatchwork%2Ftemplatetags%2Fsyntax.py;fp=apps%2Fpatchwork%2Ftemplatetags%2Fsyntax.py;h=0000000000000000000000000000000000000000;hb=ad2762cf775a8dde508de47164d6429f3fd724f1;hp=abdbb4dcf72de3ab88d8f3289548b8b43deb2899;hpb=f09e982f58384946111d4157fd2b7c2b31b78612;p=patchwork diff --git a/apps/patchwork/templatetags/syntax.py b/apps/patchwork/templatetags/syntax.py deleted file mode 100644 index abdbb4d..0000000 --- a/apps/patchwork/templatetags/syntax.py +++ /dev/null @@ -1,75 +0,0 @@ -# Patchwork - automated patch tracking system -# Copyright (C) 2008 Jeremy Kerr -# -# This file is part of the Patchwork package. -# -# Patchwork is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# Patchwork is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Patchwork; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -from django import template -from django.utils.html import escape -from django.utils.safestring import mark_safe -import re - -register = template.Library() - -def _compile(t): - (r, str) = t - return (re.compile(r, re.M | re.I), str) - -_patch_span_res = map(_compile, [ - ('^(Index:?|diff|\-\-\-|\+\+\+|\*\*\*) .*$', 'p_header'), - ('^\+.*$', 'p_add'), - ('^-.*$', 'p_del'), - ('^!.*$', 'p_mod'), - ]) - -_patch_chunk_re = \ - re.compile('^(@@ \-\d+(?:,\d+)? \+\d+(?:,\d+)? @@)(.*)$', re.M | re.I) - -_comment_span_res = map(_compile, [ - ('^\s*Signed-off-by: .*$', 'signed-off-by'), - ('^\s*Acked-by: .*$', 'acked-by'), - ('^\s*Nacked-by: .*$', 'nacked-by'), - ('^\s*Tested-by: .*$', 'tested-by'), - ('^\s*Reviewed-by: .*$', 'reviewed-by'), - ('^\s*From: .*$', 'from'), - ('^\s*>.*$', 'quote'), - ]) - -_span = '%s' - -@register.filter -def patchsyntax(patch): - content = escape(patch.content) - - for (r,cls) in _patch_span_res: - content = r.sub(lambda x: _span % (cls, x.group(0)), content) - - content = _patch_chunk_re.sub( \ - lambda x: \ - _span % ('p_chunk', x.group(1)) + ' ' + \ - _span % ('p_context', x.group(2)), \ - content) - - return mark_safe(content) - -@register.filter -def commentsyntax(comment): - content = escape(comment.content) - - for (r,cls) in _comment_span_res: - content = r.sub(lambda x: _span % (cls, x.group(0)), content) - - return mark_safe(content)