1
Fork 0

split off a separate RenderOptions struct

This commit is contained in:
QuietMisdreavus 2018-10-30 10:53:46 -05:00
parent 157833c588
commit 4d6c2765e6
3 changed files with 67 additions and 49 deletions

View file

@ -32,14 +32,13 @@ use opts;
use passes::{self, DefaultPassOption};
use theme;
/// Configuration options for rustdoc.
#[derive(Clone)]
pub struct Options {
// Basic options / Options passed directly to rustc
/// The crate root or Markdown file to load.
pub input: PathBuf,
/// Output directory to generate docs into. Defaults to `doc`.
pub output: PathBuf,
/// The name of the crate being documented.
pub crate_name: Option<String>,
/// How to format errors and warnings.
@ -91,20 +90,29 @@ pub struct Options {
/// Whether to display warnings during doc generation or while gathering doctests. By default,
/// all non-rustdoc-specific lints are allowed when generating docs.
pub display_warnings: bool,
/// A pre-populated `IdMap` with the default headings and any headings added by Markdown files
/// processed by `external_html`.
pub id_map: IdMap,
// Options that alter generated documentation pages
/// Crate version to note on the sidebar of generated docs.
pub crate_version: Option<String>,
/// Collected options specific to outputting final pages.
pub render_options: RenderOptions,
}
/// Configuration options for the HTML page-creation process.
#[derive(Clone)]
pub struct RenderOptions {
/// Output directory to generate docs into. Defaults to `doc`.
pub output: PathBuf,
/// External files to insert into generated pages.
pub external_html: ExternalHtml,
/// A pre-populated `IdMap` with the default headings and any headings added by Markdown files
/// processed by `external_html`.
pub id_map: IdMap,
/// If present, playground URL to use in the "Run" button added to code samples.
///
/// Be aware: This option can come both from the CLI and from crate attributes!
pub playground_url: Option<String>,
/// Crate version to note on the sidebar of generated docs.
pub crate_version: Option<String>,
/// Whether to sort modules alphabetically on a module page instead of using declaration order.
/// `true` by default.
///
@ -390,7 +398,6 @@ impl Options {
Ok(Options {
input,
output,
crate_name,
error_format,
libs,
@ -410,10 +417,12 @@ impl Options {
default_passes,
manual_passes,
display_warnings,
id_map,
external_html,
playground_url,
crate_version,
render_options: RenderOptions {
output,
external_html,
id_map,
playground_url,
sort_modules_alphabetically,
themes,
extension_css,
@ -425,6 +434,7 @@ impl Options {
markdown_no_toc,
markdown_css,
markdown_playground_url,
}
})
}

View file

@ -509,7 +509,7 @@ pub fn run(mut krate: clean::Crate,
id_map: IdMap,
enable_index_page: bool,
index_page: Option<PathBuf>,
options: config::Options,
options: config::RenderOptions,
diag: &errors::Handler,
) -> Result<(), Error> {
let src_root = match krate.src {
@ -760,7 +760,7 @@ fn write_shared(
cache: &Cache,
search_index: String,
enable_minification: bool,
options: &config::Options,
options: &config::RenderOptions,
diag: &errors::Handler,
) -> Result<(), Error> {
// Write out the shared files. Note that these are shared among all rustdoc

View file

@ -90,6 +90,7 @@ mod theme;
struct Output {
krate: clean::Crate,
renderinfo: html::render::RenderInfo,
renderopts: config::RenderOptions,
passes: Vec<String>,
}
@ -381,36 +382,38 @@ fn main_args(args: &[String]) -> isize {
options.display_warnings, options.linker, options.edition,
options.codegen_options)
}
(false, true) => return markdown::render(&options.input, options.output,
&options.markdown_css,
options.markdown_playground_url
.or(options.playground_url),
&options.external_html,
!options.markdown_no_toc, &diag),
(false, true) => return markdown::render(&options.input, options.render_options.output,
&options.render_options.markdown_css,
options.render_options.markdown_playground_url
.or(options.render_options.playground_url),
&options.render_options.external_html,
!options.render_options.markdown_no_toc, &diag),
(false, false) => {}
}
//TODO: split render-time options into their own struct so i don't have to clone here
rust_input(options.clone(), move |out| {
let Output { krate, passes, renderinfo } = out;
info!("going to format");
let diag = core::new_handler(options.error_format,
None,
// need to move these items separately because we lose them by the time the closure is called,
// but we can't crates the Handler ahead of time because it's not Send
let diag_opts = (options.error_format,
options.debugging_options.treat_err_as_bug,
options.debugging_options.ui_testing);
let html_opts = options.clone();
html::render::run(krate, options.extern_html_root_urls, &options.external_html, options.playground_url,
options.output,
options.resource_suffix,
rust_input(options, move |out| {
let Output { krate, passes, renderinfo, renderopts } = out;
info!("going to format");
let (error_format, treat_err_as_bug, ui_testing) = diag_opts;
let diag = core::new_handler(error_format, None, treat_err_as_bug, ui_testing);
let html_opts = renderopts.clone();
html::render::run(krate, renderopts.extern_html_root_urls, &renderopts.external_html,
renderopts.playground_url,
renderopts.output,
renderopts.resource_suffix,
passes.into_iter().collect(),
options.extension_css,
renderopts.extension_css,
renderinfo,
options.sort_modules_alphabetically,
options.themes,
options.enable_minification, options.id_map,
options.enable_index_page, options.index_page,
html_opts,
&diag)
renderopts.sort_modules_alphabetically,
renderopts.themes,
renderopts.enable_minification, renderopts.id_map,
renderopts.enable_index_page, renderopts.index_page,
html_opts, &diag)
.expect("failed to generate documentation");
0
})
@ -482,7 +485,12 @@ where R: 'static + Send,
krate = pass(krate);
}
tx.send(f(Output { krate: krate, renderinfo: renderinfo, passes: passes })).unwrap();
tx.send(f(Output {
krate: krate,
renderinfo: renderinfo,
renderopts: options.render_options,
passes: passes
})).unwrap();
}));
match result {