Skip to content

Commit

Permalink
fix: JS examples now work correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dayle Salmon committed Dec 7, 2020
1 parent 05b5a49 commit b3f7709
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 46 deletions.
9 changes: 6 additions & 3 deletions gulp-tasks/build-nunjucks.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ const mergingJSONFiles = () => {
};

const manageEnv = env => {
// Custom Filters
// Custom Filters for nunjucks

// This filter beautify's our html, useful for the pre/code blocks in component-example.njk
env.addFilter('formatHTML', html => {
const beautifulHTML = beautify(html.trim(), {
Expand All @@ -39,6 +40,7 @@ const manageEnv = env => {
return beautifulHTML;
});

// Beautify function shared by the two JS filters below
const beautifyJavascript = js =>
beautifyJS(js.trim(), {
indent_size: 2,
Expand All @@ -47,13 +49,14 @@ const manageEnv = env => {
max_preserve_newlines: 0
});

// Filter to format JS
env.addFilter('formatJS', js => {
return beautifyJavascript(js);
});

// Filter to convert content to ES5
env.addFilter('convertToES5', js => {
const compileJs = input =>
babel.transform(input, { presets: ['env', { modules: false }] }).code;
const compileJs = input => babel.transform(input, { presets: ['env'] }).code; // BABEL COMPILER ES6 => ES5
const compiledJS = compileJs(js);

return beautifyJavascript(compiledJS);
Expand Down
31 changes: 0 additions & 31 deletions src/www/_partials/component-example/_component-example-script.js

This file was deleted.

4 changes: 0 additions & 4 deletions src/www/_partials/component-example/component-example.njk
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,6 @@
{% endfilter -%}
</code></pre>
</details>

{# <script type="text/plain" class="wmnds-website-code-example__script">
{%- include componentPath + "_example.js" -%}
</script> #}
</div>
{% endif %}
</div>
Expand Down
3 changes: 1 addition & 2 deletions src/www/_partials/component-example/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import componentExample from './_component-example';
import componentExampleScript from './_component-example-script';
import componentExampleIframe from './_component-example-iframe';

export { componentExample, componentExampleScript, componentExampleIframe };
export { componentExample, componentExampleIframe };
7 changes: 1 addition & 6 deletions src/www/wmnds-website.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ import footerJs from '../wmnds/patterns/footer/_example';
import accordionsJS from '../wmnds/components/accordion/_example';
import searchFilterJs from '../wmnds/patterns/search/search-filter/_example';

import {
componentExample,
componentExampleScript,
componentExampleIframe
} from './_partials/component-example';
import { componentExample, componentExampleIframe } from './_partials/component-example';

const isInIframe = window.frameElement && window.frameElement.nodeName === 'IFRAME'; // check if we are in an iframe
// If not in iframe and we are in prod, then run sentry
Expand Down Expand Up @@ -46,6 +42,5 @@ window.addEventListener(
cookies(),
searchFilterJs(),
componentExampleIframe(),
componentExampleScript(),
componentExample)
);

0 comments on commit b3f7709

Please sign in to comment.