1
Fork 0

Rollup merge of #58028 - GuillaumeGomez:fix-settings-image-link, r=QuietMisdreavus

Fix image link in the settings menu

Fixes #57892.

r? @QuietMisdreavus
This commit is contained in:
Guillaume Gomez 2019-02-07 14:28:33 +01:00 committed by GitHub
commit 1a99a32bd7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 15 deletions

View file

@ -4,6 +4,8 @@ use std::path::PathBuf;
use externalfiles::ExternalHtml; use externalfiles::ExternalHtml;
use html::render::SlashChecker;
#[derive(Clone)] #[derive(Clone)]
pub struct Layout { pub struct Layout {
pub logo: String, pub logo: String,
@ -176,16 +178,22 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
static_root_path = static_root_path, static_root_path = static_root_path,
root_path = page.root_path, root_path = page.root_path,
css_class = page.css_class, css_class = page.css_class,
logo = if layout.logo.is_empty() { logo = {
format!("<a href='{}{}/index.html'>\ let p = format!("{}{}", page.root_path, layout.krate);
<img src='{static_root_path}rust-logo{suffix}.png' alt='logo' width='100'></a>", let p = SlashChecker(&p);
static_root_path=static_root_path, if layout.logo.is_empty() {
suffix=page.resource_suffix) format!("<a href='{path}index.html'>\
} else { <img src='{static_root_path}rust-logo{suffix}.png' \
format!("<a href='{}{}/index.html'>\ alt='logo' width='100'></a>",
<img src='{}' alt='logo' width='100'></a>", path=p,
page.root_path, layout.krate, static_root_path=static_root_path,
layout.logo) suffix=page.resource_suffix)
} else {
format!("<a href='{}index.html'>\
<img src='{}' alt='logo' width='100'></a>",
p,
layout.logo)
}
}, },
title = page.title, title = page.title,
description = page.description, description = page.description,

View file

@ -73,6 +73,18 @@ use minifier;
/// A pair of name and its optional document. /// A pair of name and its optional document.
pub type NameDoc = (String, Option<String>); pub type NameDoc = (String, Option<String>);
pub struct SlashChecker<'a>(pub &'a str);
impl<'a> Display for SlashChecker<'a> {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
if !self.0.ends_with("/") && !self.0.is_empty() {
write!(f, "{}/", self.0)
} else {
write!(f, "{}", self.0)
}
}
}
/// Major driving force in all rustdoc rendering. This contains information /// Major driving force in all rustdoc rendering. This contains information
/// about where in the tree-like hierarchy rendering is occurring and controls /// about where in the tree-like hierarchy rendering is occurring and controls
/// how the current page is being rendered. /// how the current page is being rendered.
@ -1140,7 +1152,8 @@ themePicker.onblur = handleThemeButtonsBlur;
krates krates
.iter() .iter()
.map(|s| { .map(|s| {
format!("<li><a href=\"{}/index.html\">{}</li>", s, s) format!("<li><a href=\"{}index.html\">{}</li>",
SlashChecker(s), s)
}) })
.collect::<String>()); .collect::<String>());
try_err!(layout::render(&mut w, &cx.shared.layout, try_err!(layout::render(&mut w, &cx.shared.layout,
@ -2075,8 +2088,7 @@ impl Context {
let mut themes = self.shared.themes.clone(); let mut themes = self.shared.themes.clone();
let sidebar = "<p class='location'>Settings</p><div class='sidebar-elems'></div>"; let sidebar = "<p class='location'>Settings</p><div class='sidebar-elems'></div>";
themes.push(PathBuf::from("settings.css")); themes.push(PathBuf::from("settings.css"));
let mut layout = self.shared.layout.clone(); let layout = self.shared.layout.clone();
layout.krate = String::new();
try_err!(layout::render(&mut w, &layout, try_err!(layout::render(&mut w, &layout,
&page, &sidebar, &settings, &page, &sidebar, &settings,
self.shared.css_file_extension.is_some(), self.shared.css_file_extension.is_some(),
@ -2455,7 +2467,7 @@ impl<'a> fmt::Display for Item<'a> {
fn item_path(ty: ItemType, name: &str) -> String { fn item_path(ty: ItemType, name: &str) -> String {
match ty { match ty {
ItemType::Module => format!("{}/index.html", name), ItemType::Module => format!("{}index.html", SlashChecker(name)),
_ => format!("{}.{}.html", ty.css_class(), name), _ => format!("{}.{}.html", ty.css_class(), name),
} }
} }

View file

@ -7,7 +7,7 @@
// @has foo/keyword.match.html '//a[@class="keyword"]' 'match' // @has foo/keyword.match.html '//a[@class="keyword"]' 'match'
// @has foo/keyword.match.html '//span[@class="in-band"]' 'Keyword match' // @has foo/keyword.match.html '//span[@class="in-band"]' 'Keyword match'
// @has foo/keyword.match.html '//section[@id="main"]//div[@class="docblock"]//p' 'this is a test!' // @has foo/keyword.match.html '//section[@id="main"]//div[@class="docblock"]//p' 'this is a test!'
// @!has foo/index.html '//a/@href' 'foo/index.html' // @has foo/index.html '//a/@href' '../foo/index.html'
// @!has foo/foo/index.html // @!has foo/foo/index.html
// @!has-dir foo/foo // @!has-dir foo/foo
#[doc(keyword = "match")] #[doc(keyword = "match")]