Skip to content

Commit

Permalink
Fasten even more theme switch
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Jan 22, 2018
1 parent 5f93159 commit 5b85044
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
13 changes: 11 additions & 2 deletions src/librustdoc/html/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use std::fmt;
use std::io;
use std::path::PathBuf;

use externalfiles::ExternalHtml;

Expand All @@ -31,7 +32,7 @@ pub struct Page<'a> {

pub fn render<T: fmt::Display, S: fmt::Display>(
dst: &mut io::Write, layout: &Layout, page: &Page, sidebar: &S, t: &T,
css_file_extension: bool)
css_file_extension: bool, themes: &[PathBuf])
-> io::Result<()>
{
write!(dst,
Expand All @@ -48,7 +49,9 @@ r##"<!DOCTYPE html>
<link rel="stylesheet" type="text/css" href="{root_path}normalize.css">
<link rel="stylesheet" type="text/css" href="{root_path}rustdoc.css" id="mainThemeStyle">
<link rel="stylesheet" type="text/css" href="" id="themeStyle">
{themes}
<link rel="stylesheet" type="text/css" href="{root_path}dark.css">
<link rel="stylesheet" type="text/css" href="{root_path}main.css" id="themeStyle">
<script src="{root_path}storage.js"></script>
{css_extension}
Expand Down Expand Up @@ -182,6 +185,12 @@ r##"<!DOCTYPE html>
after_content = layout.external_html.after_content,
sidebar = *sidebar,
krate = layout.krate,
themes = themes.iter()
.filter_map(|t| t.file_stem())
.filter_map(|t| t.to_str())
.map(|t| format!(r#"<link rel="stylesheet" type="text/css" href="{}{}">"#,
page.root_path, t))
.collect::<String>(),
)
}

Expand Down
6 changes: 4 additions & 2 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,8 @@ impl<'a> SourceCollector<'a> {
};
layout::render(&mut w, &self.scx.layout,
&page, &(""), &Source(contents),
self.scx.css_file_extension.is_some())?;
self.scx.css_file_extension.is_some(),
&self.scx.themes)?;
w.flush()?;
self.scx.local_sources.insert(p.clone(), href);
Ok(())
Expand Down Expand Up @@ -1588,7 +1589,8 @@ impl Context {
layout::render(writer, &self.shared.layout, &page,
&Sidebar{ cx: self, item: it },
&Item{ cx: self, item: it },
self.shared.css_file_extension.is_some())?;
self.shared.css_file_extension.is_some(),
&self.shared.themes)?;
} else {
let mut url = self.root_path();
if let Some(&(ref names, ty)) = cache().paths.get(&it.def_id) {
Expand Down
8 changes: 0 additions & 8 deletions src/librustdoc/html/static/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ function getCurrentValue(name) {
function switchTheme(styleElem, mainStyleElem, newTheme) {
styleElem.href = mainStyleElem.href.replace("rustdoc.css", newTheme + ".css");
updateLocalStorage('theme', newTheme);
/*var elem = document.getElementsByTagName('body')[0];
if (elem) {
updateLocalStorage('background', getComputedStyle(elem)['background-color']);
}*/
}

/*var elem = document.getElementsByTagName('body')[0];
if (elem) {
var value =
}*/
switchTheme(currentTheme, mainTheme, getCurrentValue('theme') || 'main');

0 comments on commit 5b85044

Please sign in to comment.