Skip to content

Commit

Permalink
Adds Prettier
Browse files Browse the repository at this point in the history
Closes #169
  • Loading branch information
LB Johnston authored and lb- committed Jul 14, 2023
1 parent 9fce031 commit f633a06
Show file tree
Hide file tree
Showing 30 changed files with 250 additions and 212 deletions.
2 changes: 1 addition & 1 deletion .github/actions/setup-firefox/action.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Shamelessly copied from https://github.com/SeleniumHQ/selenium/blob/5d108f9a679634af0bbc387e7e3811bc1565912b/.github/actions/setup-firefox/action.yml
name: 'Setup Firefox and geckodriver'
runs:
using: "composite"
using: 'composite'
steps:
- run: |
GECKODRIVER_URL=`curl -Ls -o /dev/null -w %{url_effective} https://github.com/mozilla/geckodriver/releases/latest`
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
run: echo "##[set-output name=NVMRC;]$(cat .nvmrc)"
- uses: actions/setup-node@v2-beta
with:
node-version: "${{ steps.nvm.outputs.NVMRC }}"
node-version: '${{ steps.nvm.outputs.NVMRC }}'
- run: npm install
- run: npm run build
- uses: actions/setup-python@v2
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
### Added

- Add basic styling of `autodoc` generated methods for readability (Temidayo Azeez)
- Add Prettier formatting and checks (LB (Ben) Johnston)

### Fixed

