Skip to content

Transform "documentation" tab into button #1032

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/web/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,32 @@ impl From<PoolError> for IronError {
IronError::new(err.compat(), Status::InternalServerError)
}
}

#[cfg(test)]
mod tests {
use crate::test::wrapper;
use kuchiki::traits::TendrilSink;

#[test]
fn check_404_page_content() {
wrapper(|env| {
let page = kuchiki::parse_html().one(
env.frontend()
.get("/page-which-doesnt-exist")
.send()?
.text()?,
);
assert_eq!(page.select("#crate-title").unwrap().count(), 1);
assert_eq!(
page.select("#crate-title")
.unwrap()
.next()
.unwrap()
.text_contents(),
"The requested resource does not exist",
);

Ok(())
});
}
}
54 changes: 54 additions & 0 deletions src/web/releases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1213,4 +1213,58 @@ mod tests {
Ok(())
});
}

#[test]
fn check_releases_page_content() {
// NOTE: this is a little fragile and may have to be updated if the HTML layout changes
let sel = ".pure-menu-horizontal>.pure-menu-list>.pure-menu-item>.pure-menu-link>.title";
wrapper(|env| {
let tester = |url| {
let page = kuchiki::parse_html()
.one(env.frontend().get(url).send().unwrap().text().unwrap());
assert_eq!(page.select("#crate-title").unwrap().count(), 1);
let not_matching = page
.select(sel)
.unwrap()
.map(|node| node.text_contents())
.zip(
[
"Recent",
"Stars",
"Recent Failures",
"Failures By Stars",
"Activity",
"Queue",
]
.iter(),
)
.filter(|(a, b)| a.as_str() != **b)
.collect::<Vec<_>>();
if not_matching.len() > 0 {
let not_found = not_matching.iter().map(|(_, b)| b).collect::<Vec<_>>();
let found = not_matching.iter().map(|(a, _)| a).collect::<Vec<_>>();
assert!(
not_matching.is_empty(),
"Titles did not match for URL `{}`: not found: {:?}, found: {:?}",
url,
not_found,
found,
);
}
};

for url in &[
"/releases",
"/releases/stars",
"/releases/recent-failures",
"/releases/failures",
"/releases/activity",
"/releases/queue",
] {
tester(url);
}

Ok(())
});
}
}
44 changes: 23 additions & 21 deletions templates/about-base.html
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
{% extends "base.html" %}

{% block header %}
<div class="cratesfyi-package-container">
<div class="cratesfyi-package-container">
<div class="container">
<h1 id="crate-title" class="no-description">Docs.rs documentation</h1>
<div class="pure-menu pure-menu-horizontal">
<ul class="pure-menu-list">
{% set text = "info-circle" | fas(fw=true) %}
{% set text = text ~ ' <span class="title">About</span>' %}
{{ macros::active_link(expected="index", href="/about", text=text) }}
<div class="description-container">
<h1 id="crate-title" class="no-description">Docs.rs documentation</h1>
<div class="pure-menu pure-menu-horizontal">
<ul class="pure-menu-list">
{% set text = "info-circle" | fas(fw=true) %}
{% set text = text ~ ' <span class="title">About</span>' %}
{{ macros::active_link(expected="index", href="/about", text=text) }}

{% set text = "fonticons" | fab(fw=true) %}
{% set text = text ~ ' <span class="title">Badges</span>' %}
{{ macros::active_link(expected="badges", href="/about/badges", text=text) }}
{% set text = "fonticons" | fab(fw=true) %}
{% set text = text ~ ' <span class="title">Badges</span>' %}
{{ macros::active_link(expected="badges", href="/about/badges", text=text) }}

{% set text = "cogs" | fas(fw=true) %}
{% set text = text ~ ' <span class="title">Builds</span>' %}
{{ macros::active_link(expected="builds", href="/about/builds", text=text) }}
{% set text = "cogs" | fas(fw=true) %}
{% set text = text ~ ' <span class="title">Builds</span>' %}
{{ macros::active_link(expected="builds", href="/about/builds", text=text) }}

{% set text = "table" | fas(fw=true) %}
{% set text = text ~ ' <span class="title">Metadata</span>' %}
{{ macros::active_link(expected="metadata", href="/about/metadata", text=text) }}
{% set text = "table" | fas(fw=true) %}
{% set text = text ~ ' <span class="title">Metadata</span>' %}
{{ macros::active_link(expected="metadata", href="/about/metadata", text=text) }}

