Skip to content

Commit 5d9e21c

Browse files
committed
Follow BEM for CSS, use separate class for JS hooks
1 parent 4e28fd5 commit 5d9e21c

File tree

3 files changed

+32
-23
lines changed

3 files changed

+32
-23
lines changed

warehouse/static/js/warehouse/utils/repository-info.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default () => {
2929
return;
3030
}
3131
repoInfoContainer.classList.remove("hidden");
32-
const items = document.querySelectorAll(".repo-info__item");
32+
const items = document.querySelectorAll(".js-repo-data");
3333
items.forEach(function(elem) {
3434
const jsonKey = elem.dataset.key;
3535
let jsonValue = json[jsonKey];

warehouse/static/sass/blocks/_repo-info.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717
1818
<div class="repo-info">
1919
<em>Service statistics:</em> // GitHub or GitLab
20-
<span class="statistic-item">
20+
<span class="repo-info__item">
2121
<i class="fa fa-star" aria-hidden="true"></i> // fa icon
2222
<strong>Star: </strong> // item title
23-
<span class="repo-info__item" data-key="star_count">1</span> // item value
23+
<span>1</span> // item value
2424
</span>
2525
</div>
2626
2727
*/
2828
.repo-info {
29-
.statistic-item {
29+
&__item {
3030
@include clearfix;
3131
display: block;
3232
padding: $spacing-unit / 4 $spacing-unit / 2;

warehouse/templates/includes/packaging/project-data.html

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,50 +26,59 @@ <h3 class="sidebar-section__title">Project links</h3>
2626
</div>
2727
{% endif %}
2828

29-
{% macro statistic_item(title, json_data_key, json_base_url_key=None, url_ending=None, icon=None) %}
29+
{% macro repo_item(title, json_data_key, json_base_url_key=None, url_ending=None, icon=None) %}
3030
{% if not icon %}
3131
{% if title == 'Stars' %}
3232
{% set icon = 'fa-star' %}
3333
{% elif title == 'Forks' %}
3434
{% set icon = 'fa-code-branch' %}
35-
{% elif title == 'Open issues/PRs' %}
35+
{% elif title == 'Open issues / PRs' %}
3636
{% set icon = 'fa-exclamation-circle' %}
3737
{% endif %}
3838
{% endif %}
3939
{% if json_base_url_key %}
40-
<a class="statistic-item repo-info__item"
41-
data-key="{{ json_base_url_key }}" data-attr="href" data-supplement="{{ url_ending }}"
42-
rel="noopener" target="_blank">
43-
{% else %}
44-
<span class="statistic-item">
45-
{% endif %}
40+
<a class="repo-info__item js-repo-data"
41+
data-key="{{ json_base_url_key }}"
42+
data-attr="href"
43+
data-supplement="{{ url_ending }}"
44+
rel="noopener"
45+
target="_blank">
4646
<i class="fa {{ icon }}" aria-hidden="true"></i>
4747
<strong>{{ title }}: </strong>
48-
<span class="repo-info__item" data-key="{{ json_data_key }}"></span>
49-
{% if json_base_url_key %}
48+
<span class="js-repo-data" data-key="{{ json_data_key }}"></span>
5049
</a>
5150
{% else %}
51+
<span class="repo-info__item">
52+
<i class="fa {{ icon }}" aria-hidden="true"></i>
53+
<strong>{{ title }}: </strong>
54+
<span class="js-repo-data" data-key="{{ json_data_key }}"></span>
5255
</span>
5356
{% endif %}
5457
{% endmacro %}
5558

5659
<div class="sidebar-section">
57-
<h3 class="sidebar-section__title">Statistics</h3>
5860
{% if release.github_repo_info_url %}
61+
<h3 class="sidebar-section__title">
62+
<i class="fab fa-github" aria-hidden="true"></i>
63+
GitHub statistics
64+
</h3>
5965
<div class="repo-info hidden" data-url="{{release.github_repo_info_url}}">
60-
<em>GitHub statistics:</em>
61-
{{ statistic_item('Stars', 'stargazers_count', 'html_url', '/stargazers') }}
62-
{{ statistic_item('Forks', 'forks_count', 'html_url', '/network') }}
63-
{{ statistic_item('Open issues/PRs', 'open_issues_count', 'html_url', '/issues') }}
66+
{{ repo_item('Stars', 'stargazers_count', 'html_url', '/stargazers') }}
67+
{{ repo_item('Forks', 'forks_count', 'html_url', '/network') }}
68+
{{ repo_item('Open issues / PRs', 'open_issues_count', 'html_url', '/issues') }}
6469
</div>
6570
{% elif release.gitlab_repo_info_url %}
71+
<h3 class="sidebar-section__title">
72+
<i class="fab fa-gitlab" aria-hidden="true"></i>
73+
GitLab statistics
74+
</h3>
6675
<div class="repo-info hidden" data-url="{{release.gitlab_repo_info_url}}">
67-
<em>GitLab statistics:</em>
68-
{{ statistic_item('Stars', 'star_count') }}
69-
{{ statistic_item('Forks', 'forks_count', 'web_url', '/forks') }}
76+
{{ repo_item('Stars', 'star_count') }}
77+
{{ repo_item('Forks', 'forks_count', 'web_url', '/forks') }}
7078
</div>
7179
{% endif %}
72-
<p>View statistics for this project via <a
80+
<br/>
81+
<p>View other statistics for this project via <a
7382
href="https://libraries.io/pypi/{{ release.project.name }}">Libraries.io</a>, or by using
7483
<a href="https://packaging.python.org/guides/analyzing-pypi-package-downloads/">Google
7584
BigQuery</a></p>

0 commit comments

Comments
 (0)