Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add resource-suffix option for rustdoc #48511

Merged

Conversation

GuillaumeGomez
Copy link
Member

Alternative version of #48442.

cc @onur

r? @QuietMisdreavus

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 24, 2018
@onur
Copy link
Member

onur commented Mar 1, 2018

Hi @GuillaumeGomez this is great and it will fix docs.rs breakage and save me from a lot of trouble in future. Only javascript portion of theme picker needs some adjustments now.

  1. themes in render.rs should have suffix as well in order to generate correct javascript.
  2. switchTheme function in storage should use rustdoc-SUFFIX.css instead of plain rustdoc.css.

Some example I used to make theme-picker work with --resource-suffix option. I used RUSTDOCFLAGS="-Z unstable-options --resource-suffix -EXAMPLE" cargo doc to generate documentation and here is the working version of javascript portion of this command:

switchTheme:

function switchTheme(styleElem, mainStyleElem, newTheme) {
    styleElem.href = mainStyleElem.href.replace("rustdoc-EXAMPLE.css", newTheme + ".css");
    updateLocalStorage('theme', newTheme);
}

theme-EXAMPLE.js:

["dark-EXAMPLE","main-EXAMPLE"].forEach(function(item) {
    var but = document.createElement('button');
    but.innerHTML = item;
    but.onclick = function(el) {
        switchTheme(currentTheme, mainTheme, item);
    };
    themes.appendChild(but);
});

@GuillaumeGomez GuillaumeGomez force-pushed the rustdoc-resource-suffix branch 4 times, most recently from 17c234c to 2497447 Compare March 1, 2018 22:51
@GuillaumeGomez
Copy link
Member Author

Apparently it's all good for @onur. So therefore, I suppose it can get merged. cc @QuietMisdreavus

@GuillaumeGomez GuillaumeGomez mentioned this pull request Mar 3, 2018
@onur
Copy link
Member

onur commented Mar 3, 2018

Yes it's all good @GuillaumeGomez. I have some (most likely) unrelated tests failing on docs.rs. Trying to fix them.

Edit: fixed them, they are not related to this.

@GuillaumeGomez
Copy link
Member Author

Perfect, now we just need to hear back from @QuietMisdreavus!

Copy link
Member

@QuietMisdreavus QuietMisdreavus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took me a minute to figure out how the names would get displayed to the users in the theme picker. Since the resource suffix is added into the JS file separately, the theme picker names should stay the same (i.e. without the suffix) so i only have a few comments before i'm willing to sign off on this.

try_err!(fs::copy(css, out), css);
}
write(cx.dst.join("normalize.css"),
write(cx.dst.join(&format!("normalize{}.css", cx.shared.resource_suffix)),
include_bytes!("static/normalize.css"))?;
write(cx.dst.join("FiraSans-Regular.woff"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing the fonts and their copyright notices aren't relevant for wanting to switch the filenames out?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @onur

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to @onur from a conversation on IRC, it matters less for the fonts to handle it, since they're loaded from the CSS (which would need to also be processed to use the suffix), and they don't churn like the CSS/JS do. This is fine as-is.

{
let mut data = format!("var resourcesSuffix = \"{}\";\n",
cx.shared.resource_suffix).into_bytes();
data.extend_from_slice(include_bytes!("static/storage.js"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a Vec<u8> and include_bytes here instead of a String and include_str seems weird to me. I get that on the very next line it needs to be bytes for the write call, but i don't know how much we gain by sidesteppning the UTF-8 check on this extend call.

@@ -261,6 +261,11 @@ pub fn opts() -> Vec<RustcOptGroup> {
"check if given theme is valid",
"FILES")
}),
unstable("resource-suffix", |o| {
o.optopt("",
"resource-suffix", "suffix which will be added at the end of resource files",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems odd, both in verb tense and what we mean by "resource files". What about this?

suffix to add to CSS and JavaScript files, e.g. "main.css" will become "main-suffix.css"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It changed through the writing of this PR. Now we have an almost definitive version so it's more clear. I'll update to your sentence.

@QuietMisdreavus
Copy link
Member

r=me pending travis

@GuillaumeGomez
Copy link
Member Author

@bors: r=QuietMisdreavus

@bors
Copy link
Contributor

bors commented Mar 6, 2018

📌 Commit 831009f has been approved by QuietMisdreavus

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 6, 2018
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Mar 6, 2018
…fix, r=QuietMisdreavus

Add resource-suffix option for rustdoc

Alternative version of rust-lang#48442.

cc @onur

r? @QuietMisdreavus
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Mar 6, 2018
…fix, r=QuietMisdreavus

Add resource-suffix option for rustdoc

Alternative version of rust-lang#48442.

cc @onur

r? @QuietMisdreavus
alexcrichton added a commit to alexcrichton/rust that referenced this pull request Mar 7, 2018
…fix, r=QuietMisdreavus

Add resource-suffix option for rustdoc

Alternative version of rust-lang#48442.

cc @onur

r? @QuietMisdreavus
@bors
Copy link
Contributor

bors commented Mar 7, 2018

⌛ Testing commit 831009f with merge a012ad893062d107b305274a20d56c3a75c25bac...

@alexcrichton
Copy link
Member

@bors: retry

prioritizing rollup with this in it

bors added a commit that referenced this pull request Mar 7, 2018
Rollup of 9 pull requests

- Successful merges: #48511, #48549, #48618, #48624, #48651, #48698, #48778, #48787, #48802
- Failed merges: #48669, #48710
bors added a commit that referenced this pull request Mar 7, 2018
Rollup of 9 pull requests

- Successful merges: #48511, #48549, #48618, #48624, #48651, #48698, #48778, #48787, #48802
- Failed merges: #48669, #48710
bors added a commit that referenced this pull request Mar 7, 2018
Rollup of 9 pull requests

- Successful merges: #48511, #48549, #48618, #48624, #48651, #48698, #48778, #48787, #48802
- Failed merges: #48669, #48710
@alexcrichton alexcrichton merged commit 831009f into rust-lang:master Mar 8, 2018
@GuillaumeGomez GuillaumeGomez deleted the rustdoc-resource-suffix branch March 8, 2018 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants