]> git.lizzy.rs Git - rust.git/commitdiff
Fix image link in the settings menu
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Thu, 31 Jan 2019 14:42:45 +0000 (15:42 +0100)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Fri, 1 Feb 2019 10:27:59 +0000 (11:27 +0100)
src/librustdoc/html/layout.rs
src/librustdoc/html/render.rs
src/test/rustdoc/keyword.rs

index c34dcbbb672e9b8753d784dbe9687171faed258f..b444993c1b5ecd9f153492c5a2058248c2fe6d93 100644 (file)
@@ -4,6 +4,8 @@
 
 use externalfiles::ExternalHtml;
 
+use html::render::SlashChecker;
+
 #[derive(Clone)]
 pub struct Layout {
     pub logo: String,
@@ -176,16 +178,22 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
     static_root_path = static_root_path,
     root_path = page.root_path,
     css_class = page.css_class,
-    logo      = if layout.logo.is_empty() {
-        format!("<a href='{}{}/index.html'>\
-                 <img src='{static_root_path}rust-logo{suffix}.png' alt='logo' width='100'></a>",
-                static_root_path=static_root_path,
-                suffix=page.resource_suffix)
-    } else {
-        format!("<a href='{}{}/index.html'>\
-                 <img src='{}' alt='logo' width='100'></a>",
-                page.root_path, layout.krate,
-                layout.logo)
+    logo      = {
+        let p = format!("{}{}", page.root_path, layout.krate);
+        let p = SlashChecker(&p);
+        if layout.logo.is_empty() {
+            format!("<a href='{path}index.html'>\
+                     <img src='{static_root_path}rust-logo{suffix}.png' \
+                          alt='logo' width='100'></a>",
+                    path=p,
+                    static_root_path=static_root_path,
+                    suffix=page.resource_suffix)
+        } else {
+            format!("<a href='{}index.html'>\
+                     <img src='{}' alt='logo' width='100'></a>",
+                    p,
+                    layout.logo)
+        }
     },
     title     = page.title,
     description = page.description,
index 86fb51419c270a581d9bff2a6a5d931831d26075..f2bd56978c28778f22062d52acdde0c8f51ada13 100644 (file)
 /// A pair of name and its optional document.
 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
 /// about where in the tree-like hierarchy rendering is occurring and controls
 /// how the current page is being rendered.
@@ -1140,7 +1152,8 @@ fn to_json_string(&self) -> String {
                                   krates
                                     .iter()
                                     .map(|s| {
-                                        format!("<li><a href=\"{}/index.html\">{}</li>", s, s)
+                                        format!("<li><a href=\"{}index.html\">{}</li>",
+                                                SlashChecker(s), s)
                                     })
                                     .collect::<String>());
             try_err!(layout::render(&mut w, &cx.shared.layout,
@@ -2074,8 +2087,7 @@ fn krate(self, mut krate: clean::Crate) -> Result<(), Error> {
         let mut themes = self.shared.themes.clone();
         let sidebar = "<p class='location'>Settings</p><div class='sidebar-elems'></div>";
         themes.push(PathBuf::from("settings.css"));
-        let mut layout = self.shared.layout.clone();
-        layout.krate = String::new();
+        let layout = self.shared.layout.clone();
         try_err!(layout::render(&mut w, &layout,
                                 &page, &sidebar, &settings,
                                 self.shared.css_file_extension.is_some(),
@@ -2454,7 +2466,7 @@ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
 
 fn item_path(ty: ItemType, name: &str) -> String {
     match ty {
-        ItemType::Module => format!("{}/index.html", name),
+        ItemType::Module => format!("{}index.html", SlashChecker(name)),
         _ => format!("{}.{}.html", ty.css_class(), name),
     }
 }
index d3327ae7ae11775b10987c526067d0c29585f8c2..c721c024468ddf2b75e8ee6b608b9217eba9ecad 100644 (file)
@@ -7,7 +7,7 @@
 // @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 '//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-dir foo/foo
 #[doc(keyword = "match")]