Skip to content

Commit 3244c34

Browse files
committed
highlight other diff version in the sidebar
1 parent 788ee6f commit 3244c34

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

elixir/web.py

+19-4
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,8 @@ def get_projects(basedir: str) -> list[ProjectEntry]:
444444
# Used to render version list in the sidebar
445445
VersionEntry = namedtuple('VersionEntry', 'version, url, diff_url')
446446

447+
VersionPath = namedtuple('VersionPath', 'major, minor, path')
448+
447449
# Takes result of Query.get_versions() and prepares it for the sidebar template.
448450
# Returns an OrderedDict with version information and optionally a triple with
449451
# (major, minor, version) of current_version. The triple is useful, because sometimes
@@ -456,10 +458,10 @@ def get_projects(basedir: str) -> list[ProjectEntry]:
456458
def get_versions(versions: OrderedDict[str, OrderedDict[str, str]],
457459
get_url: Callable[[str], str],
458460
get_diff_url: Optional[Callable[[str], str]],
459-
current_version: str) -> Tuple[dict[str, dict[str, list[VersionEntry]]], Tuple[str|None, str|None, str|None]]:
461+
current_version: str) -> Tuple[dict[str, dict[str, list[VersionEntry]]], VersionPath]:
460462

461463
result = OrderedDict()
462-
current_version_path = (None, None, None)
464+
current_version_path = VersionPath(None, None, None)
463465
for major, minor_verions in versions.items():
464466
for minor, patch_versions in minor_verions.items():
465467
for v in patch_versions:
@@ -471,10 +473,20 @@ def get_versions(versions: OrderedDict[str, OrderedDict[str, str]],
471473
VersionEntry(v, get_url(v), get_diff_url(v) if get_diff_url is not None else None)
472474
)
473475
if v == current_version:
474-
current_version_path = (major, minor, v)
476+
current_version_path = VersionPath(major, minor, v)
475477

476478
return result, current_version_path
477479

480+
def find_version_path(versions: OrderedDict[str, OrderedDict[str, str]],
481+
version: str) -> VersionPath:
482+
for major, minor_verions in versions.items():
483+
for minor, patch_versions in minor_verions.items():
484+
for v in patch_versions:
485+
if v == version:
486+
return VersionPath(major, minor, v)
487+
488+
return VersionPath(None, None, None)
489+
478490
def get_versions_cached(q, ctx, project):
479491
with ctx.versions_cache_lock:
480492
if project not in ctx.versions_cache:
@@ -501,6 +513,7 @@ def get_layout_template_context(q: Query, ctx: RequestContext, get_url_with_new_
501513
'projects': get_projects(ctx.config.project_dir),
502514
'versions': versions,
503515
'current_version_path': current_version_path,
516+
'other_version_path': (None, None, None),
504517
'topbar_families': TOPBAR_FAMILIES,
505518
'elixir_version_string': ctx.config.version_string,
506519
'elixir_repo_url': ctx.config.repo_url,
@@ -920,7 +933,8 @@ def generate_warning(type, version):
920933
warning = f'Files are the same in {version} and {version_other}.'
921934
else:
922935
missing_version = version_other if type == 'blob' else version
923-
warning = f'File does not exist, or is not a file in {missing_version}. ({version} displayed)'
936+
shown_version = version if type == 'blob' else version_other
937+
warning = f'File does not exist, or is not a file in {missing_version}. ({shown_version} displayed)'
924938

925939
template_ctx = {
926940
'code': generate_source(q, project, version if type == 'blob' else version_other, path),
@@ -952,6 +966,7 @@ def generate_warning(type, version):
952966
**get_layout_template_context(q, ctx, get_url_with_new_version, get_diff_url, project, version),
953967
**template_ctx,
954968

969+
'other_version_path': find_version_path(get_versions_cached(q, ctx, project), version_other),
955970
'diff_mode_available': True,
956971
'diff_checked': True,
957972
'diff_exit_url': stringify_source_path(project, version, path),

static/style.css

+4-1
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,13 @@ h2 {
453453
margin: 0;
454454
}
455455
.sidebar nav li.active a {
456-
color: #eee;
457456
color: #6d7dd2;
458457
font-weight: 700;
459458
}
459+
.sidebar nav li.active-other a {
460+
color: #d2c26d;
461+
font-weight: 700;
462+
}
460463
.sidebar nav ul {
461464
padding: 0;
462465
}

templates/sidebar.html

+7-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ <h3 class="screenreader">Versions</h3>
2828
{% endif %}
2929

3030
{% set current_major, current_minor, current_version = current_version_path %}
31+
{% set other_major, other_minor, other_version = other_version_path %}
3132
{% for major, major_versions in (versions|default({})).items() %}
3233
<li>
33-
<span class="{{ 'active' if current_major == major else '' }}">{{ major }}</span>
34+
<span class="{{ 'active' if major in (current_major, other_major) else '' }}">{{ major }}</span>
3435

3536
<ul>
3637
{% for minor, minor_versions in major_versions.items() %}
@@ -40,10 +41,13 @@ <h3 class="screenreader">Versions</h3>
4041
</li>
4142
{% else %}
4243
<li>
43-
<span class="{{ 'active' if minor == current_minor else '' }}">{{ minor }}</span>
44+
<span class="{{ 'active' if minor in (current_minor, other_minor) else '' }}">{{ minor }}</span>
4445
<ul>
4546
{% for v in minor_versions %}
46-
<li class="li-link {{ 'active' if v.version == current_tag else '' }}">
47+
<li class="li-link
48+
{{ 'active' if v.version == current_tag else '' }}
49+
{{ 'active-other' if v.version == other_tag else '' }}
50+
">
4751
<a class="version-link-source" href="{{ v.url }}">
4852
{{ v.version }}
4953
</a>

0 commit comments

Comments
 (0)