1
Fork 0

Rename rustdoc options --themes and --check-themes to --theme and --check-theme

This commit is contained in:
Guillaume Gomez 2019-09-22 22:35:25 +02:00
parent 685b63a163
commit 8f9014d98f
6 changed files with 21 additions and 18 deletions

View file

@ -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 given edition as well. As with `rustc`, the default edition that `rustdoc` will use is `2015`
(the first edition). (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, 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: you'll need to use this flag as follows:
```bash ```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 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`. `/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 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 implements all the CSS rules present in the "light"
@ -380,5 +380,5 @@ CSS theme.
You can use this flag like this: You can use this flag like this:
```bash ```bash
$ rustdoc --check-themes /path/to/your/theme/file.css $ rustdoc --check-theme /path/to/your/theme/file.css
``` ```

View file

@ -282,12 +282,12 @@ impl Options {
// check for deprecated options // check for deprecated options
check_deprecated_options(&matches, &diag); 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() { if !to_check.is_empty() {
let paths = theme::load_css_paths(static_files::themes::LIGHT.as_bytes()); let paths = theme::load_css_paths(static_files::themes::LIGHT.as_bytes());
let mut errors = 0; 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() { for theme_file in to_check.iter() {
print!(" - Checking \"{}\"...", theme_file); print!(" - Checking \"{}\"...", theme_file);
let (success, differences) = theme::test_theme_against(theme_file, &paths, &diag); let (success, differences) = theme::test_theme_against(theme_file, &paths, &diag);
@ -358,15 +358,15 @@ impl Options {
} }
let mut themes = Vec::new(); 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()); 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() .iter()
.map(|s| (PathBuf::from(&s), s.to_owned())) { .map(|s| (PathBuf::from(&s), s.to_owned())) {
if !theme_file.is_file() { if !theme_file.is_file() {
diag.struct_err(&format!("invalid file: \"{}\"", theme_s)) 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(); .emit();
return Err(1); return Err(1);
} }
@ -384,7 +384,7 @@ impl Options {
default theme", theme_s)) default theme", theme_s))
.warn("the theme may appear incorrect when loaded") .warn("the theme may appear incorrect when loaded")
.help(&format!("to see what rules are missing, call `rustdoc \ .help(&format!("to see what rules are missing, call `rustdoc \
--check-themes \"{}\"`", theme_s)) --check-theme \"{}\"`", theme_s))
.emit(); .emit();
} }
themes.push(theme_file); themes.push(theme_file);

View file

@ -59,7 +59,7 @@ pub static RUST_FAVICON: &'static [u8] = include_bytes!("static/favicon.ico");
/// The built-in themes given to every documentation site. /// The built-in themes given to every documentation site.
pub mod themes { pub mod themes {
/// The "light" theme, selected by default when no setting is available. Used as the basis for /// 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"); pub static LIGHT: &'static str = include_str!("static/themes/light.css");
/// The "dark" theme. /// The "dark" theme.

View file

@ -251,13 +251,13 @@ fn opts() -> Vec<RustcOptGroup> {
o.optflag("", "sort-modules-by-appearance", "sort modules by where they appear in the \ o.optflag("", "sort-modules-by-appearance", "sort modules by where they appear in the \
program, rather than alphabetically") program, rather than alphabetically")
}), }),
stable("themes", |o| { stable("theme", |o| {
o.optmulti("", "themes", o.optmulti("", "theme",
"additional themes which will be added to the generated docs", "additional themes which will be added to the generated docs",
"FILES") "FILES")
}), }),
stable("check-themes", |o| { stable("check-theme", |o| {
o.optmulti("", "check-themes", o.optmulti("", "check-theme",
"check if given theme is valid", "check if given theme is valid",
"FILES") "FILES")
}), }),

View file

@ -6,5 +6,5 @@ OUTPUT_DIR := "$(TMPDIR)/rustdoc-themes"
all: all:
cp $(S)/src/librustdoc/html/static/themes/light.css $(TMPDIR)/test.css 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 $(HTMLDOCCK) $(OUTPUT_DIR) foo.rs

View file

@ -38,9 +38,12 @@ fn main() {
eprintln!("No theme found in \"{}\"...", themes_folder); eprintln!("No theme found in \"{}\"...", themes_folder);
exit(1); exit(1);
} }
let arg_name = "--check-theme".to_owned();
let status = Command::new(rustdoc_bin) let status = Command::new(rustdoc_bin)
.args(&["-Z", "unstable-options", "--check-themes"]) .args(&["-Z", "unstable-options"])
.args(&themes) .args(&themes.iter()
.flat_map(|t| vec![&arg_name, t].into_iter())
.collect::<Vec<_>>())
.status() .status()
.expect("failed to execute child"); .expect("failed to execute child");
if !status.success() { if !status.success() {