Skip to content

Commit

Permalink
Revert "Update npm package generator to place layouts and components …
Browse files Browse the repository at this point in the history
…in templates to satisfy flask (#276)" (#302)

This reverts commit a0b355b.
  • Loading branch information
bameyrick authored Apr 3, 2019
1 parent a0b355b commit aa166f8
Show file tree
Hide file tree
Showing 124 changed files with 739 additions and 1,069 deletions.
4 changes: 0 additions & 4 deletions lib/filters/set-attribute.js

This file was deleted.

9 changes: 0 additions & 9 deletions lib/filters/set-attributes.js

This file was deleted.

6 changes: 0 additions & 6 deletions lib/helpers/generate-example-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import pretty from 'pretty';

import { NunjucksLoader } from '../nunjucks-loader';
import { removeFrontmatterFromString } from '../remove-frontmatter-from-string';
import setAttribute from '../filters/set-attribute';
import setAttributes from '../filters/set-attributes';

const sourcePath = `${process.cwd()}/src`;

Expand Down Expand Up @@ -57,10 +55,6 @@ export function generateExampleParams(params, addDependency) {

const loader = new NunjucksLoader(sourcePath);
const environment = new nunjucks.Environment(loader);

environment.addFilter('setAttribute', setAttribute);
environment.addFilter('setAttributes', setAttributes);

nunjucks.configure(null, {
watch: false,
autoescape: true
Expand Down
118 changes: 58 additions & 60 deletions lib/nunjucks-html-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import { htmlErrorStack } from 'print-error';
import { MarkdownExtension } from './tags/markdown';
import { NunjucksLoader } from './nunjucks-loader';
import { removeFrontmatterFromString } from './remove-frontmatter-from-string';
import setAttribute from './filters/set-attribute';
import setAttributes from './filters/set-attributes';

import { navigationHelper, subNavigationHelper, generateExampleParams } from './helpers';

Expand Down Expand Up @@ -97,6 +95,10 @@ function getPageInfo(context) {
let pageRef = siteMap;
let pathRef = '';

if (path === '/components/language-selector/examples/english/index.njk') {
debugger;
}

pathParts.forEach((part, index) => {
if (pageRef) {
part = `/${part.replace('index.njk', '').replace('.njk')}`;
Expand Down Expand Up @@ -133,12 +135,11 @@ function getPageInfo(context) {
}
}

function handleError(error, environment, layoutPath, callback, pageInfo) {
function handleError(error, environment, layoutPath, callback) {
if (error) {
const filePath = `${process.cwd()}/src${pageInfo.url}/index.njk`;
console.log('');
console.log(chalk.red(error.stack.replace('(unknown path)', filePath)));
let html = htmlErrorStack(error, { fontSize: '10px' }).replace('(unknown path)', filePath);
console.log(chalk.red(error.stack));
let html = htmlErrorStack(error, { fontSize: '10px' });
html = `{% extends "${layoutPath}/_error.njk" %}{% block body %}${html}{% endblock %}`;
html = nunjucks.compile(html, environment).render({
error: error.toString()
Expand All @@ -159,6 +160,7 @@ function getFrontmatterFromFile(filePath) {

export default async function(source) {
this.cacheable();
let didError;

const callback = this.async();
const options = loaderUtils.getOptions(this) || {};
Expand Down Expand Up @@ -196,78 +198,74 @@ export default async function(source) {
addDependency: this.addDependency.bind(this)
});

environment.addFilter('setAttribute', setAttribute);
environment.addFilter('setAttributes', setAttributes);

environment.addExtension('MarkdownExtension', new MarkdownExtension());

// Render page nunjucks to HTML
renderHTML(nunjucks, source, environment, context)
.then(html => {
// Prettify HTML to stop markdown wrapping everything in code blocks
html = pretty(html);

// No need to render markdown if rendering an example page
if (!isExample) {
// Fix indented markdown (from nunjucks renderer) from being wrapped in code blocks by removing indents
html = html.replace(/(?!<code[^>]*?>)(\n +)(?![^<]*?<\/code>)/g, '\n');

// Render page markdown to HTML
html = marked(html, {
smartypants: true,
pedantic: true,
renderer: markdownRenderer
});
}
let html = await renderHTML(nunjucks, source, environment, context, options, callback, didError);

// Get page layout template path
let layoutPath;
// Prettify HTML to stop markdown wrapping everything in code blocks
html = pretty(html);

if (frontmatterData && frontmatterData.layout) {
layoutPath = `${frontmatterData.layout}.njk`;
} else if (isExample) {
layoutPath = '_example.njk';
} else {
layoutPath = '_page.njk';
}
// No need to render markdown if rendering an example page
if (!isExample) {
// Fix indented markdown (from nunjucks renderer) from being wrapped in code blocks by removing indents
html = html.replace(/(?!<code[^>]*?>)(\n +)(?![^<]*?<\/code>)/g, '\n');

if (layoutPath.slice(0, 1) !== '_') {
layoutPath = `_${layoutPath}`;
}
// Render page markdown to HTML
html = marked(html, {
smartypants: true,
pedantic: true,
renderer: markdownRenderer
});
}

layoutPath = `${options.layoutPath}/${layoutPath}`;
// Get page layout template path
let layoutPath;

this.addDependency(layoutPath);
if (frontmatterData && frontmatterData.layout) {
layoutPath = `${frontmatterData.layout}.njk`;
} else if (isExample) {
layoutPath = '_example.njk';
} else {
layoutPath = '_page.njk';
}

// Wrap html in extend for layout
source = `{% extends "${layoutPath}" %}
if (layoutPath.slice(0, 1) !== '_') {
layoutPath = `_${layoutPath}`;
}

layoutPath = `${options.layoutPath}/${layoutPath}`;

this.addDependency(layoutPath);

// Wrap html in extend for layout
source = `{% extends "${layoutPath}" %}
{% block body %}
${html}
{% endblock %}`;

// Render full page wrapped in layout
renderHTML(nunjucks, source, environment, context)
.then(html => {
// Clean up html
html = pretty(html, {
ocd: true
});

callback(null, html);
})
.catch(error => handleError(error, environment, options.layoutPath, callback, pageInfo));
})
.catch(error => handleError(error, environment, options.layoutPath, callback, pageInfo));
// Render full page wrapped in layout
html = await renderHTML(nunjucks, source, environment, context, options, callback, didError);

// Clean up html
html = pretty(html, {
ocd: true
});

if (!didError) {
callback(null, html);
}
}

async function renderHTML(nunjucks, source, environment, context) {
return new Promise((resolve, reject) => {
function renderHTML(nunjucks, source, environment, context, options, callback, didError) {
return new Promise(resolve => {
nunjucks.compile(source, environment).render(context, (error, result) => {
if (error) {
reject(error);
} else {
resolve(result);
didError = true;
handleError(error, environment, options.layoutPath, callback);
}

resolve(result);
});
});
}
7 changes: 0 additions & 7 deletions nunjucks.config.js

This file was deleted.

50 changes: 26 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,42 @@
"main": "index.js",
"license": "MIT",
"author": {
"name": "Ben Meyrick",
"email": "[email protected]",
"name": "Ben Meyrick",
"url": "https://github.com/bameyrick"
},
"publishConfig": {
"access": "public"
},
"scripts": {
"start": "yarn tidy-clean && yarn webpack-dev-server --host 0.0.0.0 --watch --config webpack.dev.babel.js",
"build": "yarn tidy-clean && yarn webpack --config webpack.prod.babel.js",
"check-unused": "npx npm-check-unused",
"dedupe-deps": "npx yarn-deduplicate yarn.lock",
"lint-staged": "lint-staged",
"npm-bundle": "NODE_ENV=production yarn build && babel-node lib/generate-npm-package.js",
"start": "yarn tidy-clean && yarn webpack-dev-server --host 0.0.0.0 --watch --config webpack.dev.babel.js",
"test": "karma start ./src/tests/config/karma.conf.js && karma start ./src/tests/config/karma.conf.nomodule.js && codecov",
"test:browserstack": "TEST_ON_BROWSERSTACK=true karma start ./src/tests/config/karma.conf.js && TEST_ON_BROWSERSTACK=true karma start ./src/tests/config/karma.conf.nomodule.js",
"test:local": "KARMA_SINGLE_RUN=false karma start ./src/tests/config/karma.conf.js",
"tidy-clean": "rm -rf build css favicons fonts img templates scripts coverage scss"
"dedupe-deps": "npx yarn-deduplicate yarn.lock",
"tidy-clean": "rm -rf build css favicons fonts img components page-templates scripts coverage scss",
"npm-bundle": "NODE_ENV=production yarn build && babel-node lib/generate-npm-package.js"
},
"browserslist": [
"last 2 versions",
"not ie < 11",
"not ie_mob < 11"
],
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"post-checkout": "yarn tidy-clean && yarn check"
}
},
"lint-staged": {
"*.scss": [
"prettier --print-width 140 --single-quote --parser postcss --write",
"sass-lint",
"git add"
],
"*.js": [
"prettier --print-width 140 --single-quote --parser babylon --write",
"eslint --fix",
Expand All @@ -37,18 +50,8 @@
"prettier --write",
"remark",
"git add"
],
"*.scss": [
"prettier --print-width 140 --single-quote --parser postcss --write",
"sass-lint",
"git add"
]
},
"browserslist": [
"last 2 versions",
"not ie < 11",
"not ie_mob < 11"
],
"devDependencies": {
"@babel/core": "^7.1.6",
"@babel/node": "^7.2.2",
Expand All @@ -58,7 +61,6 @@
"@babel/preset-env": "^7.1.6",
"@babel/register": "^7.0.0",
"@babel/runtime": "^7.2.0",
"abortcontroller-polyfill": "^1.2.3",
"autoprefixer": "^9.3.1",
"babel-eslint": "^10.0.1",
"babel-loader": "^8.0.4",
Expand All @@ -68,7 +70,6 @@
"circular-dependency-plugin": "^5.0.2",
"codecov": "^3.1.0",
"copy-webpack-plugin": "^4.6.0",
"core-js": "^2.6.0",
"cssnano": "^4.1.7",
"eslint": "^5.9.0",
"eslint-cli": "^1.1.1",
Expand Down Expand Up @@ -98,12 +99,10 @@
"loader-utils": "^1.1.0",
"lodash": "^4.17.11",
"marked": "^0.5.2",
"mdn-polyfills": "^5.14.0",
"mocha": "^5.2.0",
"ncp": "^2.0.0",
"node-sass": "^4.10.0",
"node-sass-glob-importer": "^5.2.0",
"normalize-scss": "^7.0.1",
"nunjucks": "^3.1.4",
"nunjucks-loader": "^3.0.0",
"postcss-loader": "^3.0.0",
Expand All @@ -120,7 +119,6 @@
"rimraf": "^2.6.3",
"sass-lint": "^1.12.1",
"sass-loader": "^7.1.0",
"throttle-typescript": "^1.0.1",
"url-loader": "^1.1.2",
"url-search-params-polyfill": "^5.0.0",
"webpack": "^4.26.0",
Expand All @@ -129,10 +127,14 @@
"webpack-dev-server": "^3.1.10",
"webpack-fix-style-only-entries": "^0.0.5",
"webpack-livereload-plugin": "^2.1.1",
"webpack-merge": "^4.1.4",
"whatwg-fetch": "^3.0.0"
"webpack-merge": "^4.1.4"
},
"publishConfig": {
"access": "public"
"dependencies": {
"abortcontroller-polyfill": "^1.2.3",
"core-js": "^2.6.0",
"mdn-polyfills": "^5.14.0",
"normalize-scss": "^7.0.1",
"throttle-typescript": "^1.0.1",
"whatwg-fetch": "^3.0.0"
}
}
36 changes: 10 additions & 26 deletions src/components/accordion/_macro-options.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,15 @@
| Name | Type | Required | Description |
| --------- | ---------------------- | -------- | ---------------------------------------------------------------------------------------- |
| id | string | true | id of the accordion |
| classes | string | false | Classes to add to the accordion component |
| itemList | `Array<AccordionItem>` | true | Accordion items to render |
| allButton | `AccordionButton` | false | Settings for the show all / hide all button. If not specified the button will not render |
| Name | Type | Required | Description |
| ----------- | -------------------- | -------- | -------------------------------------------------------------------------- |
| id | string | true | id of the accordion |
| classes | string | false | Classes to add to the button component |
| closeButton | string | true | The close button text for each accordion item |
| buttonOpen | string | true | The open button text for each accordion item |
| items | Array<AccordionItem> | true | Accordion items to render |
| openAll | string | false | Text for the open all button. If not specified the button will not render |
| closeAll | string | false | Text for the close all button. If not specified the button will not render |

## AccordionItem
| Name | Type | Required | Description |
| ----------------- | --------------------- | -------- | --------------------------------------------------------------------------- |
| ------- | ------ | -------- | --------------------------------- |
| title | string | true | The title of the accordion item |
| content | string | true | The content of the accordion item |
| button | `AccordionItemButton` | false | Settings for the button |
| attributes | object | false | HTML attributes (for example data attributes) to add to the details element |
| summaryAttributes | object | false | HTML attributes (for example data attributes) to add to the summary element |

## AccordionButton

| Name | Type | Required | Description |
| ---------- | ------ | -------- | ------------------------------------------------------------------ |
| open | string | true | Text to show when all of the items aren't open |
| close | string | true | Text to show when all of the items are open |
| attributes | object | false | HTML attributes (for example data attributes) to add to the button |

## AccordionItemButton

| Name | Type | Required | Description |
| ---------- | ------ | -------- | ------------------------------------------------------------------ |
| open | string | true | Text for the button when the item is closed |
| close | string | true | Text for the button when the item is open |
| attributes | object | false | HTML attributes (for example data attributes) to add to the button |
Loading

0 comments on commit aa166f8

Please sign in to comment.