Skip to content

Commit

Permalink
Improve documentation, add checks for themes option arguments, make s…
Browse files Browse the repository at this point in the history
…ure the themes file names are js compatible
  • Loading branch information
GuillaumeGomez committed Nov 18, 2019
1 parent 6f2d1f5 commit bbfd63c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/doc/rustdoc/src/command-line-arguments.md
Expand Up @@ -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
Expand All @@ -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
```
8 changes: 7 additions & 1 deletion src/librustdoc/config.rs
@@ -1,4 +1,5 @@
use std::collections::BTreeMap;
use std::ffi::OsStr;
use std::fmt;
use std::path::PathBuf;

Expand Down Expand Up @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/render.rs
Expand Up @@ -645,7 +645,7 @@ themePicker.onblur = handleThemeButtonsBlur;
themes.appendChild(but);
}});"#,
themes.iter()
.map(|s| format!("\"{}\"", s))
.map(|s| format!("\"{}\"", s.replace("\\", "\\\\").replace("\"", "\\\"")))
.collect::<Vec<String>>()
.join(","));
write(cx.dst.join(&format!("theme{}.js", cx.shared.resource_suffix)),
Expand Down

0 comments on commit bbfd63c

Please sign in to comment.