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

Document specifying beautifier config file, use Docusaurus tabs for code #211

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions docs/options-for-beautifiers.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,17 @@ If the beautifier's configuration file is found then Unibeautify's own configura
This is useful when Unibeautify does not support an option and you want more control over a specific beautifier.

> Only certain beautifiers support the `prefer_beautifier_config` option. See the `Advanced` section on a beautifier's page to see what beautifier options are supported. For example, see the [PHP-CS-Fixer beautifier](/docs/beautifier-php-cs-fixer.html#advanced).

### Config File Path
You can also specify the absolute path to the beautifier's config file by putting a string in the `prefer_beautifier_config` option. It will otherwise look in the directory of the file being beautified, and if it doesn't find it there, will go to the parent directory.

```yaml
---
PHP: # Language
beautifiers: # Enable beautifiers
- PHP-CS-Fixer
PHP-CS-Fixer: # <------------------------ Beautifier options start here
prefer_beautifier_config: "path/to/beautifier/config/file"
PHP-CS-Fixer: # Executable options
path: "/absolute/path/to/php-cs-fixer"
```
41 changes: 3 additions & 38 deletions scripts/generate-docs/OptionsDoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,49 +195,15 @@ export default class OptionsDoc extends Doc {
),
).then(beautified => {
builder.header("Examples", 2);
builder.append(
'<div class="input-group languages-select"><div class="input-group-prepend">',
);
builder.append(
'<label class="input-group-text" for="languages-select">Select Language:</label>',
);
builder.append(
'</div><select class="custom-select" id="languages-select">',
);
let defaultDisplay: string;
let isDefault: boolean = true;
this.languages.forEach(language => {
const example = examplesForLanguages[language.name];
builder.append(
`<option ${
example && isDefault ? 'selected="selected"' : ""
} data-text="${
language.name
}" value="${language.name
Copy link
Member

Choose a reason for hiding this comment

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

@stevenzeck Before we had the direct links to select the appropriate tab: https://unibeautify.com/docs/option-end-with-newline.html?language=html

Now the similar link will no longer select the code tab: https://deploy-preview-211--unibeautify.netlify.com/docs/option-end-with-newline.html?language=html

I do want to continue to support this feature.

.toLowerCase()
.replace(/ /g, "")}">${language.name +
(example ? " *" : "")}</option>`,
);
if (example && isDefault) {
defaultDisplay = language.name;
isDefault = false;
}
});
builder.append(`</select><div class="select__arrow"></div></div>`);
builder.append("Invisible characters are shown with the following symbols:\n");
builder.append(Object.keys(invisiblesMap).map(invisibleName => {
const visibleChar = invisiblesMap[invisibleName];
return (`<kbd>${optionKeyToTitle(invisibleName)}</kbd> = <kbd>${visibleChar}</kbd>`);
}).join('; ') + '.');
builder.append('<!--DOCUSAURUS_CODE_TABS-->',);
this.languages.forEach((language, languageIndex) => {
const example = examplesForLanguages[language.name];
builder.append(
`<div class="exampleCode${
language.name === defaultDisplay ? "" : " hidden"
}" id="example-${language.name
.toLowerCase()
.replace(/ /g, "")}">\n`,
);
builder.append(`<!--${language.name}-->`);
if (example) {
builder.editButton(
`Edit ${language.name} Example`,
Expand Down Expand Up @@ -292,7 +258,6 @@ export default class OptionsDoc extends Doc {
builder.append("");
}
});

if (
this.exampleValues.length > 1 &&
!beautifiedExamplesAreDifferent
Expand All @@ -308,8 +273,8 @@ export default class OptionsDoc extends Doc {
);
builder.append("No example found. Please submit a Pull Request!");
}
builder.append(`</div>`);
});
builder.append('<!--END_DOCUSAURUS_CODE_TABS-->');
});
})
.then(() => builder);
Expand Down
16 changes: 9 additions & 7 deletions website/static/js/selectList.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
let previousSelectedLanguage;

window.onload = function() {
const langSelectedElement = document.getElementById("languages-select");
const langSelectedElement = document.querySelectorAll('.nav-link');

if (langSelectedElement.length == 0) return;

loadSelected();

langSelectedElement.onchange = function onSelectionChange() {
const languageName = getSelectedLanguage();
history.pushState({ language: languageName }, null, `?language=${languageName}`);
updateCodeExample(languageName);
};

langSelectedElement.forEach(function(tab) {
tab.addEventListener('click', function(e) {
const languageName = e.target.innerHTML;
history.pushState({ language: languageName }, null, `?language=${languageName}`);
})
});
};

function loadSelected() {
Expand All @@ -34,6 +35,7 @@ window.onpopstate = function onPageChange(event) {

function updateCodeExample(languageName) {
languageName = fixLanguage(languageName);
element = [...document.querySelectorAll(".nav-tabs .nav-link")].filter(text => text.textContent === languageName);
Copy link
Member

Choose a reason for hiding this comment

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

@stevenzeck is this element used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR is going to be redone.

if (!languageName) {
return;
}
Expand Down