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

Commit

Permalink
Merge branch 'dartdocs-link'
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 committed Jun 17, 2014
2 parents 3e570fe + 61a556b commit 8d39776
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 3 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
12 changes: 11 additions & 1 deletion app/models/package.py
Expand Up @@ -70,11 +70,21 @@ 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.pubspec.get('documentation')
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):
Expand Down
11 changes: 11 additions & 0 deletions app/models/package_version.py
Expand Up @@ -158,6 +158,17 @@ def short_created(self):
"""The short created time of the package version."""
return self.created.strftime('%b %d, %Y')

@property
def dartdocs_url(self):
"""The dartdocs URL for the package."""
return 'http://www.dartdocs.org/documentation/%s/%s/index.html#%s' % \
(self.package.name, self.version, self.package.name)

@property
def documentation(self):
"""The documentation URL for the package, or the default dartdocs."""
return self.pubspec.get('documentation', self.dartdocs_url)

@property
def relative_created(self):
"""The relative created time of the package version."""
Expand Down
1 change: 1 addition & 0 deletions app/static/style.css
Expand Up @@ -5090,6 +5090,7 @@ td table td, td table th {
padding: 4px;
}

td.documentation, th.documentation,
td.archive, th.archive {
text-align: center;
vertical-align: middle;
Expand Down
13 changes: 11 additions & 2 deletions app/views/packages/show.mustache
Expand Up @@ -75,13 +75,22 @@ $ <strong>pub install</strong>
<tr>
<th>Version</th>
<th>Uploaded</th>
<th class="documentation" width="60">Documentation</th>
<th class="archive" width="60">Archive</th>
</tr>
</thead>
{{#versions}}
<tr>
<th>{{version}}</th>
<td>{{short_created}}</td>
<td class="documentation">
<a href="{{documentation}}"
title="Go to the documentation of {{package.name}} {{version}}">
<i class="icon-book">
Go to the documentation of {{package.name}} {{version}}
</i>
</a>
</td>
<td class="archive">
<a href="{{download_url}}"
title="Download {{package.name}} {{version}} archive">
Expand Down Expand Up @@ -114,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
1 change: 1 addition & 0 deletions css/sass/style.scss
Expand Up @@ -154,6 +154,7 @@ td table {
}
}

td.documentation, th.documentation,
td.archive, th.archive {
text-align: center;
vertical-align: middle;
Expand Down

2 comments on commit 8d39776

@a14n
Copy link
Contributor

@a14n a14n commented on 8d39776 Jun 23, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the ellipsis you can use CSS:

p.documentation {
  overflow: hidden;
  text-overflow: ellipsis;
}

@nex3
Copy link
Contributor Author

@nex3 nex3 commented on 8d39776 Jun 23, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Patches welcome 😃.

Please sign in to comment.