rustdoc: fix up --playground-url

This commit is contained in:
Liigo Zhuang
2016-11-30 10:25:08 +08:00
parent 943bf96300
commit d5785a368e
3 changed files with 9 additions and 11 deletions

View File

@@ -428,6 +428,7 @@ pub fn derive_id(candidate: String) -> String {
/// Generates the documentation for `crate` into the directory `dst` /// Generates the documentation for `crate` into the directory `dst`
pub fn run(mut krate: clean::Crate, pub fn run(mut krate: clean::Crate,
external_html: &ExternalHtml, external_html: &ExternalHtml,
playground_url: Option<String>,
dst: PathBuf, dst: PathBuf,
passes: FxHashSet<String>, passes: FxHashSet<String>,
css_file_extension: Option<PathBuf>, css_file_extension: Option<PathBuf>,
@@ -452,12 +453,11 @@ pub fn run(mut krate: clean::Crate,
}; };
// If user passed in `--playground-url` arg, we fill in crate name here // If user passed in `--playground-url` arg, we fill in crate name here
markdown::PLAYGROUND.with(|slot| { if let Some(url) = playground_url {
if slot.borrow().is_some() { markdown::PLAYGROUND.with(|slot| {
let url = slot.borrow().as_ref().unwrap().1.clone();
*slot.borrow_mut() = Some((Some(krate.name.clone()), url)); *slot.borrow_mut() = Some((Some(krate.name.clone()), url));
} });
}); }
// Crawl the crate attributes looking for attributes which control how we're // Crawl the crate attributes looking for attributes which control how we're
// going to emit HTML // going to emit HTML

View File

@@ -234,10 +234,6 @@ pub fn main_args(args: &[String]) -> isize {
} }
}; };
if let Some(playground) = matches.opt_str("playground-url") {
html::markdown::PLAYGROUND.with(|s| { *s.borrow_mut() = Some((None, playground)); });
}
let test_args = matches.opt_strs("test-args"); let test_args = matches.opt_strs("test-args");
let test_args: Vec<String> = test_args.iter() let test_args: Vec<String> = test_args.iter()
.flat_map(|s| s.split_whitespace()) .flat_map(|s| s.split_whitespace())
@@ -266,6 +262,7 @@ pub fn main_args(args: &[String]) -> isize {
None => return 3 None => return 3
}; };
let crate_name = matches.opt_str("crate-name"); let crate_name = matches.opt_str("crate-name");
let playground_url = matches.opt_str("playground-url");
match (should_test, markdown_input) { match (should_test, markdown_input) {
(true, true) => { (true, true) => {
@@ -287,7 +284,7 @@ pub fn main_args(args: &[String]) -> isize {
info!("going to format"); info!("going to format");
match output_format.as_ref().map(|s| &**s) { match output_format.as_ref().map(|s| &**s) {
Some("html") | None => { Some("html") | None => {
html::render::run(krate, &external_html, html::render::run(krate, &external_html, playground_url,
output.unwrap_or(PathBuf::from("doc")), output.unwrap_or(PathBuf::from("doc")),
passes.into_iter().collect(), passes.into_iter().collect(),
css_file_extension, css_file_extension,

View File

@@ -63,7 +63,8 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches,
Err(LoadStringError::ReadFail) => return 1, Err(LoadStringError::ReadFail) => return 1,
Err(LoadStringError::BadUtf8) => return 2, Err(LoadStringError::BadUtf8) => return 2,
}; };
if let Some(playground) = matches.opt_str("markdown-playground-url") { if let Some(playground) = matches.opt_str("markdown-playground-url").or(
matches.opt_str("playground-url")) {
markdown::PLAYGROUND.with(|s| { *s.borrow_mut() = Some((None, playground)); }); markdown::PLAYGROUND.with(|s| { *s.borrow_mut() = Some((None, playground)); });
} }