From 265aed5b1c696499fee12969ffd2b0038cbdfc03 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 1 Jun 2020 20:38:25 -0700 Subject: [PATCH] Rename playpen to playground. --- README.md | 2 +- book-example/book.toml | 2 +- book-example/src/format/config.md | 8 +- book-example/src/format/mdbook.md | 14 +-- book-example/src/format/theme/editor.md | 10 +- src/config.rs | 35 +++--- src/preprocess/links.rs | 100 +++++++++------- src/renderer/html_handlebars/hbs_renderer.rs | 111 ++++++++++-------- src/theme/book.js | 38 +++--- src/theme/index.hbs | 12 +- src/theme/mod.rs | 2 +- .../ace.js | 0 .../editor.js | 2 +- .../mod.rs | 2 +- .../mode-rust.js | 0 .../theme-dawn.js | 0 .../theme-tomorrow_night.js | 0 tests/dummy_book/src/second.md | 2 +- tests/rendered_output.rs | 20 ++-- 19 files changed, 191 insertions(+), 169 deletions(-) rename src/theme/{playpen_editor => playground_editor}/ace.js (100%) rename src/theme/{playpen_editor => playground_editor}/editor.js (91%) rename src/theme/{playpen_editor => playground_editor}/mod.rs (86%) rename src/theme/{playpen_editor => playground_editor}/mode-rust.js (100%) rename src/theme/{playpen_editor => playground_editor}/theme-dawn.js (100%) rename src/theme/{playpen_editor => playground_editor}/theme-tomorrow_night.js (100%) diff --git a/README.md b/README.md index a96df09d8e..6f839b86a3 100644 --- a/README.md +++ b/README.md @@ -148,7 +148,7 @@ preprocessors are: all `README.md` chapters to `index.md` so `foo/README.md` can be accessed via the url `foo/` when published to a browser - `links` - a built-in preprocessor (enabled by default) for expanding the - `{{# playpen}}` and `{{# include}}` helpers in a chapter. + `{{# playground}}` and `{{# include}}` helpers in a chapter. Renderers are given the final book so they can do something with it. This is typically used for, as the name suggests, rendering the document in a particular diff --git a/book-example/book.toml b/book-example/book.toml index d21c84873e..da7d23f3f2 100644 --- a/book-example/book.toml +++ b/book-example/book.toml @@ -10,7 +10,7 @@ edition = "2018" [output.html] mathjax-support = true -[output.html.playpen] +[output.html.playground] editable = true line-numbers = true diff --git a/book-example/src/format/config.md b/book-example/src/format/config.md index cc5c6845fc..6c9a548c44 100644 --- a/book-example/src/format/config.md +++ b/book-example/src/format/config.md @@ -100,7 +100,7 @@ This controls the build process of your book. The following preprocessors are available and included by default: -- `links`: Expand the `{{ #playpen }}`, `{{ #include }}`, and `{{ #rustdoc_include }}` handlebars +- `links`: Expand the `{{ #playground }}`, `{{ #include }}`, and `{{ #rustdoc_include }}` handlebars helpers in a chapter to include the contents of a file. - `index`: Convert all chapter files named `README.md` into `index.md`. That is to say, all `README.md` would be rendered to an index file `index.html` in the @@ -191,7 +191,7 @@ The following configuration options are available: contents column. For example, "1.", "2.1". Set this option to true to disable those labels. Defaults to `false`. - **fold:** A subtable for configuring sidebar section-folding behavior. -- **playpen:** A subtable for configuring various playpen settings. +- **playground:** A subtable for configuring various playground settings. - **search:** A subtable for configuring the in-browser search functionality. mdBook must be compiled with the `search` feature enabled (on by default). - **git-repository-url:** A url to the git repository for the book. If provided @@ -212,7 +212,7 @@ Available configuration options for the `[output.html.fold]` table: - **level:** The higher the more folded regions are open. When level is 0, all folds are closed. Defaults to `0`. -Available configuration options for the `[output.html.playpen]` table: +Available configuration options for the `[output.html.playground]` table: - **editable:** Allow editing the source code. Defaults to `false`. - **copyable:** Display the copy button on code snippets. Defaults to `true`. @@ -271,7 +271,7 @@ git-repository-icon = "fa-github" enable = false level = 0 -[output.html.playpen] +[output.html.playground] editable = false copy-js = true line-numbers = false diff --git a/book-example/src/format/mdbook.md b/book-example/src/format/mdbook.md index de41768e53..223ba2159d 100644 --- a/book-example/src/format/mdbook.md +++ b/book-example/src/format/mdbook.md @@ -92,17 +92,17 @@ impl System for MySystem { ... } Then in the book, all you have to do is: ````hbs Here is a component: -```rust,no_run,noplaypen +```rust,no_run,noplayground \{{#include file.rs:component}} ``` Here is a system: -```rust,no_run,noplaypen +```rust,no_run,noplayground \{{#include file.rs:system}} ``` This is the full file. -```rust,no_run,noplaypen +```rust,no_run,noplayground \{{#include file.rs:all}} ``` ```` @@ -178,17 +178,17 @@ That is, it looks like this (click the "expand" icon to see the rest of the file With the following syntax, you can insert runnable Rust files into your book: ```hbs -\{{#playpen file.rs}} +\{{#playground file.rs}} ``` The path to the Rust file has to be relative from the current source file. -When play is clicked, the code snippet will be sent to the [Rust Playpen] to be +When play is clicked, the code snippet will be sent to the [Rust Playground] to be compiled and run. The result is sent back and displayed directly underneath the code. Here is what a rendered code snippet looks like: -{{#playpen example.rs}} +{{#playground example.rs}} -[Rust Playpen]: https://play.rust-lang.org/ +[Rust Playground]: https://play.rust-lang.org/ diff --git a/book-example/src/format/theme/editor.md b/book-example/src/format/theme/editor.md index 3f07fcff50..e39032f59a 100644 --- a/book-example/src/format/theme/editor.md +++ b/book-example/src/format/theme/editor.md @@ -1,11 +1,11 @@ # Editor -In addition to providing runnable code playpens, mdBook optionally allows them +In addition to providing runnable code playgrounds, mdBook optionally allows them to be editable. In order to enable editable code blocks, the following needs to be added to the ***book.toml***: ```toml -[output.html.playpen] +[output.html.playground] editable = true ``` @@ -19,7 +19,7 @@ fn main() { } ``` -The above will result in this editable playpen: +The above will result in this editable playground: ```rust,editable fn main() { @@ -28,7 +28,7 @@ fn main() { } ``` -Note the new `Undo Changes` button in the editable playpens. +Note the new `Undo Changes` button in the editable playgrounds. ## Customizing the Editor @@ -36,7 +36,7 @@ By default, the editor is the [Ace](https://ace.c9.io/) editor, but, if desired, the functionality may be overriden by providing a different folder: ```toml -[output.html.playpen] +[output.html.playground] editable = true editor = "/path/to/editor" ``` diff --git a/src/config.rs b/src/config.rs index dc712bbb29..04b18e8756 100644 --- a/src/config.rs +++ b/src/config.rs @@ -158,7 +158,7 @@ impl Config { /// Fetch an arbitrary item from the `Config` as a `toml::Value`. /// /// You can use dotted indices to access nested items (e.g. - /// `output.html.playpen` will fetch the "playpen" out of the html output + /// `output.html.playground` will fetch the "playground" out of the html output /// table). pub fn get(&self, key: &str) -> Option<&Value> { self.rest.read(key) @@ -451,11 +451,11 @@ impl Default for BuildConfig { } } -/// Configuration for the Rust compiler(e.g., for playpen) +/// Configuration for the Rust compiler(e.g., for playground) #[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)] #[serde(default, rename_all = "kebab-case")] pub struct RustConfig { - /// Rust edition used in playpen + /// Rust edition used in playground pub edition: Option, } @@ -496,8 +496,9 @@ pub struct HtmlConfig { pub additional_js: Vec, /// Fold settings. pub fold: Fold, - /// Playpen settings. - pub playpen: Playpen, + /// Playground settings. + #[serde(alias = "playpen")] + pub playground: Playground, /// Don't render section labels. pub no_section_label: bool, /// Search settings. If `None`, the default will be used. @@ -533,7 +534,7 @@ impl Default for HtmlConfig { additional_css: Vec::new(), additional_js: Vec::new(), fold: Fold::default(), - playpen: Playpen::default(), + playground: Playground::default(), no_section_label: false, search: None, git_repository_url: None, @@ -567,24 +568,24 @@ pub struct Fold { pub level: u8, } -/// Configuration for tweaking how the the HTML renderer handles the playpen. +/// Configuration for tweaking how the the HTML renderer handles the playground. #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(default, rename_all = "kebab-case")] -pub struct Playpen { - /// Should playpen snippets be editable? Default: `false`. +pub struct Playground { + /// Should playground snippets be editable? Default: `false`. pub editable: bool, /// Display the copy button. Default: `true`. pub copyable: bool, /// Copy JavaScript files for the editor to the output directory? /// Default: `true`. pub copy_js: bool, - /// Display line numbers on playpen snippets. Default: `false`. + /// Display line numbers on playground snippets. Default: `false`. pub line_numbers: bool, } -impl Default for Playpen { - fn default() -> Playpen { - Playpen { +impl Default for Playground { + fn default() -> Playground { + Playground { editable: false, copyable: true, copy_js: true, @@ -694,7 +695,7 @@ mod tests { git-repository-url = "https://foo.com/" git-repository-icon = "fa-code-fork" - [output.html.playpen] + [output.html.playground] editable = true editor = "ace" @@ -725,7 +726,7 @@ mod tests { use_default_preprocessors: true, }; let rust_should_be = RustConfig { edition: None }; - let playpen_should_be = Playpen { + let playground_should_be = Playground { editable: true, copyable: true, copy_js: true, @@ -737,7 +738,7 @@ mod tests { additional_css: vec![PathBuf::from("./foo/bar/baz.css")], theme: Some(PathBuf::from("./themedir")), default_theme: Some(String::from("rust")), - playpen: playpen_should_be, + playground: playground_should_be, git_repository_url: Some(String::from("https://foo.com/")), git_repository_icon: Some(String::from("fa-code-fork")), redirect: vec![ @@ -854,7 +855,7 @@ mod tests { // is happy... let src = COMPLEX_CONFIG; let mut config = Config::from_str(src).unwrap(); - let key = "output.html.playpen.editable"; + let key = "output.html.playground.editable"; assert_eq!(config.get(key).unwrap(), &Value::Boolean(true)); *config.get_mut(key).unwrap() = Value::Boolean(false); diff --git a/src/preprocess/links.rs b/src/preprocess/links.rs index 6d01c2cdfd..8cd9582417 100644 --- a/src/preprocess/links.rs +++ b/src/preprocess/links.rs @@ -22,7 +22,7 @@ const MAX_LINK_NESTED_DEPTH: usize = 10; ///. specified or the lines between specified anchors, and include the rest of the file behind `#`. /// This hides the lines from initial display but shows them when the reader expands the code /// block and provides them to Rustdoc for testing. -/// - `{{# playpen}}` - Insert runnable Rust files +/// - `{{# playground}}` - Insert runnable Rust files #[derive(Default)] pub struct LinkPreprocessor; @@ -114,7 +114,7 @@ where enum LinkType<'a> { Escaped, Include(PathBuf, RangeOrAnchor), - Playpen(PathBuf, Vec<&'a str>), + Playground(PathBuf, Vec<&'a str>), RustdocInclude(PathBuf, RangeOrAnchor), } @@ -183,7 +183,7 @@ impl<'a> LinkType<'a> { match self { LinkType::Escaped => None, LinkType::Include(p, _) => Some(return_relative_path(base, &p)), - LinkType::Playpen(p, _) => Some(return_relative_path(base, &p)), + LinkType::Playground(p, _) => Some(return_relative_path(base, &p)), LinkType::RustdocInclude(p, _) => Some(return_relative_path(base, &p)), } } @@ -262,7 +262,15 @@ impl<'a> Link<'a> { match (typ.as_str(), file_arg) { ("include", Some(pth)) => Some(parse_include_path(pth)), - ("playpen", Some(pth)) => Some(LinkType::Playpen(pth.into(), props)), + ("playground", Some(pth)) => Some(LinkType::Playground(pth.into(), props)), + ("playpen", Some(pth)) => { + warn!( + "the {{{{#playpen}}}} expression has been \ + renamed to {{{{#playground}}}}, \ + please update your book to use the new name" + ); + Some(LinkType::Playground(pth.into(), props)) + } ("rustdoc_include", Some(pth)) => Some(parse_rustdoc_include_path(pth)), _ => None, } @@ -324,7 +332,7 @@ impl<'a> Link<'a> { ) }) } - LinkType::Playpen(ref pat, ref attrs) => { + LinkType::Playground(ref pat, ref attrs) => { let target = base.join(pat); let contents = fs::read_to_string(&target).with_context(|| { @@ -406,7 +414,7 @@ mod tests { #[test] fn test_find_links_partial_link() { - let s = "Some random text with {{#playpen..."; + let s = "Some random text with {{#playground..."; assert!(find_links(s).collect::>() == vec![]); let s = "Some random text with {{#include..."; assert!(find_links(s).collect::>() == vec![]); @@ -416,19 +424,19 @@ mod tests { #[test] fn test_find_links_empty_link() { - let s = "Some random text with {{#playpen}} and {{#playpen }} {{}} {{#}}..."; + let s = "Some random text with {{#playground}} and {{#playground }} {{}} {{#}}..."; assert!(find_links(s).collect::>() == vec![]); } #[test] fn test_find_links_unknown_link_type() { - let s = "Some random text with {{#playpenz ar.rs}} and {{#incn}} {{baz}} {{#bar}}..."; + let s = "Some random text with {{#playgroundz ar.rs}} and {{#incn}} {{baz}} {{#bar}}..."; assert!(find_links(s).collect::>() == vec![]); } #[test] fn test_find_links_simple_link() { - let s = "Some random text with {{#playpen file.rs}} and {{#playpen test.rs }}..."; + let s = "Some random text with {{#playground file.rs}} and {{#playground test.rs }}..."; let res = find_links(s).collect::>(); println!("\nOUTPUT: {:?}\n", res); @@ -438,15 +446,15 @@ mod tests { vec![ Link { start_index: 22, - end_index: 42, - link_type: LinkType::Playpen(PathBuf::from("file.rs"), vec![]), - link_text: "{{#playpen file.rs}}", + end_index: 45, + link_type: LinkType::Playground(PathBuf::from("file.rs"), vec![]), + link_text: "{{#playground file.rs}}", }, Link { - start_index: 47, - end_index: 68, - link_type: LinkType::Playpen(PathBuf::from("test.rs"), vec![]), - link_text: "{{#playpen test.rs }}", + start_index: 50, + end_index: 74, + link_type: LinkType::Playground(PathBuf::from("test.rs"), vec![]), + link_text: "{{#playground test.rs }}", }, ] ); @@ -454,7 +462,7 @@ mod tests { #[test] fn test_find_links_with_special_characters() { - let s = "Some random text with {{#playpen foo-bar\\baz/_c++.rs}}..."; + let s = "Some random text with {{#playground foo-bar\\baz/_c++.rs}}..."; let res = find_links(s).collect::>(); println!("\nOUTPUT: {:?}\n", res); @@ -463,9 +471,9 @@ mod tests { res, vec![Link { start_index: 22, - end_index: 54, - link_type: LinkType::Playpen(PathBuf::from("foo-bar\\baz/_c++.rs"), vec![]), - link_text: "{{#playpen foo-bar\\baz/_c++.rs}}", + end_index: 57, + link_type: LinkType::Playground(PathBuf::from("foo-bar\\baz/_c++.rs"), vec![]), + link_text: "{{#playground foo-bar\\baz/_c++.rs}}", },] ); } @@ -605,7 +613,7 @@ mod tests { #[test] fn test_find_links_escaped_link() { - let s = "Some random text with escaped playpen \\{{#playpen file.rs editable}} ..."; + let s = "Some random text with escaped playground \\{{#playground file.rs editable}} ..."; let res = find_links(s).collect::>(); println!("\nOUTPUT: {:?}\n", res); @@ -613,18 +621,19 @@ mod tests { assert_eq!( res, vec![Link { - start_index: 38, - end_index: 68, + start_index: 41, + end_index: 74, link_type: LinkType::Escaped, - link_text: "\\{{#playpen file.rs editable}}", + link_text: "\\{{#playground file.rs editable}}", }] ); } #[test] - fn test_find_playpens_with_properties() { - let s = "Some random text with escaped playpen {{#playpen file.rs editable }} and some \ - more\n text {{#playpen my.rs editable no_run should_panic}} ..."; + fn test_find_playgrounds_with_properties() { + let s = + "Some random text with escaped playground {{#playground file.rs editable }} and some \ + more\n text {{#playground my.rs editable no_run should_panic}} ..."; let res = find_links(s).collect::>(); println!("\nOUTPUT: {:?}\n", res); @@ -632,19 +641,19 @@ mod tests { res, vec![ Link { - start_index: 38, - end_index: 68, - link_type: LinkType::Playpen(PathBuf::from("file.rs"), vec!["editable"]), - link_text: "{{#playpen file.rs editable }}", + start_index: 41, + end_index: 74, + link_type: LinkType::Playground(PathBuf::from("file.rs"), vec!["editable"]), + link_text: "{{#playground file.rs editable }}", }, Link { - start_index: 89, - end_index: 136, - link_type: LinkType::Playpen( + start_index: 95, + end_index: 145, + link_type: LinkType::Playground( PathBuf::from("my.rs"), vec!["editable", "no_run", "should_panic"], ), - link_text: "{{#playpen my.rs editable no_run should_panic}}", + link_text: "{{#playground my.rs editable no_run should_panic}}", }, ] ); @@ -652,8 +661,9 @@ mod tests { #[test] fn test_find_all_link_types() { - let s = "Some random text with escaped playpen {{#include file.rs}} and \\{{#contents are \ - insignifficant in escaped link}} some more\n text {{#playpen my.rs editable \ + let s = + "Some random text with escaped playground {{#include file.rs}} and \\{{#contents are \ + insignifficant in escaped link}} some more\n text {{#playground my.rs editable \ no_run should_panic}} ..."; let res = find_links(s).collect::>(); @@ -662,8 +672,8 @@ mod tests { assert_eq!( res[0], Link { - start_index: 38, - end_index: 58, + start_index: 41, + end_index: 61, link_type: LinkType::Include( PathBuf::from("file.rs"), RangeOrAnchor::Range(LineRange::from(..)) @@ -674,8 +684,8 @@ mod tests { assert_eq!( res[1], Link { - start_index: 63, - end_index: 112, + start_index: 66, + end_index: 115, link_type: LinkType::Escaped, link_text: "\\{{#contents are insignifficant in escaped link}}", } @@ -683,13 +693,13 @@ mod tests { assert_eq!( res[2], Link { - start_index: 130, - end_index: 177, - link_type: LinkType::Playpen( + start_index: 133, + end_index: 183, + link_type: LinkType::Playground( PathBuf::from("my.rs"), vec!["editable", "no_run", "should_panic"] ), - link_text: "{{#playpen my.rs editable no_run should_panic}}", + link_text: "{{#playground my.rs editable no_run should_panic}}", } ); } diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index ecb8359ee1..ad178f038c 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -1,9 +1,9 @@ use crate::book::{Book, BookItem}; -use crate::config::{Config, HtmlConfig, Playpen, RustEdition}; +use crate::config::{Config, HtmlConfig, Playground, RustEdition}; use crate::errors::*; use crate::renderer::html_handlebars::helpers; use crate::renderer::{RenderContext, Renderer}; -use crate::theme::{self, playpen_editor, Theme}; +use crate::theme::{self, playground_editor, Theme}; use crate::utils; use std::borrow::Cow; @@ -85,7 +85,7 @@ impl HtmlHandlebars { debug!("Render template"); let rendered = ctx.handlebars.render("index", &ctx.data)?; - let rendered = self.post_process(rendered, &ctx.html_config.playpen, ctx.edition); + let rendered = self.post_process(rendered, &ctx.html_config.playground, ctx.edition); // Write to file debug!("Creating {}", filepath.display()); @@ -97,7 +97,7 @@ impl HtmlHandlebars { ctx.data.insert("is_index".to_owned(), json!("true")); let rendered_index = ctx.handlebars.render("index", &ctx.data)?; let rendered_index = - self.post_process(rendered_index, &ctx.html_config.playpen, ctx.edition); + self.post_process(rendered_index, &ctx.html_config.playground, ctx.edition); debug!("Creating index.html from {}", ctx_path); utils::fs::write_file(&ctx.destination, "index.html", rendered_index.as_bytes())?; } @@ -109,12 +109,12 @@ impl HtmlHandlebars { fn post_process( &self, rendered: String, - playpen_config: &Playpen, + playground_config: &Playground, edition: Option, ) -> String { let rendered = build_header_links(&rendered); let rendered = fix_code_blocks(&rendered); - let rendered = add_playpen_pre(&rendered, playpen_config, edition); + let rendered = add_playground_pre(&rendered, playground_config, edition); rendered } @@ -194,19 +194,23 @@ impl HtmlHandlebars { )?; } - let playpen_config = &html_config.playpen; + let playground_config = &html_config.playground; // Ace is a very large dependency, so only load it when requested - if playpen_config.editable && playpen_config.copy_js { + if playground_config.editable && playground_config.copy_js { // Load the editor - write_file(destination, "editor.js", playpen_editor::JS)?; - write_file(destination, "ace.js", playpen_editor::ACE_JS)?; - write_file(destination, "mode-rust.js", playpen_editor::MODE_RUST_JS)?; - write_file(destination, "theme-dawn.js", playpen_editor::THEME_DAWN_JS)?; + write_file(destination, "editor.js", playground_editor::JS)?; + write_file(destination, "ace.js", playground_editor::ACE_JS)?; + write_file(destination, "mode-rust.js", playground_editor::MODE_RUST_JS)?; + write_file( + destination, + "theme-dawn.js", + playground_editor::THEME_DAWN_JS, + )?; write_file( destination, "theme-tomorrow_night.js", - playpen_editor::THEME_TOMORROW_NIGHT_JS, + playground_editor::THEME_TOMORROW_NIGHT_JS, )?; } @@ -447,7 +451,8 @@ impl Renderer for HtmlHandlebars { debug!("Render template"); let rendered = handlebars.render("index", &data)?; - let rendered = self.post_process(rendered, &html_config.playpen, ctx.config.rust.edition); + let rendered = + self.post_process(rendered, &html_config.playground, ctx.config.rust.edition); utils::fs::write_file(&destination, "print.html", rendered.as_bytes())?; debug!("Creating print.html ✓"); @@ -555,14 +560,14 @@ fn make_data( data.insert("additional_js".to_owned(), json!(js)); } - if html_config.playpen.editable && html_config.playpen.copy_js { - data.insert("playpen_js".to_owned(), json!(true)); - if html_config.playpen.line_numbers { - data.insert("playpen_line_numbers".to_owned(), json!(true)); + if html_config.playground.editable && html_config.playground.copy_js { + data.insert("playground_js".to_owned(), json!(true)); + if html_config.playground.line_numbers { + data.insert("playground_line_numbers".to_owned(), json!(true)); } } - if html_config.playpen.copyable { - data.insert("playpen_copyable".to_owned(), json!(true)); + if html_config.playground.copyable { + data.insert("playground_copyable".to_owned(), json!(true)); } data.insert("fold_enable".to_owned(), json!((html_config.fold.enable))); @@ -705,7 +710,11 @@ fn fix_code_blocks(html: &str) -> String { .into_owned() } -fn add_playpen_pre(html: &str, playpen_config: &Playpen, edition: Option) -> String { +fn add_playground_pre( + html: &str, + playground_config: &Playground, + edition: Option, +) -> String { let regex = Regex::new(r##"((?s)]?class="([^"]+)".*?>(.*?))"##).unwrap(); regex .replace_all(html, |caps: &Captures<'_>| { @@ -714,7 +723,9 @@ fn add_playpen_pre(html: &str, playpen_config: &Playpen, edition: Option{}", + "
{}
", classes, edition_class, { - let content: Cow<'_, str> = if playpen_config.editable + let content: Cow<'_, str> = if playground_config.editable && classes.contains("editable") || text.contains("fn main") || text.contains("quick_main!") @@ -868,29 +879,29 @@ mod tests { } #[test] - fn add_playpen() { + fn add_playground() { let inputs = [ ("x()", - "
\n#![allow(unused)]\nfn main() {\nx()\n}\n
"), + "
\n#![allow(unused)]\nfn main() {\nx()\n}\n
"), ("fn main() {}", - "
fn main() {}\n
"), + "
fn main() {}\n
"), ("let s = \"foo\n # bar\n\";", - "
let s = \"foo\n bar\n\";\n
"), + "
let s = \"foo\n bar\n\";\n
"), ("let s = \"foo\n ## bar\n\";", - "
let s = \"foo\n # bar\n\";\n
"), + "
let s = \"foo\n # bar\n\";\n
"), ("let s = \"foo\n # bar\n#\n\";", - "
let s = \"foo\n bar\n\n\";\n
"), + "
let s = \"foo\n bar\n\n\";\n
"), ("let s = \"foo\n # bar\n\";", "let s = \"foo\n bar\n\";\n"), ("#![no_std]\nlet s = \"foo\";\n #[some_attr]", - "
#![no_std]\nlet s = \"foo\";\n #[some_attr]\n
"), + "
#![no_std]\nlet s = \"foo\";\n #[some_attr]\n
"), ]; for (src, should_be) in &inputs { - let got = add_playpen_pre( + let got = add_playground_pre( src, - &Playpen { + &Playground { editable: true, - ..Playpen::default() + ..Playground::default() }, None, ); @@ -898,23 +909,23 @@ mod tests { } } #[test] - fn add_playpen_edition2015() { + fn add_playground_edition2015() { let inputs = [ ("x()", - "
\n#![allow(unused)]\nfn main() {\nx()\n}\n
"), + "
\n#![allow(unused)]\nfn main() {\nx()\n}\n
"), ("fn main() {}", - "
fn main() {}\n
"), + "
fn main() {}\n
"), ("fn main() {}", - "
fn main() {}\n
"), + "
fn main() {}\n
"), ("fn main() {}", - "
fn main() {}\n
"), + "
fn main() {}\n
"), ]; for (src, should_be) in &inputs { - let got = add_playpen_pre( + let got = add_playground_pre( src, - &Playpen { + &Playground { editable: true, - ..Playpen::default() + ..Playground::default() }, Some(RustEdition::E2015), ); @@ -922,23 +933,23 @@ mod tests { } } #[test] - fn add_playpen_edition2018() { + fn add_playground_edition2018() { let inputs = [ ("x()", - "
\n#![allow(unused)]\nfn main() {\nx()\n}\n
"), + "
\n#![allow(unused)]\nfn main() {\nx()\n}\n
"), ("fn main() {}", - "
fn main() {}\n
"), + "
fn main() {}\n
"), ("fn main() {}", - "
fn main() {}\n
"), + "
fn main() {}\n
"), ("fn main() {}", - "
fn main() {}\n
"), + "
fn main() {}\n
"), ]; for (src, should_be) in &inputs { - let got = add_playpen_pre( + let got = add_playground_pre( src, - &Playpen { + &Playground { editable: true, - ..Playpen::default() + ..Playground::default() }, Some(RustEdition::E2018), ); diff --git a/src/theme/book.js b/src/theme/book.js index 849f8cefe9..049505fc6d 100644 --- a/src/theme/book.js +++ b/src/theme/book.js @@ -4,8 +4,8 @@ window.onunload = function () { }; // Global variable, shared between modules -function playpen_text(playpen) { - let code_block = playpen.querySelector("code"); +function playground_text(playground) { + let code_block = playground.querySelector("code"); if (window.ace && code_block.classList.contains("editable")) { let editor = window.ace.edit(code_block); @@ -23,8 +23,8 @@ function playpen_text(playpen) { ]); } - var playpens = Array.from(document.querySelectorAll(".playpen")); - if (playpens.length > 0) { + var playgrounds = Array.from(document.querySelectorAll(".playground")); + if (playgrounds.length > 0) { fetch_with_timeout("https://play.rust-lang.org/meta/crates", { headers: { 'Content-Type': "application/json", @@ -36,21 +36,21 @@ function playpen_text(playpen) { .then(response => { // get list of crates available in the rust playground let playground_crates = response.crates.map(item => item["id"]); - playpens.forEach(block => handle_crate_list_update(block, playground_crates)); + playgrounds.forEach(block => handle_crate_list_update(block, playground_crates)); }); } - function handle_crate_list_update(playpen_block, playground_crates) { + function handle_crate_list_update(playground_block, playground_crates) { // update the play buttons after receiving the response - update_play_button(playpen_block, playground_crates); + update_play_button(playground_block, playground_crates); // and install on change listener to dynamically update ACE editors if (window.ace) { - let code_block = playpen_block.querySelector("code"); + let code_block = playground_block.querySelector("code"); if (code_block.classList.contains("editable")) { let editor = window.ace.edit(code_block); editor.addEventListener("change", function (e) { - update_play_button(playpen_block, playground_crates); + update_play_button(playground_block, playground_crates); }); // add Ctrl-Enter command to execute rust code editor.commands.addCommand({ @@ -59,7 +59,7 @@ function playpen_text(playpen) { win: "Ctrl-Enter", mac: "Ctrl-Enter" }, - exec: _editor => run_rust_code(playpen_block) + exec: _editor => run_rust_code(playground_block) }); } } @@ -77,7 +77,7 @@ function playpen_text(playpen) { } // get list of `extern crate`'s from snippet - var txt = playpen_text(pre_block); + var txt = playground_text(pre_block); var re = /extern\s+crate\s+([a-zA-Z_0-9]+)\s*;/g; var snippet_crates = []; var item; @@ -106,7 +106,7 @@ function playpen_text(playpen) { code_block.append(result_block); } - let text = playpen_text(code_block); + let text = playground_text(code_block); let classes = code_block.querySelector('code').classList; let has_2018 = classes.contains("edition2018"); let edition = has_2018 ? "2018" : "2015"; @@ -200,10 +200,10 @@ function playpen_text(playpen) { }); }); - if (window.playpen_copyable) { + if (window.playground_copyable) { Array.from(document.querySelectorAll('pre code')).forEach(function (block) { var pre_block = block.parentNode; - if (!pre_block.classList.contains('playpen')) { + if (!pre_block.classList.contains('playground')) { var buttons = pre_block.querySelector(".buttons"); if (!buttons) { buttons = document.createElement('div'); @@ -222,8 +222,8 @@ function playpen_text(playpen) { }); } - // Process playpen code blocks - Array.from(document.querySelectorAll(".playpen")).forEach(function (pre_block) { + // Process playground code blocks + Array.from(document.querySelectorAll(".playground")).forEach(function (pre_block) { // Add play button var buttons = pre_block.querySelector(".buttons"); if (!buttons) { @@ -243,7 +243,7 @@ function playpen_text(playpen) { run_rust_code(pre_block); }); - if (window.playpen_copyable) { + if (window.playground_copyable) { var copyCodeClipboardButton = document.createElement('button'); copyCodeClipboardButton.className = 'fa fa-copy clip-button'; copyCodeClipboardButton.innerHTML = ''; @@ -572,8 +572,8 @@ function playpen_text(playpen) { var clipboardSnippets = new ClipboardJS('.clip-button', { text: function (trigger) { hideTooltip(trigger); - let playpen = trigger.closest("pre"); - return playpen_text(playpen); + let playground = trigger.closest("pre"); + return playground_text(playground); } }); diff --git a/src/theme/index.hbs b/src/theme/index.hbs index e8a92dd098..3d2222f405 100644 --- a/src/theme/index.hbs +++ b/src/theme/index.hbs @@ -236,19 +236,19 @@ {{/if}} - {{#if playpen_line_numbers}} + {{#if playground_line_numbers}} {{/if}} - - {{#if playpen_copyable}} + + {{#if playground_copyable}} {{/if}} - {{#if playpen_js}} + {{#if playground_js}} diff --git a/src/theme/mod.rs b/src/theme/mod.rs index 38aa22e97a..793aeb2eb3 100644 --- a/src/theme/mod.rs +++ b/src/theme/mod.rs @@ -1,6 +1,6 @@ #![allow(missing_docs)] -pub mod playpen_editor; +pub mod playground_editor; pub mod fonts; diff --git a/src/theme/playpen_editor/ace.js b/src/theme/playground_editor/ace.js similarity index 100% rename from src/theme/playpen_editor/ace.js rename to src/theme/playground_editor/ace.js diff --git a/src/theme/playpen_editor/editor.js b/src/theme/playground_editor/editor.js similarity index 91% rename from src/theme/playpen_editor/editor.js rename to src/theme/playground_editor/editor.js index 5bfa1aa713..464790c499 100644 --- a/src/theme/playpen_editor/editor.js +++ b/src/theme/playground_editor/editor.js @@ -6,7 +6,7 @@ window.editors = []; } Array.from(document.querySelectorAll('.editable')).forEach(function(editable) { - let display_line_numbers = window.playpen_line_numbers || false; + let display_line_numbers = window.playground_line_numbers || false; let editor = ace.edit(editable); editor.setOptions({ diff --git a/src/theme/playpen_editor/mod.rs b/src/theme/playground_editor/mod.rs similarity index 86% rename from src/theme/playpen_editor/mod.rs rename to src/theme/playground_editor/mod.rs index 0fdf713249..19dbf4bc08 100644 --- a/src/theme/playpen_editor/mod.rs +++ b/src/theme/playground_editor/mod.rs @@ -1,4 +1,4 @@ -//! Theme dependencies for the playpen editor. +//! Theme dependencies for the playground editor. pub static JS: &[u8] = include_bytes!("editor.js"); pub static ACE_JS: &[u8] = include_bytes!("ace.js"); diff --git a/src/theme/playpen_editor/mode-rust.js b/src/theme/playground_editor/mode-rust.js similarity index 100% rename from src/theme/playpen_editor/mode-rust.js rename to src/theme/playground_editor/mode-rust.js diff --git a/src/theme/playpen_editor/theme-dawn.js b/src/theme/playground_editor/theme-dawn.js similarity index 100% rename from src/theme/playpen_editor/theme-dawn.js rename to src/theme/playground_editor/theme-dawn.js diff --git a/src/theme/playpen_editor/theme-tomorrow_night.js b/src/theme/playground_editor/theme-tomorrow_night.js similarity index 100% rename from src/theme/playpen_editor/theme-tomorrow_night.js rename to src/theme/playground_editor/theme-tomorrow_night.js diff --git a/tests/dummy_book/src/second.md b/tests/dummy_book/src/second.md index 539d17f83f..adf4fca62e 100644 --- a/tests/dummy_book/src/second.md +++ b/tests/dummy_book/src/second.md @@ -2,4 +2,4 @@ This makes sure you can insert runnable Rust files. -{{#playpen example.rs}} \ No newline at end of file +{{#playground example.rs}} diff --git a/tests/rendered_output.rs b/tests/rendered_output.rs index db0badd7c8..4f0568dcc7 100644 --- a/tests/rendered_output.rs +++ b/tests/rendered_output.rs @@ -135,18 +135,18 @@ fn check_correct_relative_links_in_print_page() { } #[test] -fn rendered_code_has_playpen_stuff() { +fn rendered_code_has_playground_stuff() { let temp = DummyBook::new().build().unwrap(); let md = MDBook::load(temp.path()).unwrap(); md.build().unwrap(); let nested = temp.path().join("book/first/nested.html"); - let playpen_class = vec![r#"class="playpen""#]; + let playground_class = vec![r#"class="playground""#]; - assert_contains_strings(nested, &playpen_class); + assert_contains_strings(nested, &playground_class); let book_js = temp.path().join("book/book.js"); - assert_contains_strings(book_js, &[".playpen"]); + assert_contains_strings(book_js, &[".playground"]); } #[test] @@ -344,23 +344,23 @@ fn create_missing_file_with_config() { assert!(temp.path().join("src").join("intro.md").exists()); } -/// This makes sure you can include a Rust file with `{{#playpen example.rs}}`. +/// This makes sure you can include a Rust file with `{{#playground example.rs}}`. /// Specification is in `book-example/src/format/rust.md` #[test] -fn able_to_include_playpen_files_in_chapters() { +fn able_to_include_playground_files_in_chapters() { let temp = DummyBook::new().build().unwrap(); let md = MDBook::load(temp.path()).unwrap(); md.build().unwrap(); let second = temp.path().join("book/second.html"); - let playpen_strings = &[ - r#"class="playpen""#, + let playground_strings = &[ + r#"class="playground""#, r#"println!("Hello World!");"#, ]; - assert_contains_strings(&second, playpen_strings); - assert_doesnt_contain_strings(&second, &["{{#playpen example.rs}}"]); + assert_contains_strings(&second, playground_strings); + assert_doesnt_contain_strings(&second, &["{{#playground example.rs}}"]); } /// This makes sure you can include a Rust file with `{{#include ../SUMMARY.md}}`.