Skip to content

Commit 77c4c02

Browse files
committed
Tests, docs and ideas
1 parent a221c38 commit 77c4c02

23 files changed

+374
-331
lines changed

src/lib.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ mod web;
2020
use web::page::GlobalAlert;
2121

2222
// Warning message shown in the navigation bar of every page. Set to `None` to hide it.
23-
// pub(crate) static GLOBAL_ALERT: Option<GlobalAlert> = None;
24-
25-
pub(crate) static GLOBAL_ALERT: Option<GlobalAlert> = Some(GlobalAlert {
26-
url: "https://blog.rust-lang.org/2019/09/18/upcoming-docsrs-changes.html",
27-
text: "Upcoming docs.rs breaking changes!",
28-
css_class: "error",
29-
fa_icon: "warning",
30-
});
23+
pub(crate) static GLOBAL_ALERT: Option<GlobalAlert> = None;
24+
// pub(crate) static GLOBAL_ALERT: Option<GlobalAlert> = Some(GlobalAlert {
25+
// url: "https://blog.rust-lang.org/2019/09/18/upcoming-docsrs-changes.html",
26+
// text: "Upcoming docs.rs breaking changes!",
27+
// css_class: "error",
28+
// fa_icon: "warning",
29+
// });
3130

3231
/// Version string generated at build time contains last git
3332
/// commit hash and build date

src/web/page/models.rs

+8
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ impl WebPage for Error {
218218
fn template() -> &'static str {
219219
"error.html"
220220
}
221+
222+
fn get_status(&self) -> Status {
223+
self.status
224+
}
221225
}
222226

223227
#[derive(Debug, Clone, PartialEq, Serialize)]
@@ -239,6 +243,10 @@ impl WebPage for Search {
239243
fn template() -> &'static str {
240244
"releases/releases.html"
241245
}
246+
247+
fn get_status(&self) -> Status {
248+
self.status
249+
}
242250
}
243251

244252
impl Default for Search {

src/web/releases.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ pub fn author_handler(req: &mut Request) -> IronResult<Response> {
485485
show_next_page,
486486
show_previous_page,
487487
page_number,
488-
author: Some(author_name.to_owned()),
488+
author: Some(author_name),
489489
}
490490
.into_response()
491491
}
@@ -587,7 +587,7 @@ pub fn search_handler(req: &mut Request) -> IronResult<Response> {
587587

588588
// FIXME: There is no pagination
589589
Search {
590-
title: title,
590+
title,
591591
results,
592592
search_query: Some(query.to_owned()),
593593
..Default::default()
@@ -1004,8 +1004,7 @@ mod tests {
10041004
"description": "serde makes things other things",
10051005
"target_name": "x86_64-pc-windows-msvc",
10061006
"rustdoc_status": true,
1007-
"release_time": super::super::duration_to_str(now),
1008-
"release_time_rfc3339": time::at(now).rfc3339().to_string(),
1007+
"release_time": time::at(now).rfc3339().to_string(),
10091008
"stars": 100
10101009
});
10111010

@@ -1018,8 +1017,7 @@ mod tests {
10181017
"description": "serde makes things other things",
10191018
"target_name": null,
10201019
"rustdoc_status": true,
1021-
"release_time": super::super::duration_to_str(now),
1022-
"release_time_rfc3339": time::at(now).rfc3339().to_string(),
1020+
"release_time": time::at(now).rfc3339().to_string(),
10231021
"stars": 100
10241022
});
10251023

@@ -1032,8 +1030,7 @@ mod tests {
10321030
"description": null,
10331031
"target_name": null,
10341032
"rustdoc_status": true,
1035-
"release_time": super::super::duration_to_str(now),
1036-
"release_time_rfc3339": time::at(now).rfc3339().to_string(),
1033+
"release_time": time::at(now).rfc3339().to_string(),
10371034
"stars": 100
10381035
});
10391036

