Skip to content

Commit 57243b7

Browse files
Move constant parameters to render to Layout struct
1 parent 3657bfc commit 57243b7

File tree

3 files changed

+16
-29
lines changed

3 files changed

+16
-29
lines changed

src/librustdoc/html/layout.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ pub struct Layout {
1111
pub favicon: String,
1212
pub external_html: ExternalHtml,
1313
pub krate: String,
14+
/// The given user css file which allow to customize the generated
15+
/// documentation theme.
16+
pub css_file_extension: Option<PathBuf>,
17+
/// If false, the `select` element to have search filtering by crates on rendered docs
18+
/// won't be generated.
19+
pub generate_search_filter: bool,
1420
}
1521

1622
pub struct Page<'a> {
@@ -30,9 +36,7 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
3036
page: &Page<'_>,
3137
sidebar: &S,
3238
t: &T,
33-
css_file_extension: bool,
3439
themes: &[PathBuf],
35-
generate_search_filter: bool,
3640
) -> String {
3741
let mut dst = Buffer::html();
3842
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>(
164168
<script defer src=\"{root_path}search-index{suffix}.js\"></script>\
165169
</body>\
166170
</html>",
167-
css_extension = if css_file_extension {
171+
css_extension = if layout.css_file_extension.is_some() {
168172
format!("<link rel=\"stylesheet\" \
169173
type=\"text/css\" \
170174
href=\"{static_root_path}theme{suffix}.css\">",
@@ -228,7 +232,7 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
228232
root_path=page.root_path,
229233
extra_script=e)
230234
}).collect::<String>(),
231-
filter_crates=if generate_search_filter {
235+
filter_crates=if layout.generate_search_filter {
232236
"<select id=\"crate-search\">\
233237
<option value=\"All crates\">All crates</option>\
234238
</select>"

src/librustdoc/html/render.rs

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,6 @@ crate struct SharedContext {
192192
/// The base-URL of the issue tracker for when an item has been tagged with
193193
/// an issue number.
194194
pub issue_tracker_base_url: Option<String>,
195-
/// The given user css file which allow to customize the generated
196-
/// documentation theme.
197-
pub css_file_extension: Option<PathBuf>,
198195
/// The directories that have already been created in this doc run. Used to reduce the number
199196
/// of spurious `create_dir_all` calls.
200197
pub created_dirs: RefCell<FxHashSet<PathBuf>>,
@@ -209,9 +206,6 @@ crate struct SharedContext {
209206
/// Optional path string to be used to load static files on output pages. If not set, uses
210207
/// combinations of `../` to reach the documentation root.
211208
pub static_root_path: Option<String>,
212-
/// If false, the `select` element to have search filtering by crates on rendered docs
213-
/// won't be generated.
214-
pub generate_search_filter: bool,
215209
/// Option disabled by default to generate files used by RLS and some other tools.
216210
pub generate_redirect_pages: bool,
217211
/// The fs handle we are working with.
@@ -545,14 +539,14 @@ pub fn run(mut krate: clean::Crate,
545539
favicon: String::new(),
546540
external_html,
547541
krate: krate.name.clone(),
542+
css_file_extension: extension_css,
543+
generate_search_filter,
548544
},
549-
css_file_extension: extension_css,
550545
created_dirs: Default::default(),
551546
sort_modules_alphabetically,
552547
themes,
553548
resource_suffix,
554549
static_root_path,
555-
generate_search_filter,
556550
generate_redirect_pages,
557551
fs: DocFS::new(&errors),
558552
};
@@ -932,7 +926,7 @@ themePicker.onblur = handleThemeButtonsBlur;
932926
options.enable_minification)?;
933927
}
934928

935-
if let Some(ref css) = cx.shared.css_file_extension {
929+
if let Some(ref css) = cx.shared.layout.css_file_extension {
936930
let out = cx.dst.join(&format!("theme{}.css", cx.shared.resource_suffix));
937931
let buffer = try_err!(fs::read_to_string(css), css);
938932
if !options.enable_minification {
@@ -1187,9 +1181,7 @@ themePicker.onblur = handleThemeButtonsBlur;
11871181
.collect::<String>());
11881182
let v = layout::render(&cx.shared.layout,
11891183
&page, &(""), &content,
1190-
cx.shared.css_file_extension.is_some(),
1191-
&cx.shared.themes,
1192-
cx.shared.generate_search_filter);
1184+
&cx.shared.themes);
11931185
cx.shared.fs.write(&dst, v.as_bytes())?;
11941186
}
11951187
}
@@ -1940,9 +1932,7 @@ impl Context {
19401932
};
19411933
let v = layout::render(&self.shared.layout,
19421934
&page, &sidebar, &all,
1943-
self.shared.css_file_extension.is_some(),
1944-
&self.shared.themes,
1945-
self.shared.generate_search_filter);
1935+
&self.shared.themes);
19461936
self.shared.fs.write(&final_file, v.as_bytes())?;
19471937

19481938
// Generating settings page.
@@ -1958,10 +1948,7 @@ impl Context {
19581948
let v = layout::render(
19591949
&self.shared.layout,
19601950
&page, &sidebar, &settings,
1961-
self.shared.css_file_extension.is_some(),
1962-
&themes,
1963-
self.shared.generate_search_filter,
1964-
);
1951+
&themes);
19651952
self.shared.fs.write(&settings_file, v.as_bytes())?;
19661953

19671954
Ok(())
@@ -2019,9 +2006,7 @@ impl Context {
20192006
layout::render(&self.shared.layout, &page,
20202007
&Sidebar{ cx: self, item: it },
20212008
&Item{ cx: self, item: it },
2022-
self.shared.css_file_extension.is_some(),
2023-
&self.shared.themes,
2024-
self.shared.generate_search_filter)
2009+
&self.shared.themes)
20252010
} else {
20262011
let mut url = self.root_path();
20272012
if let Some(&(ref names, ty)) = cache().paths.get(&it.def_id) {

src/librustdoc/html/sources.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,7 @@ impl<'a> SourceCollector<'a> {
121121
};
122122
let v = layout::render(&self.scx.layout,
123123
&page, &(""), &Source(contents),
124-
self.scx.css_file_extension.is_some(),
125-
&self.scx.themes,
126-
self.scx.generate_search_filter);
124+
&self.scx.themes);
127125
self.scx.fs.write(&cur, v.as_bytes())?;
128126
self.scx.local_sources.insert(p.clone(), href);
129127
Ok(())

0 commit comments

Comments
 (0)