From add6204484706c4a28b1d7cfbfd5fc336e18c9cf Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 1 Oct 2018 22:28:12 +0200 Subject: [PATCH 01/18] Stabilize rustdoc theme options --- src/librustdoc/config.rs | 4 +++- src/librustdoc/lib.rs | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 3e1c57182b9f5..2b8e060ce8ea0 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -364,7 +364,9 @@ impl Options { .iter() .map(|s| (PathBuf::from(&s), s.to_owned())) { if !theme_file.is_file() { - diag.struct_err("option --themes arguments must all be files").emit(); + diag.struct_err(&format!("invalid file: \"{}\"", theme_s)) + .help("option --themes arguments must all be files") + .emit(); return Err(1); } let (success, ret) = theme::test_theme_against(&theme_file, &paths, &diag); diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 4f102dbf128f4..27bef5db2d6d2 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -251,12 +251,12 @@ fn opts() -> Vec { o.optflag("", "sort-modules-by-appearance", "sort modules by where they appear in the \ program, rather than alphabetically") }), - unstable("themes", |o| { + stable("themes", |o| { o.optmulti("", "themes", "additional themes which will be added to the generated docs", "FILES") }), - unstable("theme-checker", |o| { + stable("theme-checker", |o| { o.optmulti("", "theme-checker", "check if given theme is valid", "FILES") From 3eba28432fc83935940e0c44182eec4c97e12b69 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 23 May 2019 13:45:08 +0200 Subject: [PATCH 02/18] Add documentation for stabilized flags --- src/doc/rustdoc/src/command-line-arguments.md | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/doc/rustdoc/src/command-line-arguments.md b/src/doc/rustdoc/src/command-line-arguments.md index b21defaedc313..9bbb396323d12 100644 --- a/src/doc/rustdoc/src/command-line-arguments.md +++ b/src/doc/rustdoc/src/command-line-arguments.md @@ -355,7 +355,27 @@ $ rustdoc src/lib.rs --edition 2018 $ rustdoc --test src/lib.rs --edition 2018 ``` -This flag allows rustdoc to treat your rust code as the given edition. It will compile doctests with +This flag allows `rustdoc` to treat your rust code as the given edition. It will compile doctests with the given edition as well. As with `rustc`, the default edition that `rustdoc` will use is `2015` (the first edition). +## `themes`: add more themes to generated documentation + +By default, `rustdoc` only provides the "dark" and light" themes. If you want to add new ones, +you'll need to this flag as follows: + +```bash +$ rustdoc src/lib.rs --themes /path/to/your/theme/file.css +``` + +### `theme-checker`: check if your themes implement all the required rules + +This flag allows you to check if your themes implement the necessary CSS rules. To put it more +simply, when adding a new theme, it needs to implements all the CSS rules present in the `ðark` and +`light` CSS themes. + +You can use this flag like this: + +```bash +$ rustdoc src/lib.rs --theme-checker /path/to/your/theme/file.css +``` From dcccd28e42616ae97f3e0ec97be326f634a9e12c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 23 May 2019 13:45:30 +0200 Subject: [PATCH 03/18] Warn instead of failing for themes --- src/librustdoc/config.rs | 3 +-- src/librustdoc/theme.rs | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 2b8e060ce8ea0..853be97530b93 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -371,10 +371,9 @@ impl Options { } let (success, ret) = theme::test_theme_against(&theme_file, &paths, &diag); if !success || !ret.is_empty() { - diag.struct_err(&format!("invalid theme: \"{}\"", theme_s)) + diag.struct_warn(&format!("invalid theme: \"{}\"", theme_s)) .help("check what's wrong with the --theme-checker option") .emit(); - return Err(1); } themes.push(theme_file); } diff --git a/src/librustdoc/theme.rs b/src/librustdoc/theme.rs index 7037a146c50ab..1be85f4a91d0e 100644 --- a/src/librustdoc/theme.rs +++ b/src/librustdoc/theme.rs @@ -273,6 +273,7 @@ pub fn test_theme_against>( diag: &Handler, ) -> (bool, Vec) { let data = try_something!(fs::read(f), diag, (false, vec![])); + let paths = load_css_paths(&data); let mut ret = vec![]; get_differences(against, &paths, &mut ret); From f3e4279ccc39f097f659f6e8eaf314e9e4da523e Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 24 May 2019 10:39:49 +0200 Subject: [PATCH 04/18] Apply review comments --- src/doc/rustdoc/src/command-line-arguments.md | 4 ++-- src/librustdoc/config.rs | 12 +++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/doc/rustdoc/src/command-line-arguments.md b/src/doc/rustdoc/src/command-line-arguments.md index 9bbb396323d12..2c25baf373ed2 100644 --- a/src/doc/rustdoc/src/command-line-arguments.md +++ b/src/doc/rustdoc/src/command-line-arguments.md @@ -371,8 +371,8 @@ $ rustdoc src/lib.rs --themes /path/to/your/theme/file.css ### `theme-checker`: check if your themes implement all the required rules This flag allows you to check if your themes implement the necessary CSS rules. To put it more -simply, when adding a new theme, it needs to implements all the CSS rules present in the `ðark` and -`light` CSS themes. +simply, when adding a new theme, it needs to implements all the CSS rules present in the "light" +CSS theme. You can use this flag like this: diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 853be97530b93..068da1f194120 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -370,9 +370,15 @@ impl Options { return Err(1); } let (success, ret) = theme::test_theme_against(&theme_file, &paths, &diag); - if !success || !ret.is_empty() { - diag.struct_warn(&format!("invalid theme: \"{}\"", theme_s)) - .help("check what's wrong with the --theme-checker option") + if !success { + diag.struct_warn(&format!("error loading theme file: \"{}\"", theme_s)).emit(); + return Err(1); + } else if !ret.is_empty() { + diag.struct_warn(&format!("theme file \"{}\" is missing CSS rules from the \ + default theme", theme_s)) + .warn("the theme may appear incorrect when loaded") + .help(&format!("to see what rules are missing, call `rustdoc \ + --theme-checker \"{}\"`", theme_s)) .emit(); } themes.push(theme_file); From d350008c884ef1bd3bcae88fd7af9cea125764a0 Mon Sep 17 00:00:00 2001 From: QuietMisdreavus Date: Fri, 24 May 2019 14:04:45 -0500 Subject: [PATCH 05/18] add test for rustdoc's --themes flag --- src/test/run-make-fulldeps/rustdoc-themes/Makefile | 10 ++++++++++ src/test/run-make-fulldeps/rustdoc-themes/foo.rs | 4 ++++ 2 files changed, 14 insertions(+) create mode 100644 src/test/run-make-fulldeps/rustdoc-themes/Makefile create mode 100644 src/test/run-make-fulldeps/rustdoc-themes/foo.rs diff --git a/src/test/run-make-fulldeps/rustdoc-themes/Makefile b/src/test/run-make-fulldeps/rustdoc-themes/Makefile new file mode 100644 index 0000000000000..a4536e77bd7b1 --- /dev/null +++ b/src/test/run-make-fulldeps/rustdoc-themes/Makefile @@ -0,0 +1,10 @@ +-include ../tools.mk + +# Test that rustdoc will properly load in a theme file and display it in the theme selector. + +OUTPUT_DIR := "$(TMPDIR)/rustdoc-themes" + +all: + cp $(S)/src/librustdoc/html/static/themes/light.css $(TMPDIR)/test.css + $(RUSTDOC) -o $(OUTPUT_DIR) foo.rs --themes $(TMPDIR)/test.css + $(HTMLDOCCK) $(OUTPUT_DIR) foo.rs diff --git a/src/test/run-make-fulldeps/rustdoc-themes/foo.rs b/src/test/run-make-fulldeps/rustdoc-themes/foo.rs new file mode 100644 index 0000000000000..58efaf7d5a05a --- /dev/null +++ b/src/test/run-make-fulldeps/rustdoc-themes/foo.rs @@ -0,0 +1,4 @@ +// @has test.css +// @has foo/struct.Foo.html +// @has - '//link[@rel="stylesheet"]/@href' '../test.css' +pub struct Foo; From e3651202431f1b07e51a008cd8a8a242a12ab4f1 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 30 Jun 2019 19:09:58 +0200 Subject: [PATCH 06/18] Prevent invalid html characters in themes name --- src/librustdoc/html/render.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 9a87bcc10db8e..7eb49ead52720 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -569,7 +569,9 @@ fn write_shared( let content = try_err!(fs::read(&entry), &entry); let theme = try_none!(try_none!(entry.file_stem(), &entry).to_str(), &entry); let extension = try_none!(try_none!(entry.extension(), &entry).to_str(), &entry); - cx.shared.fs.write(cx.path(&format!("{}.{}", theme, extension)), content.as_slice())?; + cx.shared.fs.write( + cx.path(&format!("{}.{}", Escape(theme), extension)), + content.as_slice())?; themes.insert(theme.to_owned()); } From 82872addf17a110d6182f73bb31ff8d2f949010c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 30 Jun 2019 19:23:45 +0200 Subject: [PATCH 07/18] Add sentence to tell other options are ignored when running check-theme --- src/librustdoc/config.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 068da1f194120..1f7f87354652f 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -281,12 +281,12 @@ impl Options { // check for deprecated options check_deprecated_options(&matches, &diag); - let to_check = matches.opt_strs("theme-checker"); + let to_check = matches.opt_strs("check-theme"); if !to_check.is_empty() { let paths = theme::load_css_paths(static_files::themes::LIGHT.as_bytes()); let mut errors = 0; - println!("rustdoc: [theme-checker] Starting tests!"); + println!("rustdoc: [check-theme] Starting tests! (Ignoring all other arguments)"); for theme_file in to_check.iter() { print!(" - Checking \"{}\"...", theme_file); let (success, differences) = theme::test_theme_against(theme_file, &paths, &diag); @@ -378,7 +378,7 @@ impl Options { default theme", theme_s)) .warn("the theme may appear incorrect when loaded") .help(&format!("to see what rules are missing, call `rustdoc \ - --theme-checker \"{}\"`", theme_s)) + --check-theme \"{}\"`", theme_s)) .emit(); } themes.push(theme_file); From 8f44c604d2586220aea497b22153290e2505ab36 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 30 Jun 2019 19:24:32 +0200 Subject: [PATCH 08/18] Rename theme-checker option to check-theme --- src/doc/rustdoc/src/command-line-arguments.md | 4 ++-- src/doc/rustdoc/src/unstable-features.md | 6 +++--- src/librustdoc/html/static_files.rs | 2 +- src/librustdoc/lib.rs | 4 ++-- src/tools/rustdoc-themes/main.rs | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/doc/rustdoc/src/command-line-arguments.md b/src/doc/rustdoc/src/command-line-arguments.md index 2c25baf373ed2..48fd8272d24f3 100644 --- a/src/doc/rustdoc/src/command-line-arguments.md +++ b/src/doc/rustdoc/src/command-line-arguments.md @@ -368,7 +368,7 @@ you'll need to this flag as follows: $ rustdoc src/lib.rs --themes /path/to/your/theme/file.css ``` -### `theme-checker`: check if your themes implement all the required rules +### `check-theme`: check if your themes implement all the required rules This flag allows you to check if your themes implement the necessary CSS rules. To put it more simply, when adding a new theme, it needs to implements all the CSS rules present in the "light" @@ -377,5 +377,5 @@ CSS theme. You can use this flag like this: ```bash -$ rustdoc src/lib.rs --theme-checker /path/to/your/theme/file.css +$ rustdoc src/lib.rs --check-theme /path/to/your/theme/file.css ``` diff --git a/src/doc/rustdoc/src/unstable-features.md b/src/doc/rustdoc/src/unstable-features.md index f8be04a1087bf..ddb6e5910cb2e 100644 --- a/src/doc/rustdoc/src/unstable-features.md +++ b/src/doc/rustdoc/src/unstable-features.md @@ -304,14 +304,14 @@ $ rustdoc src/lib.rs -Z unstable-options --themes theme.css Giving this flag to `rustdoc` will make it copy your theme into the generated crate docs and enable it in the theme selector. Note that `rustdoc` will reject your theme file if it doesn't style -everything the "light" theme does. See `--theme-checker` below for details. +everything the "light" theme does. See `--check-theme` below for details. -### `--theme-checker`: verify theme CSS for validity +### `--check-theme`: verify theme CSS for validity Using this flag looks like this: ```bash -$ rustdoc -Z unstable-options --theme-checker theme.css +$ rustdoc -Z unstable-options --check-theme theme.css ``` Before including your theme in crate docs, `rustdoc` will compare all the CSS rules it contains diff --git a/src/librustdoc/html/static_files.rs b/src/librustdoc/html/static_files.rs index 3a2c24b1a967f..9fc1d76185fb7 100644 --- a/src/librustdoc/html/static_files.rs +++ b/src/librustdoc/html/static_files.rs @@ -59,7 +59,7 @@ pub static RUST_FAVICON: &'static [u8] = include_bytes!("static/favicon.ico"); /// The built-in themes given to every documentation site. pub mod themes { /// The "light" theme, selected by default when no setting is available. Used as the basis for - /// the `--theme-checker` functionality. + /// the `--check-theme` functionality. pub static LIGHT: &'static str = include_str!("static/themes/light.css"); /// The "dark" theme. diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 27bef5db2d6d2..03a0f34b39b33 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -256,8 +256,8 @@ fn opts() -> Vec { "additional themes which will be added to the generated docs", "FILES") }), - stable("theme-checker", |o| { - o.optmulti("", "theme-checker", + stable("check-theme", |o| { + o.optmulti("", "check-theme", "check if given theme is valid", "FILES") }), diff --git a/src/tools/rustdoc-themes/main.rs b/src/tools/rustdoc-themes/main.rs index 616b5444832c1..b5be14fb41834 100644 --- a/src/tools/rustdoc-themes/main.rs +++ b/src/tools/rustdoc-themes/main.rs @@ -39,7 +39,7 @@ fn main() { exit(1); } let status = Command::new(rustdoc_bin) - .args(&["-Z", "unstable-options", "--theme-checker"]) + .args(&["-Z", "unstable-options", "--check-theme"]) .args(&themes) .status() .expect("failed to execute child"); From 6f2d1f51eb43bcf555a1b3b71998eb7f18bd87de Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 26 Jul 2019 10:15:23 +0200 Subject: [PATCH 09/18] Fix typos Co-Authored-By: Oliver Middleton --- src/doc/rustdoc/src/command-line-arguments.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/rustdoc/src/command-line-arguments.md b/src/doc/rustdoc/src/command-line-arguments.md index 48fd8272d24f3..5a0a8f767442f 100644 --- a/src/doc/rustdoc/src/command-line-arguments.md +++ b/src/doc/rustdoc/src/command-line-arguments.md @@ -361,8 +361,8 @@ the given edition as well. As with `rustc`, the default edition that `rustdoc` w ## `themes`: add more themes to generated documentation -By default, `rustdoc` only provides the "dark" and light" themes. If you want to add new ones, -you'll need to this flag as follows: +By default, `rustdoc` only provides the "dark" and "light" themes. If you want to add new ones, +you'll need to use this flag as follows: ```bash $ rustdoc src/lib.rs --themes /path/to/your/theme/file.css From bbfd63c89afe091fa9ec75bba0a5721d153d78f3 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 21 Aug 2019 15:48:26 +0200 Subject: [PATCH 10/18] Improve documentation, add checks for themes option arguments, make sure the themes file names are js compatible --- src/doc/rustdoc/src/command-line-arguments.md | 5 ++++- src/librustdoc/config.rs | 8 +++++++- src/librustdoc/html/render.rs | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/doc/rustdoc/src/command-line-arguments.md b/src/doc/rustdoc/src/command-line-arguments.md index 5a0a8f767442f..1f4584ec5645d 100644 --- a/src/doc/rustdoc/src/command-line-arguments.md +++ b/src/doc/rustdoc/src/command-line-arguments.md @@ -368,6 +368,9 @@ you'll need to use this flag as follows: $ rustdoc src/lib.rs --themes /path/to/your/theme/file.css ``` +Note that the theme's name will be the file name without its extension. So if you pass +`/path/to/your/theme/file.css` as theme, then the theme's name will be `file`. + ### `check-theme`: check if your themes implement all the required rules This flag allows you to check if your themes implement the necessary CSS rules. To put it more @@ -377,5 +380,5 @@ CSS theme. You can use this flag like this: ```bash -$ rustdoc src/lib.rs --check-theme /path/to/your/theme/file.css +$ rustdoc --check-theme /path/to/your/theme/file.css ``` diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 1f7f87354652f..38e0e34be61d4 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -1,4 +1,5 @@ use std::collections::BTreeMap; +use std::ffi::OsStr; use std::fmt; use std::path::PathBuf; @@ -369,9 +370,14 @@ impl Options { .emit(); return Err(1); } + if theme_file.extension() != Some(OsStr::new("css")) { + diag.struct_err(&format!("invalid file: \"{}\": expected CSS file", theme_s)) + .emit(); + return Err(1); + } let (success, ret) = theme::test_theme_against(&theme_file, &paths, &diag); if !success { - diag.struct_warn(&format!("error loading theme file: \"{}\"", theme_s)).emit(); + diag.struct_err(&format!("error loading theme file: \"{}\"", theme_s)).emit(); return Err(1); } else if !ret.is_empty() { diag.struct_warn(&format!("theme file \"{}\" is missing CSS rules from the \ diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 7eb49ead52720..60bb159c45fc7 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -645,7 +645,7 @@ themePicker.onblur = handleThemeButtonsBlur; themes.appendChild(but); }});"#, themes.iter() - .map(|s| format!("\"{}\"", s)) + .map(|s| format!("\"{}\"", s.replace("\\", "\\\\").replace("\"", "\\\""))) .collect::>() .join(",")); write(cx.dst.join(&format!("theme{}.js", cx.shared.resource_suffix)), From 7cbf31aa04679b6a9ccf7b19f9752be8a65e0245 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 14 Sep 2019 17:43:10 +0200 Subject: [PATCH 11/18] rename check-theme option into check-themes --- src/librustdoc/config.rs | 6 +++--- src/librustdoc/html/render.rs | 7 ++----- src/librustdoc/html/static_files.rs | 2 +- src/librustdoc/lib.rs | 4 ++-- src/tools/rustdoc-themes/main.rs | 2 +- 5 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 38e0e34be61d4..85feb89d7d5dc 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -282,12 +282,12 @@ impl Options { // check for deprecated options check_deprecated_options(&matches, &diag); - let to_check = matches.opt_strs("check-theme"); + let to_check = matches.opt_strs("check-themes"); if !to_check.is_empty() { let paths = theme::load_css_paths(static_files::themes::LIGHT.as_bytes()); let mut errors = 0; - println!("rustdoc: [check-theme] Starting tests! (Ignoring all other arguments)"); + println!("rustdoc: [check-themes] Starting tests! (Ignoring all other arguments)"); for theme_file in to_check.iter() { print!(" - Checking \"{}\"...", theme_file); let (success, differences) = theme::test_theme_against(theme_file, &paths, &diag); @@ -384,7 +384,7 @@ impl Options { default theme", theme_s)) .warn("the theme may appear incorrect when loaded") .help(&format!("to see what rules are missing, call `rustdoc \ - --check-theme \"{}\"`", theme_s)) + --check-themes \"{}\"`", theme_s)) .emit(); } themes.push(theme_file); diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 60bb159c45fc7..dda4b024bcea5 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -635,7 +635,7 @@ function handleThemeButtonsBlur(e) {{ themePicker.onclick = switchThemeButtonState; themePicker.onblur = handleThemeButtonsBlur; -[{}].forEach(function(item) {{ +{}.forEach(function(item) {{ var but = document.createElement('button'); but.innerHTML = item; but.onclick = function(el) {{ @@ -644,10 +644,7 @@ themePicker.onblur = handleThemeButtonsBlur; but.onblur = handleThemeButtonsBlur; themes.appendChild(but); }});"#, - themes.iter() - .map(|s| format!("\"{}\"", s.replace("\\", "\\\\").replace("\"", "\\\""))) - .collect::>() - .join(",")); + as_json(&themes)); write(cx.dst.join(&format!("theme{}.js", cx.shared.resource_suffix)), theme_js.as_bytes() )?; diff --git a/src/librustdoc/html/static_files.rs b/src/librustdoc/html/static_files.rs index 9fc1d76185fb7..8702ba224db56 100644 --- a/src/librustdoc/html/static_files.rs +++ b/src/librustdoc/html/static_files.rs @@ -59,7 +59,7 @@ pub static RUST_FAVICON: &'static [u8] = include_bytes!("static/favicon.ico"); /// The built-in themes given to every documentation site. pub mod themes { /// The "light" theme, selected by default when no setting is available. Used as the basis for - /// the `--check-theme` functionality. + /// the `--check-themes` functionality. pub static LIGHT: &'static str = include_str!("static/themes/light.css"); /// The "dark" theme. diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 03a0f34b39b33..6241ae7a3bbb9 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -256,8 +256,8 @@ fn opts() -> Vec { "additional themes which will be added to the generated docs", "FILES") }), - stable("check-theme", |o| { - o.optmulti("", "check-theme", + stable("check-themes", |o| { + o.optmulti("", "check-themes", "check if given theme is valid", "FILES") }), diff --git a/src/tools/rustdoc-themes/main.rs b/src/tools/rustdoc-themes/main.rs index b5be14fb41834..fb0c9d7d4e0c4 100644 --- a/src/tools/rustdoc-themes/main.rs +++ b/src/tools/rustdoc-themes/main.rs @@ -39,7 +39,7 @@ fn main() { exit(1); } let status = Command::new(rustdoc_bin) - .args(&["-Z", "unstable-options", "--check-theme"]) + .args(&["-Z", "unstable-options", "--check-themes"]) .args(&themes) .status() .expect("failed to execute child"); From 685b63a163e7a976ee3d304829647f4e22ed4071 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 14 Sep 2019 17:43:19 +0200 Subject: [PATCH 12/18] remove unstable docs --- src/doc/rustdoc/src/command-line-arguments.md | 4 ++-- src/doc/rustdoc/src/unstable-features.md | 24 ------------------- 2 files changed, 2 insertions(+), 26 deletions(-) diff --git a/src/doc/rustdoc/src/command-line-arguments.md b/src/doc/rustdoc/src/command-line-arguments.md index 1f4584ec5645d..64eaf5282414b 100644 --- a/src/doc/rustdoc/src/command-line-arguments.md +++ b/src/doc/rustdoc/src/command-line-arguments.md @@ -371,7 +371,7 @@ $ rustdoc src/lib.rs --themes /path/to/your/theme/file.css Note that the theme's name will be the file name without its extension. So if you pass `/path/to/your/theme/file.css` as theme, then the theme's name will be `file`. -### `check-theme`: check if your themes implement all the required rules +### `check-themes`: check if your themes implement all the required rules This flag allows you to check if your themes implement the necessary CSS rules. To put it more simply, when adding a new theme, it needs to implements all the CSS rules present in the "light" @@ -380,5 +380,5 @@ CSS theme. You can use this flag like this: ```bash -$ rustdoc --check-theme /path/to/your/theme/file.css +$ rustdoc --check-themes /path/to/your/theme/file.css ``` diff --git a/src/doc/rustdoc/src/unstable-features.md b/src/doc/rustdoc/src/unstable-features.md index ddb6e5910cb2e..a48526d39fd0a 100644 --- a/src/doc/rustdoc/src/unstable-features.md +++ b/src/doc/rustdoc/src/unstable-features.md @@ -294,30 +294,6 @@ some consideration for their stability, and names that end in a number). Giving `rustdoc` will disable this sorting and instead make it print the items in the order they appear in the source. -### `--themes`: provide additional themes - -Using this flag looks like this: - -```bash -$ rustdoc src/lib.rs -Z unstable-options --themes theme.css -``` - -Giving this flag to `rustdoc` will make it copy your theme into the generated crate docs and enable -it in the theme selector. Note that `rustdoc` will reject your theme file if it doesn't style -everything the "light" theme does. See `--check-theme` below for details. - -### `--check-theme`: verify theme CSS for validity - -Using this flag looks like this: - -```bash -$ rustdoc -Z unstable-options --check-theme theme.css -``` - -Before including your theme in crate docs, `rustdoc` will compare all the CSS rules it contains -against the "light" theme included by default. Using this flag will allow you to see which rules are -missing if `rustdoc` rejects your theme. - ### `--resource-suffix`: modifying the name of CSS/JavaScript in crate docs Using this flag looks like this: From 8f9014d98f88c57dbd786a3b9ac86c5bfcdcb401 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 22 Sep 2019 22:35:25 +0200 Subject: [PATCH 13/18] Rename rustdoc options --themes and --check-themes to --theme and --check-theme --- src/doc/rustdoc/src/command-line-arguments.md | 8 ++++---- src/librustdoc/config.rs | 12 ++++++------ src/librustdoc/html/static_files.rs | 2 +- src/librustdoc/lib.rs | 8 ++++---- src/test/run-make-fulldeps/rustdoc-themes/Makefile | 2 +- src/tools/rustdoc-themes/main.rs | 7 +++++-- 6 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/doc/rustdoc/src/command-line-arguments.md b/src/doc/rustdoc/src/command-line-arguments.md index 64eaf5282414b..c935699abb087 100644 --- a/src/doc/rustdoc/src/command-line-arguments.md +++ b/src/doc/rustdoc/src/command-line-arguments.md @@ -359,19 +359,19 @@ This flag allows `rustdoc` to treat your rust code as the given edition. It will the given edition as well. As with `rustc`, the default edition that `rustdoc` will use is `2015` (the first edition). -## `themes`: add more themes to generated documentation +## `theme`: add more themes to generated documentation By default, `rustdoc` only provides the "dark" and "light" themes. If you want to add new ones, you'll need to use this flag as follows: ```bash -$ rustdoc src/lib.rs --themes /path/to/your/theme/file.css +$ rustdoc src/lib.rs --theme /path/to/your/theme/file.css ``` Note that the theme's name will be the file name without its extension. So if you pass `/path/to/your/theme/file.css` as theme, then the theme's name will be `file`. -### `check-themes`: check if your themes implement all the required rules +### `check-theme`: check if your themes implement all the required rules This flag allows you to check if your themes implement the necessary CSS rules. To put it more simply, when adding a new theme, it needs to implements all the CSS rules present in the "light" @@ -380,5 +380,5 @@ CSS theme. You can use this flag like this: ```bash -$ rustdoc --check-themes /path/to/your/theme/file.css +$ rustdoc --check-theme /path/to/your/theme/file.css ``` diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 85feb89d7d5dc..d48416d4177b1 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -282,12 +282,12 @@ impl Options { // check for deprecated options check_deprecated_options(&matches, &diag); - let to_check = matches.opt_strs("check-themes"); + let to_check = matches.opt_strs("check-theme"); if !to_check.is_empty() { let paths = theme::load_css_paths(static_files::themes::LIGHT.as_bytes()); let mut errors = 0; - println!("rustdoc: [check-themes] Starting tests! (Ignoring all other arguments)"); + println!("rustdoc: [check-theme] Starting tests! (Ignoring all other arguments)"); for theme_file in to_check.iter() { print!(" - Checking \"{}\"...", theme_file); let (success, differences) = theme::test_theme_against(theme_file, &paths, &diag); @@ -358,15 +358,15 @@ impl Options { } let mut themes = Vec::new(); - if matches.opt_present("themes") { + if matches.opt_present("theme") { let paths = theme::load_css_paths(static_files::themes::LIGHT.as_bytes()); - for (theme_file, theme_s) in matches.opt_strs("themes") + for (theme_file, theme_s) in matches.opt_strs("theme") .iter() .map(|s| (PathBuf::from(&s), s.to_owned())) { if !theme_file.is_file() { diag.struct_err(&format!("invalid file: \"{}\"", theme_s)) - .help("option --themes arguments must all be files") + .help("option --theme arguments must all be files") .emit(); return Err(1); } @@ -384,7 +384,7 @@ impl Options { default theme", theme_s)) .warn("the theme may appear incorrect when loaded") .help(&format!("to see what rules are missing, call `rustdoc \ - --check-themes \"{}\"`", theme_s)) + --check-theme \"{}\"`", theme_s)) .emit(); } themes.push(theme_file); diff --git a/src/librustdoc/html/static_files.rs b/src/librustdoc/html/static_files.rs index 8702ba224db56..9fc1d76185fb7 100644 --- a/src/librustdoc/html/static_files.rs +++ b/src/librustdoc/html/static_files.rs @@ -59,7 +59,7 @@ pub static RUST_FAVICON: &'static [u8] = include_bytes!("static/favicon.ico"); /// The built-in themes given to every documentation site. pub mod themes { /// The "light" theme, selected by default when no setting is available. Used as the basis for - /// the `--check-themes` functionality. + /// the `--check-theme` functionality. pub static LIGHT: &'static str = include_str!("static/themes/light.css"); /// The "dark" theme. diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 6241ae7a3bbb9..bdb45f888d254 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -251,13 +251,13 @@ fn opts() -> Vec { o.optflag("", "sort-modules-by-appearance", "sort modules by where they appear in the \ program, rather than alphabetically") }), - stable("themes", |o| { - o.optmulti("", "themes", + stable("theme", |o| { + o.optmulti("", "theme", "additional themes which will be added to the generated docs", "FILES") }), - stable("check-themes", |o| { - o.optmulti("", "check-themes", + stable("check-theme", |o| { + o.optmulti("", "check-theme", "check if given theme is valid", "FILES") }), diff --git a/src/test/run-make-fulldeps/rustdoc-themes/Makefile b/src/test/run-make-fulldeps/rustdoc-themes/Makefile index a4536e77bd7b1..f5a471e66e573 100644 --- a/src/test/run-make-fulldeps/rustdoc-themes/Makefile +++ b/src/test/run-make-fulldeps/rustdoc-themes/Makefile @@ -6,5 +6,5 @@ OUTPUT_DIR := "$(TMPDIR)/rustdoc-themes" all: cp $(S)/src/librustdoc/html/static/themes/light.css $(TMPDIR)/test.css - $(RUSTDOC) -o $(OUTPUT_DIR) foo.rs --themes $(TMPDIR)/test.css + $(RUSTDOC) -o $(OUTPUT_DIR) foo.rs --theme $(TMPDIR)/test.css $(HTMLDOCCK) $(OUTPUT_DIR) foo.rs diff --git a/src/tools/rustdoc-themes/main.rs b/src/tools/rustdoc-themes/main.rs index fb0c9d7d4e0c4..87c1de3e715e1 100644 --- a/src/tools/rustdoc-themes/main.rs +++ b/src/tools/rustdoc-themes/main.rs @@ -38,9 +38,12 @@ fn main() { eprintln!("No theme found in \"{}\"...", themes_folder); exit(1); } + let arg_name = "--check-theme".to_owned(); let status = Command::new(rustdoc_bin) - .args(&["-Z", "unstable-options", "--check-themes"]) - .args(&themes) + .args(&["-Z", "unstable-options"]) + .args(&themes.iter() + .flat_map(|t| vec![&arg_name, t].into_iter()) + .collect::>()) .status() .expect("failed to execute child"); if !status.success() { From 530d866aef047fa0f20a655676fd0b3ff4cbf86b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 10 Oct 2019 12:09:01 +0200 Subject: [PATCH 14/18] Apply review comments --- src/doc/rustdoc/src/command-line-arguments.md | 2 +- src/librustdoc/html/layout.rs | 10 ++++++---- src/librustdoc/html/render.rs | 6 ++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/doc/rustdoc/src/command-line-arguments.md b/src/doc/rustdoc/src/command-line-arguments.md index c935699abb087..40bd6f43c61f0 100644 --- a/src/doc/rustdoc/src/command-line-arguments.md +++ b/src/doc/rustdoc/src/command-line-arguments.md @@ -374,7 +374,7 @@ Note that the theme's name will be the file name without its extension. So if yo ### `check-theme`: check if your themes implement all the required rules This flag allows you to check if your themes implement the necessary CSS rules. To put it more -simply, when adding a new theme, it needs to implements all the CSS rules present in the "light" +simply, when adding a new theme, it needs to implement all the CSS rules present in the "light" CSS theme. You can use this flag like this: diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index 697dee0216e3b..8249e69e9a74f 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -1,6 +1,7 @@ use std::path::PathBuf; use crate::externalfiles::ExternalHtml; +use crate::html::escape::Escape; use crate::html::render::ensure_trailing_slash; use crate::html::format::{Buffer, Print}; @@ -166,10 +167,11 @@ pub fn render( themes = themes.iter() .filter_map(|t| t.file_stem()) .filter_map(|t| t.to_str()) - .map(|t| format!(r#""#, - static_root_path, - t, - page.resource_suffix)) + .map(|t| format!(r#""#, + Escape(&format!("{}{}{}", + static_root_path, + t, + page.resource_suffix)))) .collect::(), suffix=page.resource_suffix, static_extra_scripts=page.static_extra_scripts.iter().map(|e| { diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index dda4b024bcea5..1207c5e3bc58d 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -569,9 +569,7 @@ fn write_shared( let content = try_err!(fs::read(&entry), &entry); let theme = try_none!(try_none!(entry.file_stem(), &entry).to_str(), &entry); let extension = try_none!(try_none!(entry.extension(), &entry).to_str(), &entry); - cx.shared.fs.write( - cx.path(&format!("{}.{}", Escape(theme), extension)), - content.as_slice())?; + cx.shared.fs.write(cx.path(&format!("{}.{}", theme, extension)), content.as_slice())?; themes.insert(theme.to_owned()); } @@ -637,7 +635,7 @@ themePicker.onclick = switchThemeButtonState; themePicker.onblur = handleThemeButtonsBlur; {}.forEach(function(item) {{ var but = document.createElement('button'); - but.innerHTML = item; + but.textContent = item; but.onclick = function(el) {{ switchTheme(currentTheme, mainTheme, item, true); }}; From b004a50f7395202bb6822f4ec8a098fdf9c7456a Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 12 Oct 2019 11:53:02 +0200 Subject: [PATCH 15/18] remove -Z option from rustdoc theme checker tool --- src/tools/rustdoc-themes/main.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/tools/rustdoc-themes/main.rs b/src/tools/rustdoc-themes/main.rs index 87c1de3e715e1..a549b0d0efaac 100644 --- a/src/tools/rustdoc-themes/main.rs +++ b/src/tools/rustdoc-themes/main.rs @@ -40,7 +40,6 @@ fn main() { } let arg_name = "--check-theme".to_owned(); let status = Command::new(rustdoc_bin) - .args(&["-Z", "unstable-options"]) .args(&themes.iter() .flat_map(|t| vec![&arg_name, t].into_iter()) .collect::>()) From 71c7dace89959e185948e91b902ffb803aa8d223 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 17 Oct 2019 14:26:21 +0200 Subject: [PATCH 16/18] improve error messages and documentation --- src/doc/rustdoc/src/command-line-arguments.md | 34 ++++++++++++------- src/librustdoc/config.rs | 6 ++-- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/doc/rustdoc/src/command-line-arguments.md b/src/doc/rustdoc/src/command-line-arguments.md index 40bd6f43c61f0..2e32ce31ecae0 100644 --- a/src/doc/rustdoc/src/command-line-arguments.md +++ b/src/doc/rustdoc/src/command-line-arguments.md @@ -359,26 +359,34 @@ This flag allows `rustdoc` to treat your rust code as the given edition. It will the given edition as well. As with `rustc`, the default edition that `rustdoc` will use is `2015` (the first edition). -## `theme`: add more themes to generated documentation +## `--theme`: add a theme to the documentation output -By default, `rustdoc` only provides the "dark" and "light" themes. If you want to add new ones, -you'll need to use this flag as follows: +Using this flag looks like this: ```bash -$ rustdoc src/lib.rs --theme /path/to/your/theme/file.css +$ rustdoc src/lib.rs --theme /path/to/your/custom-theme.css ``` -Note that the theme's name will be the file name without its extension. So if you pass -`/path/to/your/theme/file.css` as theme, then the theme's name will be `file`. - -### `check-theme`: check if your themes implement all the required rules +`rustdoc`'s default output includes two themes: `light` (the default) and +`dark`. This flag allows you to add custom themes to the output. Giving a CSS +file to this flag adds it to your documentation as an additional theme choice. +The theme's name is determined by its filename; a theme file named +`custom-theme.css` will add a theme named `custom-theme` to the documentation. -This flag allows you to check if your themes implement the necessary CSS rules. To put it more -simply, when adding a new theme, it needs to implement all the CSS rules present in the "light" -CSS theme. +## `--check-theme`: verify custom themes against the default theme -You can use this flag like this: +Using this flag looks like this: ```bash -$ rustdoc --check-theme /path/to/your/theme/file.css +$ rustdoc --check-theme /path/to/your/custom-theme.css ``` + +While `rustdoc`'s HTML output is more-or-less consistent between versions, there +is no guarantee that a theme file will have the same effect. The `--theme` flag +will still allow you to add the theme to your documentation, but to ensure that +your theme works as expected, you can use this flag to verify that it implements +the same CSS rules as the official `light` theme. + +`--check-theme` is a separate mode in `rustdoc`. When `rustdoc` sees the +`--check-theme` flag, it discards all other flags and only performs the CSS rule +comparison operation. diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index d48416d4177b1..cdb1a1f6997c9 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -365,13 +365,13 @@ impl Options { .iter() .map(|s| (PathBuf::from(&s), s.to_owned())) { if !theme_file.is_file() { - diag.struct_err(&format!("invalid file: \"{}\"", theme_s)) - .help("option --theme arguments must all be files") + diag.struct_err(&format!("invalid argument: \"{}\"", theme_s)) + .help("arguments to --theme must be files") .emit(); return Err(1); } if theme_file.extension() != Some(OsStr::new("css")) { - diag.struct_err(&format!("invalid file: \"{}\": expected CSS file", theme_s)) + diag.struct_err(&format!("invalid argument: \"{}\"", theme_s)) .emit(); return Err(1); } From a9e8d4c0c523ff4da185084790fa39cdc7ece1f3 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 18 Nov 2019 16:49:44 +0100 Subject: [PATCH 17/18] Remove redundant html check --- src/test/run-make-fulldeps/rustdoc-themes/Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/run-make-fulldeps/rustdoc-themes/Makefile b/src/test/run-make-fulldeps/rustdoc-themes/Makefile index f5a471e66e573..4d80c5f3fc45e 100644 --- a/src/test/run-make-fulldeps/rustdoc-themes/Makefile +++ b/src/test/run-make-fulldeps/rustdoc-themes/Makefile @@ -7,4 +7,3 @@ OUTPUT_DIR := "$(TMPDIR)/rustdoc-themes" all: cp $(S)/src/librustdoc/html/static/themes/light.css $(TMPDIR)/test.css $(RUSTDOC) -o $(OUTPUT_DIR) foo.rs --theme $(TMPDIR)/test.css - $(HTMLDOCCK) $(OUTPUT_DIR) foo.rs From 45b83c9164c2462503c2cd381a4b1b85f75fa107 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 18 Nov 2019 18:53:45 +0100 Subject: [PATCH 18/18] Fix Makefile themes check --- src/test/run-make-fulldeps/rustdoc-themes/Makefile | 1 + src/test/run-make-fulldeps/tools.mk | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/run-make-fulldeps/rustdoc-themes/Makefile b/src/test/run-make-fulldeps/rustdoc-themes/Makefile index 4d80c5f3fc45e..f5a471e66e573 100644 --- a/src/test/run-make-fulldeps/rustdoc-themes/Makefile +++ b/src/test/run-make-fulldeps/rustdoc-themes/Makefile @@ -7,3 +7,4 @@ OUTPUT_DIR := "$(TMPDIR)/rustdoc-themes" all: cp $(S)/src/librustdoc/html/static/themes/light.css $(TMPDIR)/test.css $(RUSTDOC) -o $(OUTPUT_DIR) foo.rs --theme $(TMPDIR)/test.css + $(HTMLDOCCK) $(OUTPUT_DIR) foo.rs diff --git a/src/test/run-make-fulldeps/tools.mk b/src/test/run-make-fulldeps/tools.mk index 20a5e8e64225d..48fd3ff724634 100644 --- a/src/test/run-make-fulldeps/tools.mk +++ b/src/test/run-make-fulldeps/tools.mk @@ -15,7 +15,7 @@ RUSTC := $(RUSTC) -Clinker=$(RUSTC_LINKER) RUSTDOC := $(RUSTDOC) -Clinker=$(RUSTC_LINKER) endif #CC := $(CC) -L $(TMPDIR) -HTMLDOCCK := $(PYTHON) $(S)/src/etc/htmldocck.py +HTMLDOCCK := '$(PYTHON)' '$(S)/src/etc/htmldocck.py' CGREP := "$(S)/src/etc/cat-and-grep.sh" # This is the name of the binary we will generate and run; use this