Changeset - 53f19cdfa40c
[Not reviewed]
default
0 6 0
Mads Kiilerich - 10 years ago 2015-06-19 18:00:42
madski@unity3d.com
helpers: introduce urlify_stylize_text for correctly and safely stylizing and urlifying a string
6 files changed with 18 insertions and 27 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/journal.py
Show inline comments
 
@@ -236,16 +236,13 @@ class JournalController(BaseController):
 
            return _render('revision', repo_name, cs_cache.get('revision'),
 
                           cs_cache.get('raw_id'), cs_cache.get('author'),
 
                           cs_cache.get('message'))
 

	
 
        def desc(desc):
 
            from pylons import tmpl_context as c
 
            if c.visual.stylify_metatags:
 
                return h.urlify_text(h.desc_stylize(h.truncate(desc, 60)))
 
            else:
 
                return h.urlify_text(h.truncate(desc, 60))
 
            return h.urlify_text(desc, truncate=60, stylize=c.visual.stylify_metatags)
 

	
 
        def repo_actions(repo_name):
 
            return _render('repo_actions', repo_name)
 

	
 
        def owner_actions(user_id, username):
 
            return _render('user_name', user_id, username)
kallithea/lib/helpers.py
Show inline comments
 
@@ -1270,16 +1270,21 @@ def _urlify_text(s):
 
    """
 
    def url_func(match_obj):
 
        url_full = match_obj.group(1)
 
        return '<a href="%(url)s">%(url)s</a>' % ({'url': url_full})
 
    return url_re.sub(url_func, s)
 

	
 
def urlify_text(s):
 
def urlify_text(s, truncate=None, stylize=False, truncatef=truncate):
 
    """
 
    Extract urls from text and make literal html links out of them
 
    """
 
    if truncate is not None:
 
        s = truncatef(s, truncate)
 
    s = html_escape(s)
 
    if stylize:
 
        s = desc_stylize(s)
 
    s = _urlify_text(s)
 
    return literal(s)
 

	
 
def urlify_changesets(text_, repository):
 
    """
 
    Extract revision ids from changeset and make link from them
kallithea/model/repo.py
Show inline comments
 
@@ -206,16 +206,13 @@ class RepoModel(BaseModel):
 
        def last_rev(repo_name, cs_cache):
 
            return _render('revision', repo_name, cs_cache.get('revision'),
 
                           cs_cache.get('raw_id'), cs_cache.get('author'),
 
                           cs_cache.get('message'))
 

	
 
        def desc(desc):
 
            if c.visual.stylify_metatags:
 
                return h.urlify_text(h.desc_stylize(h.html_escape(h.truncate(desc, 60))))
 
            else:
 
                return h.urlify_text(h.html_escape(h.truncate(desc, 60)))
 
            return h.urlify_text(desc, truncate=60, stylize=c.visual.stylify_metatags)
 

	
 
        def state(repo_state):
 
            return _render("repo_state", repo_state)
 

	
 
        def repo_actions(repo_name):
 
            return _render('repo_actions', repo_name, super_user_actions)
kallithea/templates/index_base.html
Show inline comments
 
@@ -56,17 +56,13 @@
 
                              <a href="${url('repos_group_home',group_name=gr.group_name)}">
 
                                <i class="icon-folder"></i>
 
                                <span class="dt_repo_name">${gr.name}</span>
 
                              </a>
 
                            </div>
 
                        </td>
 
                        %if c.visual.stylify_metatags:
 
                            <td>${h.urlify_text(h.desc_stylize(gr.group_description))}</td>
 
                        %else:
 
                            <td>${gr.group_description}</td>
 
                        %endif
 
                        <td>${h.urlify_text(gr.group_description, stylize=c.visual.stylify_metatags)}</td>
 
                        ## this is commented out since for multi nested repos can be HEAVY!
 
                        ## in number of executed queries during traversing uncomment at will
 
                        ##<td><b>${gr.repositories_recursive_count}</b></td>
 
                    </tr>
 
                  % endfor
 
              </table>
kallithea/templates/summary/summary.html
Show inline comments
 
@@ -81,17 +81,13 @@ summary = lambda n:{False:'summary-short
 
            </div>
 

	
 
            <div class="field">
 
              <div class="label-summary">
 
                  <label>${_('Description')}:</label>
 
              </div>
 
                 %if c.visual.stylify_metatags:
 
                   <div class="input ${summary(c.show_stats)} desc">${h.urlify_text(h.desc_stylize(h.html_escape(c.db_repo.description)))}</div>
 
                 %else:
 
                   <div class="input ${summary(c.show_stats)} desc">${h.urlify_text(h.html_escape(c.db_repo.description))}</div>
 
                 %endif
 
              <div class="input ${summary(c.show_stats)} desc">${h.urlify_text(c.db_repo.description, stylize=c.visual.stylify_metatags)}</div>
 
            </div>
 

	
 
            <div class="field">
 
              <div class="label-summary">
 
                  <label>${_('Trending files')}:</label>
 
              </div>
kallithea/tests/other/test_libs.py
Show inline comments
 
@@ -186,20 +186,20 @@ class TestLibs(BaseTestCase):
 
        sample = (
 
            "hello pta[tag] gog [[]] [[] sda ero[or]d [me =>>< sa]"
 
            "[requires] [stale] [see<>=>] [see => http://url.com]"
 
            "[requires => url] [lang => python] [just a tag]"
 
            "[,d] [ => ULR ] [obsolete] [desc]]"
 
        )
 
        from kallithea.lib.helpers import desc_stylize, html_escape
 
        res = desc_stylize(html_escape(sample))
 
        self.assertTrue('<div class="metatag" tag="tag">tag</div>' in res)
 
        self.assertTrue('<div class="metatag" tag="obsolete">obsolete</div>' in res)
 
        self.assertTrue('<div class="metatag" tag="stale">stale</div>' in res)
 
        self.assertTrue('<div class="metatag" tag="lang">python</div>' in res)
 
        self.assertTrue('<div class="metatag" tag="requires">requires =&gt; <a href="/url">url</a></div>' in res)
 
        self.assertTrue('<div class="metatag" tag="tag">tag</div>' in res)
 
        from kallithea.lib.helpers import urlify_text
 
        res = urlify_text(sample, stylize=True)
 
        self.assertIn('<div class="metatag" tag="tag">tag</div>', res)
 
        self.assertIn('<div class="metatag" tag="obsolete">obsolete</div>', res)
 
        self.assertIn('<div class="metatag" tag="stale">stale</div>', res)
 
        self.assertIn('<div class="metatag" tag="lang">python</div>', res)
 
        self.assertIn('<div class="metatag" tag="requires">requires =&gt; <a href="/url">url</a></div>', res)
 
        self.assertIn('<div class="metatag" tag="tag">tag</div>', res)
 

	
 
    def test_alternative_gravatar(self):
 
        from kallithea.lib.helpers import gravatar_url
 
        _md5 = lambda s: hashlib.md5(s).hexdigest()
 

	
 
        #mock pylons.url
0 comments (0 inline, 0 general)