Mercurial > kallithea
comparison rhodecode/lib/helpers.py @ 3405:a9adca4ba3c9 beta
fixed urlify changesets regex + tests
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Tue, 26 Feb 2013 00:11:59 +0100 |
parents | 5ff79fad209c |
children | b8f929bff7e3 |
comparison
equal
deleted
inserted
replaced
3404:7854097b189c | 3405:a9adca4ba3c9 |
---|---|
1002 | 1002 |
1003 :param text_: | 1003 :param text_: |
1004 :param repository: repo name to build the URL with | 1004 :param repository: repo name to build the URL with |
1005 """ | 1005 """ |
1006 from pylons import url # doh, we need to re-import url to mock it later | 1006 from pylons import url # doh, we need to re-import url to mock it later |
1007 URL_PAT = re.compile(r'(?:^|\s)([0-9a-fA-F]{12,40})(?:$|\s)') | 1007 URL_PAT = re.compile(r'(^|\s)([0-9a-fA-F]{12,40})($|\s)') |
1008 | 1008 |
1009 def url_func(match_obj): | 1009 def url_func(match_obj): |
1010 rev = match_obj.groups()[0] | 1010 rev = match_obj.groups()[1] |
1011 pref = '' | 1011 pref = match_obj.groups()[0] |
1012 suf = '' | 1012 suf = match_obj.groups()[2] |
1013 if match_obj.group().startswith(' '): | 1013 |
1014 pref = ' ' | |
1015 if match_obj.group().endswith(' '): | |
1016 suf = ' ' | |
1017 tmpl = ( | 1014 tmpl = ( |
1018 '%(pref)s<a class="%(cls)s" href="%(url)s">' | 1015 '%(pref)s<a class="%(cls)s" href="%(url)s">' |
1019 '%(rev)s' | 1016 '%(rev)s</a>%(suf)s' |
1020 '</a>' | |
1021 '%(suf)s' | |
1022 ) | 1017 ) |
1023 return tmpl % { | 1018 return tmpl % { |
1024 'pref': pref, | 1019 'pref': pref, |
1025 'cls': 'revision-link', | 1020 'cls': 'revision-link', |
1026 'url': url('changeset_home', repo_name=repository, revision=rev), | 1021 'url': url('changeset_home', repo_name=repository, revision=rev), |