book: Emit links to play.rust-lang.org to run examples

Had to fix a bug in `--markdown-playground-url` for markdown files in rustdoc as
well as adding some necessary JS to the rustbook output as well.

Closes #21553
This commit is contained in:
Alex Crichton 2015-04-07 11:23:14 -07:00
parent 0f3183f42b
commit 947f1b66cb
3 changed files with 12 additions and 1 deletions

View File

@ -59,7 +59,7 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches,
let input_str = load_or_return!(input, 1, 2);
let playground = matches.opt_str("markdown-playground-url");
if playground.is_some() {
markdown::PLAYGROUND_KRATE.with(|s| { *s.borrow_mut() = None; });
markdown::PLAYGROUND_KRATE.with(|s| { *s.borrow_mut() = Some(None); });
}
let playground = playground.unwrap_or("".to_string());

View File

@ -135,6 +135,7 @@ fn render(book: &Book, tgt: &Path) -> CliResult<()> {
format!("-o{}", out_path.display()),
format!("--html-before-content={}", prelude.display()),
format!("--html-after-content={}", postlude.display()),
format!("--markdown-playground-url=http://play.rust-lang.org"),
format!("--markdown-css={}", item.path_to_root.join("rust-book.css").display()),
"--markdown-no-toc".to_string(),
];
@ -148,6 +149,14 @@ fn render(book: &Book, tgt: &Path) -> CliResult<()> {
// create index.html from the root README
try!(fs::copy(&tgt.join("README.html"), &tgt.join("index.html")));
// Copy some js for playpen
let mut jquery = try!(File::create(tgt.join("jquery.js")));
let js = include_bytes!("../librustdoc/html/static/jquery-2.1.0.min.js");
try!(jquery.write_all(js));
let mut playpen = try!(File::create(tgt.join("playpen.js")));
let js = include_bytes!("../librustdoc/html/static/playpen.js");
try!(playpen.write_all(js));
Ok(())
}

View File

@ -71,4 +71,6 @@ document.addEventListener("DOMContentLoaded", function(event) {
});
</script>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="playpen.js"></script>
"#;