Skip to content

Show configs from different versions on github pages #4221

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

Merged
merged 3 commits into from
Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ To enable unstable options, set `unstable_features = true` in `rustfmt.toml` or

Below you can find a detailed visual guide on all the supported configuration options of rustfmt.

**_Note that the below list reflects the configuration options available on the latest version of rustfmt in source control. Some newer options may not be available yet in a released version of rustfmt_**

**_Note that the below list reflects the configuration options available on the latest version of rustfmt in source control. Some newer options may not be available yet in a released version of rustfmt._**

For version- and channel-specific configurations, please visit https://rust-lang.github.io/rustfmt/.
Copy link
Member

Choose a reason for hiding this comment

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

❤️


## `array_width`

Expand Down
95 changes: 56 additions & 39 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/3.0.1/github-markdown.css" />
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.js"></script>
<script src="https://unpkg.com/vue-async-computed@3.8.1"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.min.js"></script>
<style>
@media (max-width: 767px) {
Expand Down Expand Up @@ -59,60 +60,76 @@
<label for="stable">stable: </label>
<input type="checkbox" id="stable" v-model="shouldStable">
</div>
<div>
<label for="version">version: </label>
<select name="version" id="version" v-model="version">
<option v-for="option in versionOptions" v-bind:value="option">
{{ option }}
</option>
</select>
</div>
</div>
<div v-html="aboutHtml"></div>
<div v-html="configurationAboutHtml"></div>
<div v-html="outputHtml"></div>
</article>
</div>
<script>
const ConfigurationMdUrl = 'https://raw.githubusercontent.com/rust-lang/rustfmt/master/Configurations.md';
const RusfmtTagsUrl = 'https://api.github.com/repos/rust-lang/rustfmt/tags';
const UrlHash = window.location.hash.replace(/^#/, '');
new Vue({
el: '#app',
data() {
const configurationDescriptions = [];
configurationDescriptions.links = {};
return {
aboutHtml: '',
configurationAboutHtml: '',
searchCondition: UrlHash,
configurationDescriptions,
shouldStable: false
}
data: {
aboutHtml: '',
configurationAboutHtml: '',
configurationDescriptions: [],
searchCondition: UrlHash,
shouldStable: false,
version: 'master',
oldVersion: undefined,
versionOptions: ['master']
},
computed: {
outputHtml() {
asyncComputed: {
async outputHtml() {
if (this.version !== this.oldVersion) {
const ConfigurationMdUrl =
`https://raw.githubusercontent.com/rust-lang/rustfmt/${this.version}/Configurations.md`;
const res = await axios.get(ConfigurationMdUrl);
const {
about,
configurationAbout,
configurationDescriptions
} = parseMarkdownAst(res.data);
this.aboutHtml = marked.parser(about);
this.configurationAboutHtml = marked.parser(configurationAbout);
this.configurationDescriptions = configurationDescriptions;
this.oldVersion = this.version;
}

const ast = this.configurationDescriptions
.filter(({ head, text, stable }) => {

if (
text.includes(this.searchCondition) === false &&
head.includes(this.searchCondition) === false
) {
return false;
}
return (this.shouldStable)
? stable === true
: true;
})
.reduce((stack, { value }) => {
return stack.concat(value);
}, []);
.filter(({ head, text, stable }) => {
if (text.includes(this.searchCondition) === false &&
head.includes(this.searchCondition) === false) {
return false;
}
return (this.shouldStable)
? stable === true
: true;
})
.reduce((stack, { value }) => {
return stack.concat(value);
}, []);
ast.links = {};
return marked.parser(ast);
}
},
created: async function() {
const res = await axios.get(ConfigurationMdUrl);
const {
about,
configurationAbout,
configurationDescriptions
} = parseMarkdownAst(res.data);
this.aboutHtml = marked.parser(about);
this.configurationAboutHtml = marked.parser(configurationAbout);
this.configurationDescriptions = configurationDescriptions;
const {data: tags} = await axios.get(RusfmtTagsUrl);
const reMajorVersion = /v(\d+)/;
const tagOptions = tags
.map(tag => tag.name)
.filter(tag => tag.startsWith('v'));
this.versionOptions = this.versionOptions.concat(tagOptions);
},
mounted() {
if (UrlHash === '') return;
Expand Down Expand Up @@ -144,7 +161,7 @@
const lastIndex = stack.length - 1;
stack[lastIndex].push(next);
return stack;
},
},
[[]]);
});
}
Expand Down Expand Up @@ -181,7 +198,7 @@
configurationAbout, ...configurationDescriptions
] = configurations;
configurationAbout.value.links = {};

return {
about,
configurationAbout: configurationAbout.value,
Expand Down