split off a separate RenderOptions struct
This commit is contained in:
parent
157833c588
commit
4d6c2765e6
3 changed files with 67 additions and 49 deletions
|
@ -32,14 +32,13 @@ use opts;
|
||||||
use passes::{self, DefaultPassOption};
|
use passes::{self, DefaultPassOption};
|
||||||
use theme;
|
use theme;
|
||||||
|
|
||||||
|
/// Configuration options for rustdoc.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Options {
|
pub struct Options {
|
||||||
// Basic options / Options passed directly to rustc
|
// Basic options / Options passed directly to rustc
|
||||||
|
|
||||||
/// The crate root or Markdown file to load.
|
/// The crate root or Markdown file to load.
|
||||||
pub input: PathBuf,
|
pub input: PathBuf,
|
||||||
/// Output directory to generate docs into. Defaults to `doc`.
|
|
||||||
pub output: PathBuf,
|
|
||||||
/// The name of the crate being documented.
|
/// The name of the crate being documented.
|
||||||
pub crate_name: Option<String>,
|
pub crate_name: Option<String>,
|
||||||
/// How to format errors and warnings.
|
/// 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,
|
/// Whether to display warnings during doc generation or while gathering doctests. By default,
|
||||||
/// all non-rustdoc-specific lints are allowed when generating docs.
|
/// all non-rustdoc-specific lints are allowed when generating docs.
|
||||||
pub display_warnings: bool,
|
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
|
// 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.
|
/// External files to insert into generated pages.
|
||||||
pub external_html: ExternalHtml,
|
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.
|
/// 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!
|
/// Be aware: This option can come both from the CLI and from crate attributes!
|
||||||
pub playground_url: Option<String>,
|
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.
|
/// Whether to sort modules alphabetically on a module page instead of using declaration order.
|
||||||
/// `true` by default.
|
/// `true` by default.
|
||||||
///
|
///
|
||||||
|
@ -390,7 +398,6 @@ impl Options {
|
||||||
|
|
||||||
Ok(Options {
|
Ok(Options {
|
||||||
input,
|
input,
|
||||||
output,
|
|
||||||
crate_name,
|
crate_name,
|
||||||
error_format,
|
error_format,
|
||||||
libs,
|
libs,
|
||||||
|
@ -410,21 +417,24 @@ impl Options {
|
||||||
default_passes,
|
default_passes,
|
||||||
manual_passes,
|
manual_passes,
|
||||||
display_warnings,
|
display_warnings,
|
||||||
id_map,
|
|
||||||
external_html,
|
|
||||||
playground_url,
|
|
||||||
crate_version,
|
crate_version,
|
||||||
sort_modules_alphabetically,
|
render_options: RenderOptions {
|
||||||
themes,
|
output,
|
||||||
extension_css,
|
external_html,
|
||||||
extern_html_root_urls,
|
id_map,
|
||||||
resource_suffix,
|
playground_url,
|
||||||
enable_minification,
|
sort_modules_alphabetically,
|
||||||
enable_index_page,
|
themes,
|
||||||
index_page,
|
extension_css,
|
||||||
markdown_no_toc,
|
extern_html_root_urls,
|
||||||
markdown_css,
|
resource_suffix,
|
||||||
markdown_playground_url,
|
enable_minification,
|
||||||
|
enable_index_page,
|
||||||
|
index_page,
|
||||||
|
markdown_no_toc,
|
||||||
|
markdown_css,
|
||||||
|
markdown_playground_url,
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -509,7 +509,7 @@ pub fn run(mut krate: clean::Crate,
|
||||||
id_map: IdMap,
|
id_map: IdMap,
|
||||||
enable_index_page: bool,
|
enable_index_page: bool,
|
||||||
index_page: Option<PathBuf>,
|
index_page: Option<PathBuf>,
|
||||||
options: config::Options,
|
options: config::RenderOptions,
|
||||||
diag: &errors::Handler,
|
diag: &errors::Handler,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let src_root = match krate.src {
|
let src_root = match krate.src {
|
||||||
|
@ -760,7 +760,7 @@ fn write_shared(
|
||||||
cache: &Cache,
|
cache: &Cache,
|
||||||
search_index: String,
|
search_index: String,
|
||||||
enable_minification: bool,
|
enable_minification: bool,
|
||||||
options: &config::Options,
|
options: &config::RenderOptions,
|
||||||
diag: &errors::Handler,
|
diag: &errors::Handler,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
// Write out the shared files. Note that these are shared among all rustdoc
|
// Write out the shared files. Note that these are shared among all rustdoc
|
||||||
|
|
|
@ -90,6 +90,7 @@ mod theme;
|
||||||
struct Output {
|
struct Output {
|
||||||
krate: clean::Crate,
|
krate: clean::Crate,
|
||||||
renderinfo: html::render::RenderInfo,
|
renderinfo: html::render::RenderInfo,
|
||||||
|
renderopts: config::RenderOptions,
|
||||||
passes: Vec<String>,
|
passes: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -381,36 +382,38 @@ fn main_args(args: &[String]) -> isize {
|
||||||
options.display_warnings, options.linker, options.edition,
|
options.display_warnings, options.linker, options.edition,
|
||||||
options.codegen_options)
|
options.codegen_options)
|
||||||
}
|
}
|
||||||
(false, true) => return markdown::render(&options.input, options.output,
|
(false, true) => return markdown::render(&options.input, options.render_options.output,
|
||||||
&options.markdown_css,
|
&options.render_options.markdown_css,
|
||||||
options.markdown_playground_url
|
options.render_options.markdown_playground_url
|
||||||
.or(options.playground_url),
|
.or(options.render_options.playground_url),
|
||||||
&options.external_html,
|
&options.render_options.external_html,
|
||||||
!options.markdown_no_toc, &diag),
|
!options.render_options.markdown_no_toc, &diag),
|
||||||
(false, false) => {}
|
(false, false) => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: split render-time options into their own struct so i don't have to clone here
|
// need to move these items separately because we lose them by the time the closure is called,
|
||||||
rust_input(options.clone(), move |out| {
|
// but we can't crates the Handler ahead of time because it's not Send
|
||||||
let Output { krate, passes, renderinfo } = out;
|
let diag_opts = (options.error_format,
|
||||||
|
options.debugging_options.treat_err_as_bug,
|
||||||
|
options.debugging_options.ui_testing);
|
||||||
|
rust_input(options, move |out| {
|
||||||
|
let Output { krate, passes, renderinfo, renderopts } = out;
|
||||||
info!("going to format");
|
info!("going to format");
|
||||||
let diag = core::new_handler(options.error_format,
|
let (error_format, treat_err_as_bug, ui_testing) = diag_opts;
|
||||||
None,
|
let diag = core::new_handler(error_format, None, treat_err_as_bug, ui_testing);
|
||||||
options.debugging_options.treat_err_as_bug,
|
let html_opts = renderopts.clone();
|
||||||
options.debugging_options.ui_testing);
|
html::render::run(krate, renderopts.extern_html_root_urls, &renderopts.external_html,
|
||||||
let html_opts = options.clone();
|
renderopts.playground_url,
|
||||||
html::render::run(krate, options.extern_html_root_urls, &options.external_html, options.playground_url,
|
renderopts.output,
|
||||||
options.output,
|
renderopts.resource_suffix,
|
||||||
options.resource_suffix,
|
|
||||||
passes.into_iter().collect(),
|
passes.into_iter().collect(),
|
||||||
options.extension_css,
|
renderopts.extension_css,
|
||||||
renderinfo,
|
renderinfo,
|
||||||
options.sort_modules_alphabetically,
|
renderopts.sort_modules_alphabetically,
|
||||||
options.themes,
|
renderopts.themes,
|
||||||
options.enable_minification, options.id_map,
|
renderopts.enable_minification, renderopts.id_map,
|
||||||
options.enable_index_page, options.index_page,
|
renderopts.enable_index_page, renderopts.index_page,
|
||||||
html_opts,
|
html_opts, &diag)
|
||||||
&diag)
|
|
||||||
.expect("failed to generate documentation");
|
.expect("failed to generate documentation");
|
||||||
0
|
0
|
||||||
})
|
})
|
||||||
|
@ -482,7 +485,12 @@ where R: 'static + Send,
|
||||||
krate = pass(krate);
|
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 {
|
match result {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue