Skip to content

Commit 233f132

Browse files
committed
Fix platform handling
- Remove unused platforms tab on /crate page. We always show platforms, even on rustdoc pages. - Don't show the platform dropdown if it's empty. - Add a test
1 parent c0718f5 commit 233f132

File tree

3 files changed

+35
-22
lines changed

3 files changed

+35
-22
lines changed

src/web/mod.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,36 @@ mod test {
789789
});
790790
}
791791

792+
#[test]
793+
fn platform_dropdown_not_shown_with_no_targets() {
794+
wrapper(|env| {
795+
release("0.1.0", env);
796+
let web = env.frontend();
797+
let text = web.get("/foo/0.1.0/foo").send()?.text()?;
798+
let platform = kuchiki::parse_html()
799+
.one(text)
800+
.select(r#"ul > li > a[aria-label="Platform"]"#)
801+
.unwrap()
802+
.count();
803+
assert_eq!(platform, 0);
804+
805+
// sanity check the test is doing something
806+
env.fake_release()
807+
.name("foo")
808+
.version("0.2.0")
809+
.add_platform("x86_64-unknown-linux-musl")
810+
.create()?;
811+
let text = web.get("/foo/0.2.0/foo").send()?.text()?;
812+
let platform = kuchiki::parse_html()
813+
.one(text)
814+
.select(r#"ul > li > a[aria-label="Platform"]"#)
815+
.unwrap()
816+
.count();
817+
assert_eq!(platform, 1);
818+
Ok(())
819+
});
820+
}
821+
792822
#[test]
793823
// https://github.com/rust-lang/docs.rs/issues/221
794824
fn yanked_crates_are_not_considered() {

templates/header/package_navigation.html

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
* `title` A possibly-null string. If it is null, `metadata.name metadata.version` will be used as the title
55
* `metadata` A non-null instance of the MetaData struct
6-
* `platforms` A possibly-null vector of strings
76
* `active_tab` A string with one of the following values:
87
* `crate`
98
* `source`
@@ -13,7 +12,7 @@
1312
Note: `false` here is acting as a pseudo-null value since you can't directly construct null values
1413
and tera requires all parameters without defaults to be filled
1514
#}
16-
{% macro package_navigation(title=false, metadata, platforms=false, active_tab) %}
15+
{% macro package_navigation(title=false, metadata, active_tab) %}
1716
<div class="cratesfyi-package-container">
1817
<div class="container">
1918
<div class="description-container">
@@ -41,25 +40,6 @@ <h1 id="crate-title">
4140

4241

4342
<div class="pure-menu pure-menu-horizontal">
44-
{# If there are platforms, show a dropdown with them #}
45-
{%- if platforms -%}
46-
<ul class="pure-menu-list platforms-menu">
47-
<li class="pure-menu-item pure-menu-has-children pure-menu-allow-hover">
48-
<a href="#" class="pure-menu-link">Platform</a>
49-
<ul class="pure-menu-children">
50-
{%- for platform in platforms -%}
51-
<li class="pure-menu-item">
52-
<a href="/{{ metadata.name }}/{{ metadata.version }}/{{ platform }}/{{ metadata.target_name }}/"
53-
class="pure-menu-link">
54-
{{ platform }}
55-
</a>
56-
</li>
57-
{%- endfor -%}
58-
</ul>
59-
</li>
60-
</ul>
61-
{%- endif -%}
62-
6343
<ul class="pure-menu-list">
6444
{# The crate information tab #}
6545
<li class="pure-menu-item"><a href="/crate/{{ crate_path | safe }}"

templates/rustdoc/topbar.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,9 @@
213213
</li>{#
214214

215215
Display the platforms that the release has been built for
216-
#}<li class="pure-menu-item pure-menu-has-children">
216+
#}
217+
{% if metadata.doc_targets %}
218+
<li class="pure-menu-item pure-menu-has-children">
217219
<a href="#" class="pure-menu-link" aria-label="Platform">
218220
{{ "cogs" | fas }}
219221
<span class="title">Platform</span>
@@ -238,6 +240,7 @@
238240
<span class="title">Feature flags</span>
239241
</a>
240242
</li>
243+
{% endif %}
241244
</ul>
242245

243246
{%- include "header/topbar_end.html" -%}

0 commit comments

Comments
 (0)