src/web/rustdoc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -813,8 +813,8 @@ mod test {
813813
.create()?;
814814

815815
let web = env.frontend();
816-
let redirect = latest_version_redirect("/dummy/0.1.0/dummy/", web)?;
817-
assert_eq!(redirect, "/dummy/0.2.1/dummy/index.html");
816+
let redirect = dbg!(latest_version_redirect("/dummy/0.1.0/dummy/", web))?;
817+
assert_eq!(dbg!(redirect), "/dummy/0.2.1/dummy/index.html");
818818

819819
let redirect = latest_version_redirect("/dummy/0.2.0/dummy/", web)?;
820820
assert_eq!(redirect, "/dummy/0.2.1/dummy/index.html");

templates/base.html

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
{% import "macros.html" as macros -%}
2-
{% import "header/package_navigation.html" as navigation %}
1+
{%- import "macros.html" as macros -%}
2+
{%- import "header/package_navigation.html" as navigation -%}
33

44
<!DOCTYPE html>
55
<html lang="en">
@@ -8,7 +8,7 @@
88
<meta charset="UTF-8">
99
<meta name="viewport" content="width=device-width, initial-scale=1">
1010
<meta name="generator" content="docs.rs {{ docsrs_version() }}">
11-
{% block meta -%}{% endblock meta -%}
11+
{%- block meta -%}{%- endblock meta -%}
1212

1313
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pure/0.6.0/pure-min.css" type="text/css"
1414
media="all" />
@@ -20,23 +20,24 @@
2020
<link rel="stylesheet" href="/rustdoc-{{ rustc_resource_suffix() }}.css" type="text/css" media="all" />
2121
<link rel="stylesheet" href="/light-{{ rustc_resource_suffix() }}.css" type="text/css" media="all" />
2222
<link rel="stylesheet" href="/style.css?{{ docsrs_version() | slugify }}" type="text/css" media="all" />
23-
{% block css -%}{% endblock css -%}
23+
{%- block css -%}{%- endblock css -%}
2424

2525
<link rel="search" href="/opensearch.xml" type="application/opensearchdescription+xml" title="Docs.rs">
2626

27-
<title>{% block title %} Docs.rs {% endblock title -%}</title>
27+
<title>{%- block title -%} Docs.rs {%- endblock title -%}</title>
2828
</head>
2929

3030
<body>
31-
{% include "header/topbar.html" -%}
32-
{% block header %}{% endblock header -%}
31+
{%- include "header/topbar.html" -%}
3332

34-
{% block body %}{% endblock body -%}
33+
{%- block header %}{% endblock header -%}
34+
35+
{%- block body -%}{%- endblock body -%}
3536
</body>
3637

3738
<script type="text/javascript" src="/menu.js?{{ docsrs_version() | slugify }}"></script>
3839
<script type="text/javascript" src="/index.js?{{ docsrs_version() | slugify }}"></script>
3940

40-
{% block javascript -%}{% endblock javascript -%}
41+
{%- block javascript -%}{%- endblock javascript -%}
4142

4243
</html>

templates/crate/builds.html

+21-21
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
{% extends "base.html" -%}
1+
{%- extends "base.html" -%}
22

3-
{% block title %}
3+
{%- block title -%}
44
{{ macros::doc_title(name=metadata.name, version=metadata.version) }}
5-
{% endblock title %}
5+
{%- endblock title -%}
66

7-
{% block header -%}
7+
{%- block header -%}
88
{{ navigation::package_navigation(metadata=metadata, active_tab="builds") }}
9-
{% endblock header -%}
9+
{%- endblock header -%}
1010

11-
{% block body -%}
11+
{%- block body -%}
1212
<div class="container">
1313
<div class="recent-releases-container">
1414
{# If there is a build log then show it #}
1515
{# TODO: When viewing a build log, show a back button or a hide button #}
16-
{% if build_log -%}
16+
{%- if build_log -%}
1717
<div class="release">
1818
<strong>Build #{{ build_log.id }} {{ build_log.build_time | date(format="%+") }}</strong>
1919
</div>
2020

21-
{% filter dedent %}
21+
{%- filter dedent -%}
2222
<pre>
2323
$ rustc --version
2424
{{ build_log.rustc_version }}
@@ -27,24 +27,24 @@
2727
$ docsrs ...
2828
{{ build_log.output }}
2929
</pre>
30-
{% endfilter %}
31-
{% endif -%}
30+
{%- endfilter -%}
31+
{%- endif -%}
3232

3333
<div class="release">
3434
<strong>Builds</strong>
3535
</div>
3636

3737
<ul>
38-
{% for build in builds -%}
38+
{%- for build in builds -%}
3939
<li>
4040
<a href="/crate/{{ metadata.name }}/{{ metadata.version }}/builds/{{ build.id }}" class="release">
4141
<div class="pure-g">
4242
<div class="pure-u-1 pure-u-sm-1-24 build">
43-
{% if build.build_status -%}
44-
{% set build_icon = "check" -%}
45-
{% else -%}
46-
{% set build_icon = "close" -%}
47-
{% endif -%}
43+
{%- if build.build_status -%}
44+
{%- set build_icon = "check" -%}
45+
{%- else -%}
46+
{%- set build_icon = "close" -%}
47+
{%- endif -%}
4848
<i class="fa fa-{{ build_icon }}"></i>
4949
</div>
5050
<div class="pure-u-1 pure-u-sm-10-24">{{ build.rustc_version }}</div>
@@ -53,16 +53,16 @@
5353
</div>
5454
</a>
5555
</li>
56-
{% endfor -%}
56+
{%- endfor -%}
5757
</ul>
5858

5959
<div class="about">
6060
{# BuildsPage.metadata is an `Option<MetaData>`, so accessing it can fail #}
61-
{% if metadata -%}
61+
{%- if metadata -%}
6262
<h4>{{ metadata.name }}'s sandbox limits</h4>
63-
{% else -%}
63+
{%- else -%}
6464
<h4>Sandbox limits</h4>
65-
{% endif -%}
65+
{%- endif -%}
6666

6767
<p>
6868
All the builds on docs.rs are executed inside a sandbox with limited
@@ -79,4 +79,4 @@ <h4>Sandbox limits</h4>
7979
</div>
8080
</div>
8181
</div>
82-
{% endblock body -%}
82+
{%- endblock body -%}

0 commit comments

Comments
 (0)