Skip to content

Commit

Permalink
refactor: further optimizations (#1335)
Browse files Browse the repository at this point in the history
* refactor(accessibility): axe/language - added lang attribute

<html> element must have a lang attribute: The <html> element does not have a lang attribute
more information: https://dequeuniversity.com/rules/axe/4.2/html-has-lang

* chore: replaced individual random function by the one provided as a utility

* chore: prettier code formatting

* chore: prettier code formatting

* chore: eslint feedback

* chore: reverted those previously incorrectly checked in files

* docs: removed incorrect sentence out of #1313

I've added that documentation entry with #1313, but sadly missed to remove that incorrect sentence that belongs to another section on that page.
  • Loading branch information
mfranzke authored Aug 7, 2021
1 parent aa2c203 commit c74fd66
Show file tree
Hide file tree
Showing 35 changed files with 114 additions and 112 deletions.
3 changes: 1 addition & 2 deletions packages/cli/bin/inquiries/starterkit.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ const starterkitSetup = [
message: 'What initial patterns do you want included in your project?',
choices: [
{
name:
'Handlebars base patterns (some basic patterns to get started with)',
name: 'Handlebars base patterns (some basic patterns to get started with)',
value: '@pattern-lab/starterkit-handlebars-vanilla',
},
{
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/buildListItems_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ tap.test(
'buildlistItems transforms container of listItems with one value',
(test) => {
// do this to avoid the shuffling for now
const container = Object.assign({}, { listitems: { '1': listItems['1'] } });
const container = Object.assign({}, { listitems: { 1: listItems['1'] } });
buildlistItems(container);
test.same(container.listitems, {
'listItems-one': [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Hello world!
{{ subtitle }}
{{subtitle}}
5 changes: 2 additions & 3 deletions packages/core/test/lineage_hunter_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,8 @@ tap.test(
'molecules-error'
);

var currentPatternLineageIndex = patternlab.graph.lineageIndex(
currentPattern
);
var currentPatternLineageIndex =
patternlab.graph.lineageIndex(currentPattern);
test.equal(currentPatternLineageIndex.length, 1);
test.equal(currentPatternLineageIndex[0], 'atoms-error');

Expand Down
5 changes: 2 additions & 3 deletions packages/core/test/pattern_engines_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ var engineNames = Object.keys(patternEngines);
tap.test(
'getEngineNameForPattern returns "mustache" from test pattern',
function (test) {
var engineName = patternEngines.getEngineNameForPattern(
mustacheTestPattern
);
var engineName =
patternEngines.getEngineNameForPattern(mustacheTestPattern);
test.equal(engineName, 'mustache');
test.end();
}
Expand Down
20 changes: 8 additions & 12 deletions packages/core/test/pseudopattern_hunter_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,21 @@ tap.test(
'utf8'
);
atomPattern.extendedTemplate = atomPattern.template;
atomPattern.stylePartials = atomPattern.findPartialsWithStyleModifiers(
atomPattern
);
atomPattern.parameteredPartials = atomPattern.findPartialsWithPatternParameters(
atomPattern
);
atomPattern.stylePartials =
atomPattern.findPartialsWithStyleModifiers(atomPattern);
atomPattern.parameteredPartials =
atomPattern.findPartialsWithPatternParameters(atomPattern);

var pseudoPattern = new Pattern('test/pseudomodifier.mustache');
pseudoPattern.template = fs.readFileSync(
patterns_dir + 'test/pseudomodifier.mustache',
'utf8'
);
pseudoPattern.extendedTemplate = atomPattern.template;
pseudoPattern.stylePartials = pseudoPattern.findPartialsWithStyleModifiers(
pseudoPattern
);
pseudoPattern.parameteredPartials = pseudoPattern.findPartialsWithPatternParameters(
pseudoPattern
);
pseudoPattern.stylePartials =
pseudoPattern.findPartialsWithStyleModifiers(pseudoPattern);
pseudoPattern.parameteredPartials =
pseudoPattern.findPartialsWithPatternParameters(pseudoPattern);

addPattern(atomPattern, pl);
addPattern(pseudoPattern, pl);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html class="{{ htmlClass }}">
<html class="{{ htmlClass }}" lang="en">
<head>
<title>{{ title }}</title>
<meta charset="UTF-8">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html class="{{ htmlClass }}">
<html class="{{ htmlClass }}" lang="en">
<head>
<title>{{ title }}</title>
<meta charset="UTF-8" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html class="{{ htmlClass }}">
<html class="{{ htmlClass }}" lang="en">
<head>
<title>{{ title }}</title>
<meta charset="UTF-8">
Expand Down
2 changes: 0 additions & 2 deletions packages/docs/src/docs/advanced-config-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,6 @@ Prevent specific filetypes being copied from your `source` to your `public` fold
]
```

These template and page patterns would still be accessible via navigation.

**default**: `[]`

## uikits
Expand Down
2 changes: 1 addition & 1 deletion packages/edition-node-gulp/source/_meta/_head.mustache
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html class="{{ htmlClass }}">
<html class="{{ htmlClass }}" lang="en">
<head>
<title>{{ title }}</title>
<meta charset="UTF-8">
Expand Down
2 changes: 1 addition & 1 deletion packages/edition-node/source/_meta/_head.mustache
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html class="{{ htmlClass }}">
<html class="{{ htmlClass }}" lang="en">
<head>
<title>{{ title }}</title>
<meta charset="UTF-8">
Expand Down
2 changes: 1 addition & 1 deletion packages/edition-twig/source/_meta/_head.mustache
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html class="{{ htmlClass }}">
<html class="{{ htmlClass }}" lang="en">
<head>
<title>{{ title }}</title>
<meta charset="UTF-8">
Expand Down
2 changes: 1 addition & 1 deletion packages/edition-twig/source/_meta/_head.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html class="{{ htmlClass }}">
<html class="{{ htmlClass }}" lang="en">
<head>
<title>{{ title }}</title>
<meta charset="UTF-8">
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-handlebars/_meta/_head.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html class="{{ htmlClass }}">
<html class="{{ htmlClass }}" lang="en">
<head>
<title>{{ title }}</title>
<meta charset="UTF-8">
Expand Down
3 changes: 2 additions & 1 deletion packages/engine-handlebars/lib/engine_handlebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ const glob = require('glob');

// regexes, stored here so they're only compiled once
const findPartialsRE = /{{#?>\s*([\w-\/.]+)(?:.|\s+)*?}}/g;
const findListItemsRE = /({{#( )?)(list(I|i)tems.)(one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twenty)( )?}}/g;
const findListItemsRE =
/({{#( )?)(list(I|i)tems.)(one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twenty)( )?}}/g;
const findAtPartialBlockRE = /{{#?>\s*@partial-block\s*}}/g;

function escapeAtPartialBlock(partialString) {
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-liquid/_meta/_head.liquid
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html class="{{ htmlClass }}">
<html class="{{ htmlClass }}" lang="en">
<head>
<title>{{ title }}</title>
<meta charset="UTF-8">
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-mustache/_meta/_head.mustache
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html class="{{ htmlClass }}">
<html class="{{ htmlClass }}" lang="en">
<head>
<title>{{ title }}</title>
<meta charset="UTF-8">
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-nunjucks/_meta/_head.njk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html class="{{ htmlClass }}">
<html class="{{ htmlClass }}" lang="en">
<head>
<title>{{ title }}</title>
<meta charset="UTF-8">
Expand Down
6 changes: 4 additions & 2 deletions packages/engine-nunjucks/lib/engine_nunjucks.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ const engine_nunjucks = {
expandPartials: false,

// regexes, stored here so they're only compiled once
findPartialsRE: /{%\s*(?:extends|include|import|from)\s+(?:'[^']+'|"[^"]+").*%}/g,
findPartialsRE:
/{%\s*(?:extends|include|import|from)\s+(?:'[^']+'|"[^"]+").*%}/g,
findPartialKeyRE: /{%\s*(?:extends|include|import|from)\s+('[^']+'|"[^"]+")/,
findListItemsRE: /({{#( )?)(list(I|i)tems.)(one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twenty)( )?}}/g, // still requires mustache style syntax because of how PL implements lists
findListItemsRE:
/({{#( )?)(list(I|i)tems.)(one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twenty)( )?}}/g, // still requires mustache style syntax because of how PL implements lists

// render it
renderPattern: function renderPattern(pattern, data) {
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-twig-php/_meta/_head.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html class="{{ htmlClass }}">
<html class="{{ htmlClass }}" lang="en">
<head>
<title>{{ title }}</title>
<meta charset="UTF-8">
Expand Down
11 changes: 4 additions & 7 deletions packages/engine-twig-php/lib/engine_twig_php.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const engine_twig_php = {
engineName: 'twig-php',
engineFileExtension: '.twig',
expandPartials: false,
findPartialsRE: /{%\s*(?:extends|include|embed)\s+('[^']+'|"[^"]+").*?(with|%}|\s*%})/g,
findPartialsRE:
/{%\s*(?:extends|include|embed)\s+('[^']+'|"[^"]+").*?(with|%}|\s*%})/g,
findPartialKeyRE: /"((?:\\.|[^"\\])*)"|'((?:\\.|[^"\\])*)'/,
namespaces: [],

Expand All @@ -45,12 +46,8 @@ const engine_twig_php = {
process.exit(1);
}

const {
namespaces,
alterTwigEnv,
relativeFrom,
...rest
} = config.engines.twig;
const { namespaces, alterTwigEnv, relativeFrom, ...rest } =
config.engines.twig;

// Schema on config object being passed in:
// https://github.com/basaltinc/twig-renderer/blob/master/config.schema.json
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-twig/_meta/_head.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html class="{{ htmlClass }}">
<html class="{{ htmlClass }}" lang="en">
<head>
<title>{{ title }}</title>
<meta charset="UTF-8">
Expand Down
3 changes: 2 additions & 1 deletion packages/engine-twig/lib/engine_twig.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ var engine_twig = {
// regexes, stored here so they're only compiled once
findPartialsRE: /{%\s*(?:extends|include|embed)\s+('[^']+'|"[^"]+").*?%}/g,
findPartialKeyRE: /"((?:\\.|[^"\\])*)"/,
findListItemsRE: /({{#( )?)(list(I|i)tems.)(one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twenty)( )?}}/g, // TODO
findListItemsRE:
/({{#( )?)(list(I|i)tems.)(one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twenty)( )?}}/g, // TODO

// render it
renderPattern: function renderPattern(pattern, data, partials) {
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-underscore/_meta/_head.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html class="{{ htmlClass }}">
<html class="{{ htmlClass }}" lang="en">
<head>
<title>{{ title }}</title>
<meta charset="UTF-8" />
Expand Down
6 changes: 4 additions & 2 deletions packages/engine-underscore/lib/engine_underscore.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ const engine_underscore = {
expandPartials: false,

// regexes, stored here so they're only compiled once
findPartialsRE: /<%=\s*_\.renderNamedPartial[ \t]*\(\s*("(?:[^"].*?)"|'(?:[^'].*?)').*?%>/g, // TODO
findListItemsRE: /({{#( )?)(list(I|i)tems.)(one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twenty)( )?}}/g,
findPartialsRE:
/<%=\s*_\.renderNamedPartial[ \t]*\(\s*("(?:[^"].*?)"|'(?:[^'].*?)').*?%>/g, // TODO
findListItemsRE:
/({{#( )?)(list(I|i)tems.)(one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twenty)( )?}}/g,

// render it
renderPattern: function renderPattern(pattern, data, partials) {
Expand Down
61 changes: 35 additions & 26 deletions packages/live-server/injected.html
Original file line number Diff line number Diff line change
@@ -1,29 +1,38 @@
<!-- Code injected by live-server -->
<script type="text/javascript">
// <![CDATA[ <-- For SVG support
if ('WebSocket' in window) {
(function() {
function refreshCSS() {
var sheets = [].slice.call(document.getElementsByTagName("link"));
var head = document.getElementsByTagName("head")[0];
for (var i = 0; i < sheets.length; ++i) {
var elem = sheets[i];
var rel = elem.rel;
if (elem.href && typeof rel != "string" || rel.length == 0 || rel.toLowerCase() == "stylesheet") {
var url = elem.href.replace(/(&|\?)_cacheOverride=\d+/, '');
elem.href = url + (url.indexOf('?') >= 0 ? '&' : '?') + '_cacheOverride=' + (new Date().valueOf());
}
}
}
var protocol = window.location.protocol === 'http:' ? 'ws://' : 'wss://';
var address = protocol + window.location.host + window.location.pathname + '/ws';
var socket = new WebSocket(address);
socket.onmessage = function(msg) {
if (msg.data == 'reload') window.location.reload();
else if (msg.data == 'refreshcss') refreshCSS();
};
console.log('Live reload enabled.');
})();
}
// ]]>
// <![CDATA[ <-- For SVG support
if ('WebSocket' in window) {
(function () {
function refreshCSS() {
var sheets = [].slice.call(document.getElementsByTagName('link'));
var head = document.getElementsByTagName('head')[0];
for (var i = 0; i < sheets.length; ++i) {
var elem = sheets[i];
var rel = elem.rel;
if (
(elem.href && typeof rel != 'string') ||
rel.length == 0 ||
rel.toLowerCase() == 'stylesheet'
) {
var url = elem.href.replace(/(&|\?)_cacheOverride=\d+/, '');
elem.href =
url +
(url.indexOf('?') >= 0 ? '&' : '?') +
'_cacheOverride=' +
new Date().valueOf();
}
}
}
var protocol = window.location.protocol === 'http:' ? 'ws://' : 'wss://';
var address =
protocol + window.location.host + window.location.pathname + '/ws';
var socket = new WebSocket(address);
socket.onmessage = function (msg) {
if (msg.data == 'reload') window.location.reload();
else if (msg.data == 'refreshcss') refreshCSS();
};
console.log('Live reload enabled.');
})();
}
// ]]>
</script>
2 changes: 1 addition & 1 deletion packages/starterkit-handlebars-demo/dist/_meta/_head.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html class="{{ htmlClass }}">
<html class="{{ htmlClass }}" lang="en">
<head>
<title>{{ title }}</title>
<meta charset="UTF-8">
Expand Down
4 changes: 2 additions & 2 deletions packages/starterkit-twig-demo/dist/_meta/_head.twig
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<!DOCTYPE html>
<html class="{{ htmlClass }}">
<html class="{{ htmlClass }}" lang="en">
<head>
<title>{{ title }}</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width" />

<link rel="stylesheet" href="../../css/style.css?{{ cacheBuster }}" media="all" />
<link rel="stylesheet" href="../../css/pattern-scaffolding.css?{{ cacheBuster }}" media="all" />

Expand Down
9 changes: 5 additions & 4 deletions packages/uikit-workshop/src/html/partials/base-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
{{# descBlockExists }}

<div
class="pl-c-pattern-info__panel pl-c-pattern-info__panel--info pl-js-pattern-info"
class="
pl-c-pattern-info__panel pl-c-pattern-info__panel--info
pl-js-pattern-info
"
>
{{# isPatternView }}
<!-- extra info for modal view -->
Expand Down Expand Up @@ -83,9 +86,7 @@ <h2 class="pl-c-annotations__title">Annotations</h2>
<li class="pl-c-annotations__item">
<h3 class="pl-c-annotations__item-title">{{ title }}</h3>

<div class="pl-c-annotations__item-body">
{{{ comment }}}
</div>
<div class="pl-c-annotations__item-body">{{{ comment }}}</div>
<!--end pl-c-annotations__item-body-->
</li>
<!--end pl-c-annotations__item-->
Expand Down
Loading

0 comments on commit c74fd66

Please sign in to comment.