about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/librustdoc/html/layout.rs14
-rw-r--r--src/librustdoc/html/render.rs19
-rw-r--r--src/test/rustdoc/static-root-path.rs6
3 files changed, 29 insertions, 10 deletions
diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs
index 1ead428ff49..d8a57bc93fd 100644
--- a/src/librustdoc/html/layout.rs
+++ b/src/librustdoc/html/layout.rs
@@ -30,11 +30,13 @@ pub struct Page<'a> {
     pub description: &'a str,
     pub keywords: &'a str,
     pub resource_suffix: &'a str,
+    pub extra_scripts: &'a [&'a str],
+    pub static_extra_scripts: &'a [&'a str],
 }
 
 pub fn render<T: fmt::Display, S: fmt::Display>(
     dst: &mut dyn io::Write, layout: &Layout, page: &Page, sidebar: &S, t: &T,
-    css_file_extension: bool, themes: &[PathBuf], extra_scripts: &[&str])
+    css_file_extension: bool, themes: &[PathBuf])
     -> io::Result<()>
 {
     let static_root_path = page.static_root_path.unwrap_or(page.root_path);
@@ -164,6 +166,7 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
     </script>\
     <script src=\"{root_path}aliases.js\"></script>\
     <script src=\"{static_root_path}main{suffix}.js\"></script>\
+    {static_extra_scripts}\
     {extra_scripts}\
     <script defer src=\"{root_path}search-index.js\"></script>\
 </body>\
@@ -211,9 +214,12 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
                                     page.resource_suffix))
                    .collect::<String>(),
     suffix=page.resource_suffix,
-    // TODO: break out a separate `static_extra_scripts` that uses `static_root_path` instead,
-    // then leave `source-files.js` here and move `source-script.js` to the static version
-    extra_scripts=extra_scripts.iter().map(|e| {
+    static_extra_scripts=page.static_extra_scripts.iter().map(|e| {
+        format!("<script src=\"{static_root_path}{extra_script}.js\"></script>",
+                static_root_path=static_root_path,
+                extra_script=e)
+    }).collect::<String>(),
+    extra_scripts=page.extra_scripts.iter().map(|e| {
         format!("<script src=\"{root_path}{extra_script}.js\"></script>",
                 root_path=page.root_path,
                 extra_script=e)
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index a4e71a18333..d171d747445 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -1089,6 +1089,8 @@ themePicker.onblur = handleThemeButtonsBlur;
                 description: "List of crates",
                 keywords: BASIC_KEYWORDS,
                 resource_suffix: &cx.shared.resource_suffix,
+                extra_scripts: &[],
+                static_extra_scripts: &[],
             };
             krates.push(krate.name.clone());
             krates.sort();
@@ -1107,7 +1109,7 @@ themePicker.onblur = handleThemeButtonsBlur;
             try_err!(layout::render(&mut w, &cx.shared.layout,
                                     &page, &(""), &content,
                                     cx.shared.css_file_extension.is_some(),
-                                    &cx.shared.themes, &[]), &dst);
+                                    &cx.shared.themes), &dst);
             try_err!(w.flush(), &dst);
         }
     }
@@ -1376,12 +1378,13 @@ impl<'a> SourceCollector<'a> {
             description: &desc,
             keywords: BASIC_KEYWORDS,
             resource_suffix: &self.scx.resource_suffix,
+            extra_scripts: &["source-files"],
+            static_extra_scripts: &[&format!("source-script{}", self.scx.resource_suffix)],
         };
         layout::render(&mut w, &self.scx.layout,
                        &page, &(""), &Source(contents),
                        self.scx.css_file_extension.is_some(),
-                       &self.scx.themes, &["source-files",
-                                           &format!("source-script{}", page.resource_suffix)])?;
+                       &self.scx.themes)?;
         w.flush()?;
         self.scx.local_sources.insert(p.clone(), href);
         Ok(())
@@ -1967,6 +1970,8 @@ impl Context {
             description: "List of all items in this crate",
             keywords: BASIC_KEYWORDS,
             resource_suffix: &self.shared.resource_suffix,
+            extra_scripts: &[],
+            static_extra_scripts: &[],
         };
         let sidebar = if let Some(ref version) = cache().crate_version {
             format!("<p class='location'>Crate {}</p>\
@@ -1981,7 +1986,7 @@ impl Context {
         try_err!(layout::render(&mut w, &self.shared.layout,
                                 &page, &sidebar, &all,
                                 self.shared.css_file_extension.is_some(),
-                                &self.shared.themes, &[]),
+                                &self.shared.themes),
                  &final_file);
 
         // Generating settings page.
@@ -2001,7 +2006,7 @@ impl Context {
         try_err!(layout::render(&mut w, &layout,
                                 &page, &sidebar, &settings,
                                 self.shared.css_file_extension.is_some(),
-                                &themes, &[]),
+                                &themes),
                  &settings_file);
 
         Ok(())
@@ -2048,6 +2053,8 @@ impl Context {
             description: &desc,
             keywords: &keywords,
             resource_suffix: &self.shared.resource_suffix,
+            extra_scripts: &[],
+            static_extra_scripts: &[],
         };
 
         {
@@ -2060,7 +2067,7 @@ impl Context {
                            &Sidebar{ cx: self, item: it },
                            &Item{ cx: self, item: it },
                            self.shared.css_file_extension.is_some(),
-                           &self.shared.themes, &[])?;
+                           &self.shared.themes)?;
         } else {
             let mut url = self.root_path();
             if let Some(&(ref names, ty)) = cache().paths.get(&it.def_id) {
diff --git a/src/test/rustdoc/static-root-path.rs b/src/test/rustdoc/static-root-path.rs
index 9307b501585..7df3fee3365 100644
--- a/src/test/rustdoc/static-root-path.rs
+++ b/src/test/rustdoc/static-root-path.rs
@@ -16,3 +16,9 @@
 // @matches - '"\.\./search-index\.js"'
 // @!matches - '"/cache/search-index\.js"'
 pub struct SomeStruct;
+
+// @has src/static_root_path/static-root-path.rs.html
+// @matches - '"/cache/source-script\.js"'
+// @!matches - '"\.\./\.\./source-script\.js"'
+// @matches - '"\.\./\.\./source-files.js"'
+// @!matches - '"/cache/source-files\.js"'