{% set text = "road" | fas(fw=true) %}
{% set text = text ~ ' <span class="title">Shorthand URLs</span>' %}
{{ macros::active_link(expected="redirections", href="/about/redirections", text=text) }}
</ul>
{% set text = "road" | fas(fw=true) %}
{% set text = text ~ ' <span class="title">Shorthand URLs</span>' %}
{{ macros::active_link(expected="redirections", href="/about/redirections", text=text) }}
</ul>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
140 changes: 70 additions & 70 deletions templates/header/package_navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,85 +15,85 @@
{% macro package_navigation(title=false, metadata, platforms=false, active_tab) %}
<div class="cratesfyi-package-container">
<div class="container">
{# Page title #}
<h1 id="crate-title">
{%- if title -%}
{{ title }}
{%- else -%}
{{ metadata.name }} {{ metadata.version }}
{{ "copy" | far(id="clipboard", aria_label="Copy crate name and version information", fa=true) }}
{%- endif -%}
</h1>
<div class="description-container">
{# The partial path of the crate, `:name/:release` #}
{%- set crate_path = metadata.name ~ "/" ~ metadata.version -%}

{# Page description #}
<div class="description">
{%- if metadata.description -%}
{{ metadata.description }}
{%- endif -%}
</div>
{# If docs are built, show a button for them #}

<div class="pure-menu pure-menu-horizontal">
{# If there are platforms, show a dropdown with them #}
{%- if platforms -%}
<ul class="pure-menu-list platforms-menu">
<li class="pure-menu-item pure-menu-has-children pure-menu-allow-hover">
<a href="#" class="pure-menu-link">Platform</a>
<ul class="pure-menu-children">
{%- for platform in platforms -%}
<li class="pure-menu-item">
<a href="/{{ metadata.name }}/{{ metadata.version }}/{{ platform }}/{{ metadata.target_name }}/"
class="pure-menu-link">
{{ platform }}
</a>
</li>
{%- endfor -%}
</ul>
</li>
</ul>
{%- endif -%}
{# Page title #}
<h1 id="crate-title">
{%- if title -%}
{{ title }}
{%- else -%}
{{ metadata.name }} {{ metadata.version }}
{{ "copy" | far(id="clipboard", aria_label="Copy crate name and version information", fa=true) }}
{%- endif -%}
</h1>

{# Page description #}
<div class="description">
{%- if metadata.description -%}
{{ metadata.description }}
{%- endif -%}
</div>

<ul class="pure-menu-list">
{# The partial path of the crate, `:name/:release` #}
{%- set crate_path = metadata.name ~ "/" ~ metadata.version -%}

{# If docs are built, show a tab for them #}
{%- if metadata.rustdoc_status -%}
<li class="pure-menu-item">
{# The docs tab redirects to the docs, so the tab will never be selected and seen #}
<a href="/{{ crate_path | safe }}/{{ metadata.target_name }}/" class="pure-menu-link">
{{ "book" | fas(fw=true) }}
<span class="title"> Documentation</span>
</a>
</li>
<div class="pure-menu pure-menu-horizontal">
{# If there are platforms, show a dropdown with them #}
{%- if platforms -%}
<ul class="pure-menu-list platforms-menu">
<li class="pure-menu-item pure-menu-has-children pure-menu-allow-hover">
<a href="#" class="pure-menu-link">Platform</a>
<ul class="pure-menu-children">
{%- for platform in platforms -%}
<li class="pure-menu-item">
<a href="/{{ metadata.name }}/{{ metadata.version }}/{{ platform }}/{{ metadata.target_name }}/"
class="pure-menu-link">
{{ platform }}
</a>
</li>
{%- endfor -%}
</ul>
</li>
</ul>
{%- endif -%}

{# The crate information tab #}
<li class="pure-menu-item"><a href="/crate/{{ crate_path | safe }}"
class="pure-menu-link{% if active_tab == 'crate' %} pure-menu-active{% endif %}">
{{ "cube" | fas(fw=true) }}
<span class="title"> Crate</span>
</a>
</li>
<ul class="pure-menu-list">
{# The crate information tab #}
<li class="pure-menu-item"><a href="/crate/{{ crate_path | safe }}"
class="pure-menu-link{% if active_tab == 'crate' %} pure-menu-active{% endif %}">
{{ "cube" | fas(fw=true) }}
<span class="title"> Crate</span>
</a>
</li>

{# The source view tab #}
<li class="pure-menu-item">
<a href="/crate/{{ crate_path | safe }}/source/"
class="pure-menu-link{% if active_tab == 'source' %} pure-menu-active{% endif %}">
{{ "folder-open" | far(fw=true) }}
<span class="title"> Source</span>
</a>
</li>
{# The source view tab #}
<li class="pure-menu-item">
<a href="/crate/{{ crate_path | safe }}/source/"
class="pure-menu-link{% if active_tab == 'source' %} pure-menu-active{% endif %}">
{{ "folder-open" | far(fw=true) }}
<span class="title"> Source</span>
</a>
</li>

{# The builds tab #}
<li class="pure-menu-item">
<a href="/crate/{{ crate_path | safe }}/builds"
class="pure-menu-link{% if active_tab == 'builds' %} pure-menu-active{% endif %}">
{{ "cogs" | fas }}
<span class="title"> Builds</span>
</a>
</li>
</ul>
{# The builds tab #}
<li class="pure-menu-item">
<a href="/crate/{{ crate_path | safe }}/builds"
class="pure-menu-link{% if active_tab == 'builds' %} pure-menu-active{% endif %}">
{{ "cogs" | fas }}
<span class="title"> Builds</span>
</a>
</li>
</ul>
</div>
</div>

{%- if metadata.rustdoc_status -%}
<a href="/{{ crate_path | safe }}/{{ metadata.target_name }}/" class="doc-link">
{{ "book" | fas(fw=true) }} Documentation
</a>
{%- endif -%}
</div>
</div>
{% endmacro package_navigation %}
Loading