Skip to content

Commit c07f340

Browse files
committed
add global alert to notify users about upcoming breaking changes
1 parent ff27e25 commit c07f340

File tree

5 files changed

+41
-0
lines changed

5 files changed

+41
-0
lines changed

src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ pub mod utils;
5353
mod docbuilder;
5454
mod web;
5555

56+
use web::page::GlobalAlert;
57+
58+
59+
// Warning message shown in the navigation bar of every page. Set to `None` to hide it.
60+
pub(crate) static GLOBAL_ALERT: Option<GlobalAlert> = Some(GlobalAlert {
61+
url: "https://blog.rust-lang.org/2019/09/18/upcoming-docsrs-changes.html",
62+
text: "Upcoming docs.rs breaking changes!",
63+
});
64+
5665

5766
/// Version string generated at build time contains last git
5867
/// commit hash and build date

src/web/page.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,21 @@ use iron::response::Response;
77
use handlebars_iron::Template;
88

99

10+
pub(crate) struct GlobalAlert {
11+
pub(crate) url: &'static str,
12+
pub(crate) text: &'static str,
13+
}
14+
15+
impl ToJson for GlobalAlert {
16+
fn to_json(&self) -> Json {
17+
let mut map = BTreeMap::new();
18+
map.insert("url".to_string(), self.url.to_json());
19+
map.insert("text".to_string(), self.text.to_json());
20+
Json::Object(map)
21+
}
22+
}
23+
24+
1025
pub struct Page<T: ToJson> {
1126
title: Option<String>,
1227
content: T,
@@ -89,6 +104,11 @@ impl<T: ToJson> ToJson for Page<T> {
89104
tree.insert("title".to_owned(), title.to_json());
90105
}
91106

107+
tree.insert("has_global_alert".to_owned(), ::GLOBAL_ALERT.is_some().to_json());
108+
if let Some(ref global_alert) = ::GLOBAL_ALERT {
109+
tree.insert("global_alert".to_owned(), global_alert.to_json());
110+
}
111+
92112
tree.insert("content".to_owned(), self.content.to_json());
93113
tree.insert("cratesfyi_version".to_owned(), ::BUILD_VERSION.to_json());
94114
tree.insert("cratesfyi_version_safe".to_owned(),

templates/navigation.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<li class="pure-menu-item"><a href="/about" class="pure-menu-link">About Docs.rs</a></li>
2222
</ul>
2323
</li>
24+
{{> navigation_global_alert}}
2425
</ul>
2526
</form>
2627
</div>

templates/navigation_global_alert.hbs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{{#if ../has_global_alert}}
2+
<li class="pure-menu-item">
3+
<a href="{{../global_alert.url}}" class="pure-menu-link warn">
4+
<i class="fa fa-fw fa-warning"></i>
5+
{{../global_alert.text}}
6+
<i class="fa fa-fw fa-warning"></i>
7+
</a>
8+
</li>
9+
{{/if}}
10+

templates/navigation_rustdoc.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
</ul>
102102
</li>
103103
{{/with}}
104+
{{> navigation_global_alert}}
104105
</ul>
105106
</form>
106107
</div>

0 commit comments

Comments
 (0)