Skip to content

Commit 08bd365

Browse files
authored
AFP-241: Refactor page templates
* AFP-241: WIP Refactor page templates * AFP-421: Extract all template strings into separate modules. Move page title logic into template components. * AFP-421: Tidy up tests * Fix gitignore for cypress plugins * Add changeset * Smol fixes
1 parent 1ce8baa commit 08bd365

37 files changed

+650
-499
lines changed

.changeset/e47ad29f/changes.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"releases": [{ "name": "@brisk-docs/website", "type": "patch" }],
3+
"dependents": []
4+
}

.changeset/e47ad29f/changes.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Refactor of how pages are generated. This should have no visible side effects.

.gitignore

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ node_modules
1010
package-lock.json
1111
yarn-error.log
1212

13-
cypress
13+
/cypress
14+
**/cypress/screenshots
1415

1516
/packages/website/pages/packages
1617
/packages/website/pages/docs
@@ -20,4 +21,4 @@ cypress
2021
/packages/**/bundles/**/*.js
2122
/packages/**/dist
2223

23-
out
24+
out

packages/website/bin/page-generator/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const {
1212
generateDocsHomePage,
1313
generateExamplesHomePage,
1414
generateProjectDocPage,
15-
} = require('./templates');
15+
} = require('./write-pages');
1616

1717
const packagesData = [];
1818

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const outdent = require('outdent');
2+
3+
/**
4+
* changelogTemplate - template for generating a changelog page
5+
*
6+
* @param {string} changelogPath relative path to the changelog file
7+
* @param {string} wrapperPath relative path to the page template component
8+
* @param {object} [data={}] extra data needed by the page
9+
*
10+
* @returns {string} source code for the page
11+
*/
12+
const changelogTemplate = (changelogPath, wrapperPath, data = {}) => outdent`
13+
import React from 'react';
14+
import changelog from '!!raw-loader!${changelogPath}';
15+
import Wrapper from '${wrapperPath}';
16+
17+
export default () => (
18+
<Wrapper data={${JSON.stringify(data)}}>
19+
{changelog}
20+
</Wrapper>
21+
);
22+
`;
23+
24+
module.exports = changelogTemplate;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import assertValidTemplate from '../test-utils';
2+
import changelogTemplate from './index';
3+
4+
describe('changelog page templates', () => {
5+
it('creates valid source code for a page', () => {
6+
const source = changelogTemplate('./component/path', './wrapper/path');
7+
8+
assertValidTemplate(source);
9+
});
10+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const outdent = require('outdent');
2+
3+
/**
4+
* exampleTemplate - template for an example page where the source code
5+
* for the wrapped component is also passed to the wrapper
6+
*
7+
* @param {string} componentPath absolute path to the example
8+
* @param {string} wrapperPath absolute path to the page wrapper
9+
* @param {object} [data={}] extra data needed for the page
10+
*
11+
* @returns {string} source code for the page
12+
*/
13+
const exampleTemplate = (componentPath, wrapperPath, data = {}) => outdent`
14+
import React from 'react';
15+
import Component from '${componentPath}';
16+
import fileContents from '!!raw-loader!${componentPath}';
17+
18+
import Wrapper from '${wrapperPath}';
19+
20+
export default () => (
21+
<Wrapper data={${JSON.stringify(data)}} fileContents={fileContents}>
22+
<Component />
23+
</Wrapper>
24+
);
25+
`;
26+
27+
module.exports = exampleTemplate;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import assertValidTemplate from '../test-utils';
2+
import exampleTemplate from './index';
3+
4+
describe('example page template', () => {
5+
it('creates valid source code for a page', () => {
6+
const source = exampleTemplate('./component/path', './wrapper/path');
7+
8+
assertValidTemplate(source);
9+
});
10+
});

0 commit comments

Comments
 (0)