Expand Down
60 changes: 30 additions & 30 deletions docs/examples/code-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,43 +66,43 @@ a {
## Javascript

```js
function isDivisible (dividend, divisior) {
const rest = dividend % divisior
if (rest === 0) {
return true
} else {
return false
}
function isDivisible(dividend, divisior) {
const rest = dividend % divisior;
if (rest === 0) {
return true;
} else {
return false;
}
}

exports.isDivisible = isDivisible

function numToFizzBuzz (num) {
let response = ''
if (isDivisible(num, 3)) {
response += 'Fizz'
}
if (isDivisible(num, 5)) {
response += 'Buzz'
}
if (!response) {
response = num.toString()
}
return response
exports.isDivisible = isDivisible;

function numToFizzBuzz(num) {
let response = '';
if (isDivisible(num, 3)) {
response += 'Fizz';
}
if (isDivisible(num, 5)) {
response += 'Buzz';
}
if (!response) {
response = num.toString();
}
return response;
}

exports.numToFizzBuzz = numToFizzBuzz
exports.numToFizzBuzz = numToFizzBuzz;

function fizzbuzz (start = 1, end = 100) {
const fizzbuzzArray = []
for (let i = start; i <= end; i++) {
const numString = numToFizzBuzz(i)
fizzbuzzArray.push(numString)
}
return fizzbuzzArray
function fizzbuzz(start = 1, end = 100) {
const fizzbuzzArray = [];
for (let i = start; i <= end; i++) {
const numString = numToFizzBuzz(i);
fizzbuzzArray.push(numString);
}
return fizzbuzzArray;
}

exports.fizzbuzz = fizzbuzz
exports.fizzbuzz = fizzbuzz;
```

## Console
Expand Down
1 change: 0 additions & 1 deletion docs/examples/headings.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


## Heading with `code` in it

I guess this will come up, so we should style for it.
Expand Down
7 changes: 3 additions & 4 deletions docs/examples/images.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

Images are hard to keep up-to-date as documentation evolves, but can be worthwhile nonetheless. Here are guidelines when adding images:


## Plain Images

- All images should have meaningful [alt text](https://axesslab.com/alt-texts/) unless they are decorative.
- Images are served as-is – pick the correct format, and losslessly compress all images.
- Use absolute paths for image files so they are more portable.
- All images should have meaningful [alt text](https://axesslab.com/alt-texts/) unless they are decorative.
- Images are served as-is – pick the correct format, and losslessly compress all images.
- Use absolute paths for image files so they are more portable.

![A wagtail standing on the ground](/img/wagtail.jpg)

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/inline-styles.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

Use **bold** and _italic_ sparingly.

Use inline `code` when relevant.
Use inline `code` when relevant.
16 changes: 8 additions & 8 deletions docs/examples/lists.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
4. Number list item with some longer line. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
5. You can even do paragraphs in the list.

You need make sure they are indented in the beginning though.
You need make sure they are indented in the beginning though.

## Unordered Lists

- Bullet 1
- Bullet 2
- Nested bullet 1
- Nested bullet 2
- After three levels it should be enough
- Don't go deeper
- Bullet 3
- Bullet 1
- Bullet 2
- Nested bullet 1
- Nested bullet 2
- After three levels it should be enough
- Don't go deeper
- Bullet 3
2 changes: 1 addition & 1 deletion docs/examples/nesting/child.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Child

This page is included in the page structure by linking to it.
This page is included in the page structure by linking to it.
2 changes: 1 addition & 1 deletion docs/examples/paragraphs.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Paragraphs in Markdown are separated by a blank line.

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
2 changes: 1 addition & 1 deletion docs/examples/progressive-disclosure.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Progressive Disclosure

We can add supplementary information in documentation with the HTML `<details>` element.
We can add supplementary information in documentation with the HTML `<details>` element.
This relies on HTML syntax, which can be hard to author consistently, so keep this type of formatting to a minimum.

<details>
Expand Down
1 change: 0 additions & 1 deletion docs/examples/quotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Quotes, also known as blockquotes or pull-quotes, should stand out:
> when an unknown printer took a galley of type and scrambled it to make a type
> specimen book.

RST has `epigraph`, `highlights`, and `pull-quote` which all create a quote.
Adding the double dash line at the bottom properly attributes an author.

Expand Down
16 changes: 8 additions & 8 deletions js/blocking.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
* @param {boolean?} options.isInitial - if true the current value will be resolved & set NOT toggled
*/
function updateThemeMode(event, { isInitial = false } = {}) {
const DARK = "dark";
const LIGHT = "light";
const STORAGE_KEY = "wagtail-theme";
const DARK = 'dark';
const LIGHT = 'light';
const STORAGE_KEY = 'wagtail-theme';

let currentMode;
let applyMode;
Expand All @@ -26,7 +26,7 @@ function updateThemeMode(event, { isInitial = false } = {}) {
savedThemeMode = localStorage.getItem(STORAGE_KEY);
} catch (error) {
// eslint-disable-next-line no-console
console.warn("Unable to read theme from localStorage", error);
console.warn('Unable to read theme from localStorage', error);
}

// find the current mode from existing storage or browser preference
Expand All @@ -36,7 +36,7 @@ function updateThemeMode(event, { isInitial = false } = {}) {
} else {
// fall back on browser media for first toggle
const prefersDarkMode = window.matchMedia(
"(prefers-color-scheme:dark)"
'(prefers-color-scheme:dark)',
).matches;

currentMode = prefersDarkMode ? DARK : LIGHT;
Expand All @@ -50,15 +50,15 @@ function updateThemeMode(event, { isInitial = false } = {}) {
}

// set applied mode to the DOM
document.body.classList.toggle("theme-dark", applyMode === DARK);
document.body.classList.toggle('theme-dark', applyMode === DARK);

// only store value if already stored OR was triggered by an actual click
if (savedThemeMode || event) {
try {
localStorage.setItem(STORAGE_KEY, applyMode);
} catch (error) {
// eslint-disable-next-line no-console
console.warn("Unable to store theme in localStorage", error);
console.warn('Unable to store theme in localStorage', error);
}
}
}
Expand All @@ -73,6 +73,6 @@ updateThemeMode(null, { isInitial: true });
/**
* Set up event listener for other manual toggling.
*/
document.addEventListener("theme:toggle-theme-mode", updateThemeMode, {
document.addEventListener('theme:toggle-theme-mode', updateThemeMode, {
passive: true,
});
62 changes: 31 additions & 31 deletions js/theme.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// T3Docs
import "../sass/theme.scss";
import autocomplete from "autocompleter";
import "bootstrap";
import '../sass/theme.scss';
import autocomplete from 'autocompleter';
import 'bootstrap';

// Ensure our own namespace
if (typeof window.T3Docs === "undefined") {
if (typeof window.T3Docs === 'undefined') {
window.T3Docs = {};
}

Expand All @@ -16,26 +16,26 @@ function makeMenuExpandable() {
const expandButton = event.currentTarget;
const element = expandButton.parentElement;
const siblings =
element.parentElement.parentElement.querySelectorAll("li.current");
element.parentElement.parentElement.querySelectorAll('li.current');

siblings.forEach((sibling) => {
if (sibling !== element) {
sibling.classList.remove("current");
sibling.classList.remove('current');
}
});

element.classList.toggle("current");
element.classList.toggle('current');
}

const toc = document.querySelector(".toc");
const links = Array.from(toc.getElementsByTagName("a"));
const template = document.querySelector("[data-toggle-item-template]");
const toc = document.querySelector('.toc');
const links = Array.from(toc.getElementsByTagName('a'));
const template = document.querySelector('[data-toggle-item-template]');
const templateChild = template.content.firstElementChild;

links.forEach((link) => {
if (link.nextSibling) {
const expandButton = templateChild.cloneNode(true);
expandButton.addEventListener("click", toggleCurrent, true);
expandButton.addEventListener('click', toggleCurrent, true);
link.before(expandButton);
}
});
Expand All @@ -45,70 +45,70 @@ makeMenuExpandable();

// Wrap tables to make them responsive
function makeTablesResponsive() {
var tables = document.querySelectorAll(".rst-content table.docutils");
var tables = document.querySelectorAll('.rst-content table.docutils');
for (var i = 0; i < tables.length; i++) {
const wrapper = document.createElement("div");
wrapper.classList.add("table-responsive");
const wrapper = document.createElement('div');
wrapper.classList.add('table-responsive');
tables[i].parentNode.insertBefore(wrapper, tables[i]);
wrapper.appendChild(tables[i]);
}
}

makeTablesResponsive();

document.addEventListener("DOMContentLoaded", () => {
document.addEventListener('DOMContentLoaded', () => {
// Wire up light/dark mode button.
document
.getElementById("wagtail-theme")
.addEventListener("click", (event) => {
document.dispatchEvent(new CustomEvent("theme:toggle-theme-mode", event));
.getElementById('wagtail-theme')
.addEventListener('click', (event) => {
document.dispatchEvent(new CustomEvent('theme:toggle-theme-mode', event));
});

// Search.
var searchform = document.getElementById("search-form");
var searchinput = document.getElementById("searchinput");
var searchform = document.getElementById('search-form');
var searchinput = document.getElementById('searchinput');
if (searchform && searchinput) {
autocomplete({
input: searchinput,
fetch: (text, update) => {
// Populate autocomplete suggestions from the Sphinx `Search` object.
if (typeof window.T3Docs.autocomplete === "undefined") {
if (typeof window.T3Docs.autocomplete === 'undefined') {
window.T3Docs.autocomplete = [];
// Add page titles first.
Object.keys(Search._index.titles).forEach((item) => {
window.T3Docs.autocomplete.push({
label: Search._index.titles[item],
docname: Search._index.docnames[item],
group: "Pages",
group: 'Pages',
});
});
// Add autodoc/code terms second.
Object.keys(Search._index.objects).forEach((item) => {
Object.keys(Search._index.objects[item]).forEach((subitem) => {
window.T3Docs.autocomplete.push({
label: `${item}.${subitem}`,
group: "Code reference",
group: 'Code reference',
});
});
});
}
var suggestions = window.T3Docs.autocomplete.filter((entry) =>
entry.label.toLowerCase().includes(text.toLowerCase())
entry.label.toLowerCase().includes(text.toLowerCase()),
);
update(suggestions);
},
minLength: 3,
render: (item) => {
var div = document.createElement("div");
var div = document.createElement('div');
div.textContent = item.label;
return div;
},
customize: (input, inputRect, container) => {
// Do not force same width as input box - allow it to go wider.
// eslint-disable-next-line no-param-reassign
container.style.minWidth = inputRect.width + "px";
container.style.minWidth = inputRect.width + 'px';
// eslint-disable-next-line no-param-reassign
container.style.width = "auto";
container.style.width = 'auto';
},
onSelect: (item) => {
// If they selected a page, disable search form and go straight to it.
Expand All @@ -119,12 +119,12 @@ document.addEventListener("DOMContentLoaded", () => {
// Figure out the URL from the docname.
// Mostly taken from Sphinx's searchtools.js
var linkUrl;
if (DOCUMENTATION_OPTIONS.BUILDER === "dirhtml") {
var dirname = item.docname + "/";
if (DOCUMENTATION_OPTIONS.BUILDER === 'dirhtml') {
var dirname = item.docname + '/';
if (dirname.match(/\/index\/$/)) {
dirname = dirname.substring(0, dirname.length - 6);
} else if (dirname === "index/") {
dirname = "";
} else if (dirname === 'index/') {
dirname = '';
}
linkUrl = DOCUMENTATION_OPTIONS.URL_ROOT + dirname;
} else {
Expand Down
Loading

0 comments on commit f633a06

Please sign in to comment.