Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Commit

Permalink
Truncate long sidebar URLs.
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 committed Jun 17, 2014
1 parent cd9fefb commit c846439
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
12 changes: 12 additions & 0 deletions app/models/__init__.py
Expand Up @@ -61,6 +61,18 @@ def url(**kwargs):
"""
return cherrypy.request.base + routes.url_for(**kwargs)

_MAX_URL_CHARS = 40

_HTTP_RE = re.compile(r"^https?://")

def nice_url(url):
"""Returns a human-readable version of URL.
This removes the scheme and ellipsizes if necessary. It returns None if the
url is None."""
if url is None: return None
return ellipsize(_HTTP_RE.sub("", url), _MAX_URL_CHARS)

def relative_date(date):
"""Construct a human-friendly relative date string like "2 hours ago".
Expand Down
10 changes: 10 additions & 0 deletions app/models/package.py
Expand Up @@ -70,12 +70,22 @@ def homepage(self):
if self.latest_version is None: return None
return self.latest_version.pubspec.get('homepage')

@property
def nice_homepage(self):
"""The human-readable homepage URL for the package."""
return models.nice_url(self.homepage)

@property
def documentation(self):
"""The documentation URL for the package, or None."""
if self.latest_version is None: return None
return self.latest_version.documentation

@property
def nice_documentation(self):
"""The human-readable documentation URL for the package."""
return models.nice_url(self.documentation)

@property
def authors_title(self):
"""The title for the authors list of the package."""
Expand Down
4 changes: 2 additions & 2 deletions app/views/packages/show.mustache
Expand Up @@ -123,12 +123,12 @@ $ <strong>pub install</strong>

{{#package.homepage}}
<h4>Homepage</h4>
<p><a href="{{package.homepage}}">{{package.homepage}}</a></p>
<p><a href="{{package.homepage}}">{{package.nice_homepage}}</a></p>
{{/package.homepage}}

{{#package.documentation}}
<h4>Documentation</h4>
<p><a href="{{package.documentation}}">{{package.documentation}}</a></p>
<p><a href="{{package.documentation}}">{{package.nice_documentation}}</a></p>
{{/package.documentation}}

<h4>{{package.uploaders_title}}</h4>
Expand Down

0 comments on commit c846439

Please sign in to comment.