Settings to function
This commit is contained in:
parent
bb40d5fa49
commit
17bef30d0b
1 changed files with 19 additions and 36 deletions
|
@ -1801,18 +1801,9 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
fn settings(root_path: &str, suffix: &str) -> String {
|
||||||
struct Settings<'a> {
|
|
||||||
// (id, explanation, default value)
|
// (id, explanation, default value)
|
||||||
settings: Vec<(&'static str, &'static str, bool)>,
|
let settings = [
|
||||||
root_path: &'a str,
|
|
||||||
suffix: &'a str,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Settings<'a> {
|
|
||||||
pub fn new(root_path: &'a str, suffix: &'a str) -> Settings<'a> {
|
|
||||||
Settings {
|
|
||||||
settings: vec![
|
|
||||||
("item-declarations", "Auto-hide item declarations.", true),
|
("item-declarations", "Auto-hide item declarations.", true),
|
||||||
("item-attributes", "Auto-hide item attributes.", true),
|
("item-attributes", "Auto-hide item attributes.", true),
|
||||||
("trait-implementations", "Auto-hide trait implementations documentation",
|
("trait-implementations", "Auto-hide trait implementations documentation",
|
||||||
|
@ -1821,22 +1812,14 @@ impl<'a> Settings<'a> {
|
||||||
("go-to-only-result", "Directly go to item in search if there is only one result",
|
("go-to-only-result", "Directly go to item in search if there is only one result",
|
||||||
false),
|
false),
|
||||||
("line-numbers", "Show line numbers on code examples", false),
|
("line-numbers", "Show line numbers on code examples", false),
|
||||||
],
|
];
|
||||||
root_path,
|
format!(
|
||||||
suffix,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> fmt::Display for Settings<'a> {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
write!(f,
|
|
||||||
"<h1 class='fqn'>\
|
"<h1 class='fqn'>\
|
||||||
<span class='in-band'>Rustdoc settings</span>\
|
<span class='in-band'>Rustdoc settings</span>\
|
||||||
</h1>\
|
</h1>\
|
||||||
<div class='settings'>{}</div>\
|
<div class='settings'>{}</div>\
|
||||||
<script src='{}settings{}.js'></script>",
|
<script src='{}settings{}.js'></script>",
|
||||||
self.settings.iter()
|
settings.iter()
|
||||||
.map(|(id, text, enabled)| {
|
.map(|(id, text, enabled)| {
|
||||||
format!("<div class='setting-line'>\
|
format!("<div class='setting-line'>\
|
||||||
<label class='toggle'>\
|
<label class='toggle'>\
|
||||||
|
@ -1847,9 +1830,8 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
</div>", id, if *enabled { " checked" } else { "" }, text)
|
</div>", id, if *enabled { " checked" } else { "" }, text)
|
||||||
})
|
})
|
||||||
.collect::<String>(),
|
.collect::<String>(),
|
||||||
self.root_path,
|
root_path,
|
||||||
self.suffix)
|
suffix)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Context {
|
impl Context {
|
||||||
|
@ -1924,8 +1906,6 @@ impl Context {
|
||||||
self.shared.fs.write(&final_file, v.as_bytes())?;
|
self.shared.fs.write(&final_file, v.as_bytes())?;
|
||||||
|
|
||||||
// Generating settings page.
|
// Generating settings page.
|
||||||
let settings = Settings::new(self.shared.static_root_path.as_deref().unwrap_or("./"),
|
|
||||||
&self.shared.resource_suffix);
|
|
||||||
page.title = "Rustdoc settings";
|
page.title = "Rustdoc settings";
|
||||||
page.description = "Settings of Rustdoc";
|
page.description = "Settings of Rustdoc";
|
||||||
page.root_path = "./";
|
page.root_path = "./";
|
||||||
|
@ -1935,7 +1915,10 @@ impl Context {
|
||||||
themes.push(PathBuf::from("settings.css"));
|
themes.push(PathBuf::from("settings.css"));
|
||||||
let v = layout::render(
|
let v = layout::render(
|
||||||
&self.shared.layout,
|
&self.shared.layout,
|
||||||
&page, sidebar, |buf: &mut Buffer| buf.from_display(settings),
|
&page, sidebar, settings(
|
||||||
|
self.shared.static_root_path.as_deref().unwrap_or("./"),
|
||||||
|
&self.shared.resource_suffix
|
||||||
|
),
|
||||||
&themes);
|
&themes);
|
||||||
self.shared.fs.write(&settings_file, v.as_bytes())?;
|
self.shared.fs.write(&settings_file, v.as_bytes())?;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue