This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor ahead of package.json discovery
- listings helper for combined project/package situations - tabs helper - minor formatting tweaks
- Loading branch information
1 parent
affc93b
commit 840b639
Showing
6 changed files
with
71 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
|
||
class FakeProject(object): | ||
|
||
def __init__(self, website, package): | ||
self.website = website | ||
self.package = package | ||
self.name = package.name | ||
self.url_path = '/on/{}/{}/'.format(package.package_manager, package.name) | ||
|
||
def get_image_url(self, size): | ||
assert size in ('large', 'small'), size | ||
return self.website.asset('package-default-{}.png'.format(size)) | ||
|
||
|
||
def with_unclaimed_packages_wrapped(website, projects_and_unclaimed_packages): | ||
out = [] | ||
for project, unclaimed_package in projects_and_unclaimed_packages: | ||
if unclaimed_package: | ||
assert project is None | ||
project = FakeProject(website, unclaimed_package) | ||
out.append(project) | ||
return out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
from collections import OrderedDict | ||
|
||
|
||
def make(htmlfunc, var, current, *names): | ||
"""Helper to spit out a struct for rendering tabs (see templates/nav-tabs.html). | ||
""" | ||
tabs = OrderedDict() | ||
tabs[names[0]] = {} | ||
for name in names[1:]: | ||
tabs[name] = {var: name} | ||
for name, tab in tabs.iteritems(): | ||
tab['link'] = '?{}={}'.format(var, tab[var]) if var in tab else '.' | ||
tab['is_selected'] = (tab.get(var) == current) | ||
tab['html'] = htmlfunc(name, tab) | ||
return list(tabs.values()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{% macro nav_tabs(tabs) %} | ||
<ul class="nav"> | ||
{% for tab in tabs %} | ||
<li> | ||
<a href="{{ tab.link }}"{% if tab.is_selected %} class="selected"{% endif %}> | ||
<span class="textwrap">{{ tab.html|safe }}</span> | ||
</a> | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters