Skip to content

Add global alert to notify users about upcoming breaking changes #409

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 2 commits into from
Sep 18, 2019
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
11 changes: 11 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ pub mod utils;
mod docbuilder;
mod web;

use web::page::GlobalAlert;


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


/// Version string generated at build time contains last git
/// commit hash and build date
Expand Down
24 changes: 24 additions & 0 deletions src/web/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,25 @@ use iron::response::Response;
use handlebars_iron::Template;


pub(crate) struct GlobalAlert {
pub(crate) url: &'static str,
pub(crate) text: &'static str,
pub(crate) css_class: &'static str,
pub(crate) fa_icon: &'static str,
}

impl ToJson for GlobalAlert {
fn to_json(&self) -> Json {
let mut map = BTreeMap::new();
map.insert("url".to_string(), self.url.to_json());
map.insert("text".to_string(), self.text.to_json());
map.insert("css_class".to_string(), self.css_class.to_json());
map.insert("fa_icon".to_string(), self.fa_icon.to_json());
Json::Object(map)
}
}


pub struct Page<T: ToJson> {
title: Option<String>,
content: T,
Expand Down Expand Up @@ -89,6 +108,11 @@ impl<T: ToJson> ToJson for Page<T> {
tree.insert("title".to_owned(), title.to_json());
}

tree.insert("has_global_alert".to_owned(), ::GLOBAL_ALERT.is_some().to_json());
if let Some(ref global_alert) = ::GLOBAL_ALERT {
tree.insert("global_alert".to_owned(), global_alert.to_json());
}

tree.insert("content".to_owned(), self.content.to_json());
tree.insert("cratesfyi_version".to_owned(), ::BUILD_VERSION.to_json());
tree.insert("cratesfyi_version_safe".to_owned(),
Expand Down
1 change: 1 addition & 0 deletions templates/navigation.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<li class="pure-menu-item"><a href="/about" class="pure-menu-link">About Docs.rs</a></li>
</ul>
</li>
{{> navigation_global_alert}}
</ul>
</form>
</div>
Expand Down
9 changes: 9 additions & 0 deletions templates/navigation_global_alert.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{#if ../has_global_alert}}
<li class="pure-menu-item">
<a href="{{../global_alert.url}}" class="pure-menu-link {{../global_alert.css_class}}">
<i class="fa fa-fw fa-{{../global_alert.fa_icon}}"></i>
{{../global_alert.text}}
</a>
</li>
{{/if}}

1 change: 1 addition & 0 deletions templates/navigation_rustdoc.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
</ul>
</li>
{{/with}}
{{> navigation_global_alert}}
</ul>
</form>
</div>
Expand Down
10 changes: 10 additions & 0 deletions templates/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ $color-lifetime-incode: #B76514; // orangish
$color-comment-in-code: #8E908C; // light gray
$color-background-code: #F5F5F5; // lighter gray
$color-border: #ddd; // gray
$color-red: #d93d3d; // red
$top-navbar-height: 32px; // height of the floating top navbar


Expand Down Expand Up @@ -214,6 +215,15 @@ div.nav-container {
color: darken($color-type, 10%);
}

// used for global alerts
.error {
color: $color-red;

&:hover {
color: darken($color-red, 10%);
}
}

div.rustdoc-navigation {
span.title {
display: none;
Expand Down