Mercurial > kallithea
changeset 6180:c3892e3a6ba3
helpers: merge urlify_commit into urlify_text
More reuse - they are already almost doing the same.
test_urlify_test is updated to use the new repo_name parameter and urlify
hashes.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Tue, 06 Sep 2016 00:51:18 +0200 |
parents | c759acdc463a |
children | 41882a2d41ef |
files | kallithea/lib/helpers.py kallithea/templates/admin/gists/show.html kallithea/templates/changelog/changelog.html kallithea/templates/changelog/changelog_summary_data.html kallithea/templates/changeset/changeset.html kallithea/templates/changeset/changeset_range.html kallithea/templates/compare/compare_cs.html kallithea/templates/files/files_source.html kallithea/templates/pullrequests/pullrequest_show.html kallithea/templates/search/search_commit.html kallithea/tests/other/test_libs.py |
diffstat | 11 files changed, 36 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/lib/helpers.py Tue Sep 06 00:51:18 2016 +0200 +++ b/kallithea/lib/helpers.py Tue Sep 06 00:51:18 2016 +0200 @@ -1279,16 +1279,26 @@ """ return url_re.sub(_urlify_text_replace, s) -def urlify_text(s, truncate=None, stylize=False, truncatef=truncate): + +def urlify_text(s, repo_name=None, link_=None, truncate=None, stylize=False, truncatef=truncate): """ - Extract urls from text and make literal html links out of them + Parses given text message and make literal html with markup. + The text will be truncated to the specified length. + Hashes are turned into changeset links to specified repository. + URLs links to what they say. + Issues are linked to given issue-server. + If link_ is provided, all text not already linking somewhere will link there. """ if truncate is not None: s = truncatef(s, truncate, whole_word=True) s = html_escape(s) + if repo_name is not None: + s = urlify_changesets(s, repo_name) if stylize: s = desc_stylize(s) s = _urlify_text(s) + if repo_name is not None: + s = urlify_issues(s, repo_name, link_) return literal(s) @@ -1328,24 +1338,6 @@ return ''.join(links) -def urlify_commit(text_, repo_name, link_=None): - """ - Parses given text message and makes proper links. - Issues are linked to given issue-server. If link_ is provided, all other - text will link there. - """ - newtext = html_escape(text_) - - # urlify changesets - extract revisions and make link out of them - newtext = urlify_changesets(newtext, repo_name) - - # extract http/https links and make them real urls - newtext = _urlify_text(newtext) - - newtext = urlify_issues(newtext, repo_name, link_) - - return literal(newtext) - def _urlify_issues_replace_f(repo_name, ISSUE_SERVER_LNK, ISSUE_PREFIX): def urlify_issues_replace(match_obj):
--- a/kallithea/templates/admin/gists/show.html Tue Sep 06 00:51:18 2016 +0200 +++ b/kallithea/templates/admin/gists/show.html Tue Sep 06 00:51:18 2016 +0200 @@ -70,7 +70,7 @@ ${h.gravatar_div(h.email_or_none(c.file_changeset.author), size=16)} <div title="${c.file_changeset.author}" class="user">${h.person(c.file_changeset.author)} - ${_('created')} ${h.age(c.file_changeset.date)}</div> </div> - <div class="commit">${h.urlify_commit(c.file_changeset.message,c.repo_name)}</div> + <div class="commit">${h.urlify_text(c.file_changeset.message,c.repo_name)}</div> </div> </div>
--- a/kallithea/templates/changelog/changelog.html Tue Sep 06 00:51:18 2016 +0200 +++ b/kallithea/templates/changelog/changelog.html Tue Sep 06 00:51:18 2016 +0200 @@ -116,7 +116,7 @@ </td> <td class="mid"> <div class="log-container"> - <div class="message" id="C-${cs.raw_id}">${h.urlify_commit(cs.message, c.repo_name,h.url('changeset_home',repo_name=c.repo_name,revision=cs.raw_id))}</div> + <div class="message" id="C-${cs.raw_id}">${h.urlify_text(cs.message, c.repo_name,h.url('changeset_home',repo_name=c.repo_name,revision=cs.raw_id))}</div> <div class="extra-container"> %if c.comments.get(cs.raw_id): <div class="comments-container">
--- a/kallithea/templates/changelog/changelog_summary_data.html Tue Sep 06 00:51:18 2016 +0200 +++ b/kallithea/templates/changelog/changelog_summary_data.html Tue Sep 06 00:51:18 2016 +0200 @@ -45,7 +45,7 @@ <a href="${h.url('changeset_home',repo_name=c.repo_name,revision=cs.raw_id)}" class="revision-link">${h.show_id(cs)}</a> </td> <td> - ${h.urlify_commit(h.chop_at(cs.message,'\n'),c.repo_name, h.url('changeset_home',repo_name=c.repo_name,revision=cs.raw_id))} + ${h.urlify_text(h.chop_at(cs.message,'\n'),c.repo_name, h.url('changeset_home',repo_name=c.repo_name,revision=cs.raw_id))} </td> <td><span class="tooltip" title="${h.fmt_date(cs.date)}"> ${h.age(cs.date)}</span>
--- a/kallithea/templates/changeset/changeset.html Tue Sep 06 00:51:18 2016 +0200 +++ b/kallithea/templates/changeset/changeset.html Tue Sep 06 00:51:18 2016 +0200 @@ -156,7 +156,7 @@ </div> % endif - <div class="message">${h.urlify_commit(c.changeset.message, c.repo_name)}</div> + <div class="message">${h.urlify_text(c.changeset.message, c.repo_name)}</div> </div> </div> <div class="changes_txt">
--- a/kallithea/templates/changeset/changeset_range.html Tue Sep 06 00:51:18 2016 +0200 +++ b/kallithea/templates/changeset/changeset_range.html Tue Sep 06 00:51:18 2016 +0200 @@ -50,7 +50,7 @@ <div title="${_('Changeset status')}" class="changeset-status-ico"><i class="icon-circle changeset-status-${c.statuses[cnt]}"></i></div> %endif </td> - <td><div class="message">${h.urlify_commit(h.wrap_paragraphs(cs.message),c.repo_name)}</div></td> + <td><div class="message">${h.urlify_text(h.wrap_paragraphs(cs.message),c.repo_name)}</div></td> </tr> %endfor </table>
--- a/kallithea/templates/compare/compare_cs.html Tue Sep 06 00:51:18 2016 +0200 +++ b/kallithea/templates/compare/compare_cs.html Tue Sep 06 00:51:18 2016 +0200 @@ -73,7 +73,7 @@ </div> %endfor </div> - <div id="C-${cs.raw_id}" class="message">${h.urlify_commit(cs.message, c.repo_name)}</div> + <div id="C-${cs.raw_id}" class="message">${h.urlify_text(cs.message, c.repo_name)}</div> </td> </tr> %endfor
--- a/kallithea/templates/files/files_source.html Tue Sep 06 00:51:18 2016 +0200 +++ b/kallithea/templates/files/files_source.html Tue Sep 06 00:51:18 2016 +0200 @@ -51,7 +51,7 @@ ${h.gravatar_div(h.email_or_none(c.changeset.author), size=16)} <div title="${c.changeset.author}" class="user">${h.person(c.changeset.author)}</div> </div> - <div class="commit">${h.urlify_commit(c.changeset.message,c.repo_name)}</div> + <div class="commit">${h.urlify_text(c.changeset.message,c.repo_name)}</div> </div> <div class="code-body"> %if c.file.is_browser_compatible_image():
--- a/kallithea/templates/pullrequests/pullrequest_show.html Tue Sep 06 00:51:18 2016 +0200 +++ b/kallithea/templates/pullrequests/pullrequest_show.html Tue Sep 06 00:51:18 2016 +0200 @@ -43,7 +43,7 @@ %endif </div> <div class="input"> - <div class="formatted-fixed">${h.urlify_commit(c.pull_request.description, c.pull_request.org_repo.repo_name)}</div> + <div class="formatted-fixed">${h.urlify_text(c.pull_request.description, c.pull_request.org_repo.repo_name)}</div> </div> </div> @@ -205,7 +205,7 @@ </div> %endfor </div> - <div class="message" style="white-space:normal; height:1.1em; max-width: 500px; padding:0">${h.urlify_commit(cs.message, c.repo_name)}</div> + <div class="message" style="white-space:normal; height:1.1em; max-width: 500px; padding:0">${h.urlify_text(cs.message, c.repo_name)}</div> </td> %endif </tr>
--- a/kallithea/templates/search/search_commit.html Tue Sep 06 00:51:18 2016 +0200 +++ b/kallithea/templates/search/search_commit.html Tue Sep 06 00:51:18 2016 +0200 @@ -21,7 +21,7 @@ <pre>${h.literal(sr['message_hl'])}</pre> </div> %else: - <div class="message">${h.urlify_commit(sr['message'], sr['repository'])}</div> + <div class="message">${h.urlify_text(sr['message'], sr['repository'])}</div> %endif </div> </div>
--- a/kallithea/tests/other/test_libs.py Tue Sep 06 00:51:18 2016 +0200 +++ b/kallithea/tests/other/test_libs.py Tue Sep 06 00:51:18 2016 +0200 @@ -351,7 +351,7 @@ """@mention @someone""", ""), ("deadbeefcafe 123412341234", - """deadbeefcafe 123412341234""", + """<a class="revision-link" href="/repo_name/changeset/deadbeefcafe">deadbeefcafe</a> <a class="revision-link" href="/repo_name/changeset/123412341234">123412341234</a>""", ""), # tags are covered by test_tag_extractor ]) @@ -359,7 +359,19 @@ from kallithea.lib.helpers import urlify_text expected = self._quick_url(expected, tmpl="""<a href="%s">%s</a>""", url_=url_) - assert urlify_text(sample, stylize=True) == expected + assert urlify_text(sample, 'repo_name', stylize=True) == expected + + @parametrize('sample,expected', [ + ("deadbeefcafe @mention, and http://foo.bar/ yo", + """<a class="message-link" href="#the-link"></a>""" + """<a class="revision-link" href="/repo_name/changeset/deadbeefcafe">deadbeefcafe</a>""" + """<a class="message-link" href="#the-link"> @mention, and </a>""" + """<a href="http://foo.bar/">http://foo.bar/</a>""" + """<a class="message-link" href="#the-link"> yo</a>"""), + ]) + def test_urlify_link(self, sample, expected): + from kallithea.lib.helpers import urlify_text + assert urlify_text(sample, 'repo_name', link_='#the-link') == expected @parametrize('test,expected', [ ("", None),