Changeset - c3892e3a6ba3
[Not reviewed]
default
0 11 0
Mads Kiilerich - 9 years ago 2016-09-06 00:51:18
madski@unity3d.com
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.
11 files changed with 36 insertions and 32 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/helpers.py
Show inline comments
 
@@ -1279,16 +1279,26 @@ def _urlify_text(s):
 
    """
 
    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 @@ def linkify_others(t, l):
 

	
 
    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):
kallithea/templates/admin/gists/show.html
Show inline comments
 
@@ -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>
 

	
kallithea/templates/changelog/changelog.html
Show inline comments
 
@@ -116,7 +116,7 @@ ${self.repo_context_bar('changelog', c.f
 
                        </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">
kallithea/templates/changelog/changelog_summary_data.html
Show inline comments
 
@@ -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>
kallithea/templates/changeset/changeset.html
Show inline comments
 
@@ -156,7 +156,7 @@ ${self.repo_context_bar('changelog', c.c
 
                     </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">
kallithea/templates/changeset/changeset_range.html
Show inline comments
 
@@ -50,7 +50,7 @@ ${self.repo_context_bar('changelog')}
 
                    <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>
kallithea/templates/compare/compare_cs.html
Show inline comments
 
@@ -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
kallithea/templates/files/files_source.html
Show inline comments
 
@@ -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():
kallithea/templates/pullrequests/pullrequest_show.html
Show inline comments
 
@@ -43,7 +43,7 @@ ${self.repo_context_bar('showpullrequest
 
            %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 @@ ${self.repo_context_bar('showpullrequest
 
                              </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>
kallithea/templates/search/search_commit.html
Show inline comments
 
@@ -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>
kallithea/tests/other/test_libs.py
Show inline comments
 
@@ -351,7 +351,7 @@ class TestLibs(TestController):
 
       """@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 @@ class TestLibs(TestController):
 
        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),
0 comments (0 inline, 0 general)