Move constant parameters to render to Layout struct
This commit is contained in:
parent
3657bfc040
commit
57243b74b1
3 changed files with 16 additions and 29 deletions
|
@ -11,6 +11,12 @@ pub struct Layout {
|
||||||
pub favicon: String,
|
pub favicon: String,
|
||||||
pub external_html: ExternalHtml,
|
pub external_html: ExternalHtml,
|
||||||
pub krate: String,
|
pub krate: String,
|
||||||
|
/// The given user css file which allow to customize the generated
|
||||||
|
/// documentation theme.
|
||||||
|
pub css_file_extension: Option<PathBuf>,
|
||||||
|
/// If false, the `select` element to have search filtering by crates on rendered docs
|
||||||
|
/// won't be generated.
|
||||||
|
pub generate_search_filter: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Page<'a> {
|
pub struct Page<'a> {
|
||||||
|
@ -30,9 +36,7 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
|
||||||
page: &Page<'_>,
|
page: &Page<'_>,
|
||||||
sidebar: &S,
|
sidebar: &S,
|
||||||
t: &T,
|
t: &T,
|
||||||
css_file_extension: bool,
|
|
||||||
themes: &[PathBuf],
|
themes: &[PathBuf],
|
||||||
generate_search_filter: bool,
|
|
||||||
) -> String {
|
) -> String {
|
||||||
let mut dst = Buffer::html();
|
let mut dst = Buffer::html();
|
||||||
let static_root_path = page.static_root_path.unwrap_or(page.root_path);
|
let static_root_path = page.static_root_path.unwrap_or(page.root_path);
|
||||||
|
@ -164,7 +168,7 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
|
||||||
<script defer src=\"{root_path}search-index{suffix}.js\"></script>\
|
<script defer src=\"{root_path}search-index{suffix}.js\"></script>\
|
||||||
</body>\
|
</body>\
|
||||||
</html>",
|
</html>",
|
||||||
css_extension = if css_file_extension {
|
css_extension = if layout.css_file_extension.is_some() {
|
||||||
format!("<link rel=\"stylesheet\" \
|
format!("<link rel=\"stylesheet\" \
|
||||||
type=\"text/css\" \
|
type=\"text/css\" \
|
||||||
href=\"{static_root_path}theme{suffix}.css\">",
|
href=\"{static_root_path}theme{suffix}.css\">",
|
||||||
|
@ -228,7 +232,7 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
|
||||||
root_path=page.root_path,
|
root_path=page.root_path,
|
||||||
extra_script=e)
|
extra_script=e)
|
||||||
}).collect::<String>(),
|
}).collect::<String>(),
|
||||||
filter_crates=if generate_search_filter {
|
filter_crates=if layout.generate_search_filter {
|
||||||
"<select id=\"crate-search\">\
|
"<select id=\"crate-search\">\
|
||||||
<option value=\"All crates\">All crates</option>\
|
<option value=\"All crates\">All crates</option>\
|
||||||
</select>"
|
</select>"
|
||||||
|
|
|
@ -192,9 +192,6 @@ crate struct SharedContext {
|
||||||
/// The base-URL of the issue tracker for when an item has been tagged with
|
/// The base-URL of the issue tracker for when an item has been tagged with
|
||||||
/// an issue number.
|
/// an issue number.
|
||||||
pub issue_tracker_base_url: Option<String>,
|
pub issue_tracker_base_url: Option<String>,
|
||||||
/// The given user css file which allow to customize the generated
|
|
||||||
/// documentation theme.
|
|
||||||
pub css_file_extension: Option<PathBuf>,
|
|
||||||
/// The directories that have already been created in this doc run. Used to reduce the number
|
/// The directories that have already been created in this doc run. Used to reduce the number
|
||||||
/// of spurious `create_dir_all` calls.
|
/// of spurious `create_dir_all` calls.
|
||||||
pub created_dirs: RefCell<FxHashSet<PathBuf>>,
|
pub created_dirs: RefCell<FxHashSet<PathBuf>>,
|
||||||
|
@ -209,9 +206,6 @@ crate struct SharedContext {
|
||||||
/// Optional path string to be used to load static files on output pages. If not set, uses
|
/// Optional path string to be used to load static files on output pages. If not set, uses
|
||||||
/// combinations of `../` to reach the documentation root.
|
/// combinations of `../` to reach the documentation root.
|
||||||
pub static_root_path: Option<String>,
|
pub static_root_path: Option<String>,
|
||||||
/// If false, the `select` element to have search filtering by crates on rendered docs
|
|
||||||
/// won't be generated.
|
|
||||||
pub generate_search_filter: bool,
|
|
||||||
/// Option disabled by default to generate files used by RLS and some other tools.
|
/// Option disabled by default to generate files used by RLS and some other tools.
|
||||||
pub generate_redirect_pages: bool,
|
pub generate_redirect_pages: bool,
|
||||||
/// The fs handle we are working with.
|
/// The fs handle we are working with.
|
||||||
|
@ -545,14 +539,14 @@ pub fn run(mut krate: clean::Crate,
|
||||||
favicon: String::new(),
|
favicon: String::new(),
|
||||||
external_html,
|
external_html,
|
||||||
krate: krate.name.clone(),
|
krate: krate.name.clone(),
|
||||||
|
css_file_extension: extension_css,
|
||||||
|
generate_search_filter,
|
||||||
},
|
},
|
||||||
css_file_extension: extension_css,
|
|
||||||
created_dirs: Default::default(),
|
created_dirs: Default::default(),
|
||||||
sort_modules_alphabetically,
|
sort_modules_alphabetically,
|
||||||
themes,
|
themes,
|
||||||
resource_suffix,
|
resource_suffix,
|
||||||
static_root_path,
|
static_root_path,
|
||||||
generate_search_filter,
|
|
||||||
generate_redirect_pages,
|
generate_redirect_pages,
|
||||||
fs: DocFS::new(&errors),
|
fs: DocFS::new(&errors),
|
||||||
};
|
};
|
||||||
|
@ -932,7 +926,7 @@ themePicker.onblur = handleThemeButtonsBlur;
|
||||||
options.enable_minification)?;
|
options.enable_minification)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ref css) = cx.shared.css_file_extension {
|
if let Some(ref css) = cx.shared.layout.css_file_extension {
|
||||||
let out = cx.dst.join(&format!("theme{}.css", cx.shared.resource_suffix));
|
let out = cx.dst.join(&format!("theme{}.css", cx.shared.resource_suffix));
|
||||||
let buffer = try_err!(fs::read_to_string(css), css);
|
let buffer = try_err!(fs::read_to_string(css), css);
|
||||||
if !options.enable_minification {
|
if !options.enable_minification {
|
||||||
|
@ -1187,9 +1181,7 @@ themePicker.onblur = handleThemeButtonsBlur;
|
||||||
.collect::<String>());
|
.collect::<String>());
|
||||||
let v = layout::render(&cx.shared.layout,
|
let v = layout::render(&cx.shared.layout,
|
||||||
&page, &(""), &content,
|
&page, &(""), &content,
|
||||||
cx.shared.css_file_extension.is_some(),
|
&cx.shared.themes);
|
||||||
&cx.shared.themes,
|
|
||||||
cx.shared.generate_search_filter);
|
|
||||||
cx.shared.fs.write(&dst, v.as_bytes())?;
|
cx.shared.fs.write(&dst, v.as_bytes())?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1940,9 +1932,7 @@ impl Context {
|
||||||
};
|
};
|
||||||
let v = layout::render(&self.shared.layout,
|
let v = layout::render(&self.shared.layout,
|
||||||
&page, &sidebar, &all,
|
&page, &sidebar, &all,
|
||||||
self.shared.css_file_extension.is_some(),
|
&self.shared.themes);
|
||||||
&self.shared.themes,
|
|
||||||
self.shared.generate_search_filter);
|
|
||||||
self.shared.fs.write(&final_file, v.as_bytes())?;
|
self.shared.fs.write(&final_file, v.as_bytes())?;
|
||||||
|
|
||||||
// Generating settings page.
|
// Generating settings page.
|
||||||
|
@ -1958,10 +1948,7 @@ impl Context {
|
||||||
let v = layout::render(
|
let v = layout::render(
|
||||||
&self.shared.layout,
|
&self.shared.layout,
|
||||||
&page, &sidebar, &settings,
|
&page, &sidebar, &settings,
|
||||||
self.shared.css_file_extension.is_some(),
|
&themes);
|
||||||
&themes,
|
|
||||||
self.shared.generate_search_filter,
|
|
||||||
);
|
|
||||||
self.shared.fs.write(&settings_file, v.as_bytes())?;
|
self.shared.fs.write(&settings_file, v.as_bytes())?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -2019,9 +2006,7 @@ impl Context {
|
||||||
layout::render(&self.shared.layout, &page,
|
layout::render(&self.shared.layout, &page,
|
||||||
&Sidebar{ cx: self, item: it },
|
&Sidebar{ cx: self, item: it },
|
||||||
&Item{ cx: self, item: it },
|
&Item{ cx: self, item: it },
|
||||||
self.shared.css_file_extension.is_some(),
|
&self.shared.themes)
|
||||||
&self.shared.themes,
|
|
||||||
self.shared.generate_search_filter)
|
|
||||||
} else {
|
} else {
|
||||||
let mut url = self.root_path();
|
let mut url = self.root_path();
|
||||||
if let Some(&(ref names, ty)) = cache().paths.get(&it.def_id) {
|
if let Some(&(ref names, ty)) = cache().paths.get(&it.def_id) {
|
||||||
|
|
|
@ -121,9 +121,7 @@ impl<'a> SourceCollector<'a> {
|
||||||
};
|
};
|
||||||
let v = layout::render(&self.scx.layout,
|
let v = layout::render(&self.scx.layout,
|
||||||
&page, &(""), &Source(contents),
|
&page, &(""), &Source(contents),
|
||||||
self.scx.css_file_extension.is_some(),
|
&self.scx.themes);
|
||||||
&self.scx.themes,
|
|
||||||
self.scx.generate_search_filter);
|
|
||||||
self.scx.fs.write(&cur, v.as_bytes())?;
|
self.scx.fs.write(&cur, v.as_bytes())?;
|
||||||
self.scx.local_sources.insert(p.clone(), href);
|
self.scx.local_sources.insert(p.clone(), href);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Add table
Reference in a new issue