Skip to content

Commit 60b0625

Browse files
crisbetoandrewseguin
authored andcommitted
docs: clean up example config and data generation (#9223)
* Removes all of the optional properties being passed in as null in the example config. Also adds stronger typing to the list. * Cleans up the example data generation to be closer to the rest of the project.
1 parent 2957d58 commit 60b0625

File tree

3 files changed

+192
-412
lines changed

3 files changed

+192
-412
lines changed

src/material-examples/example-data.ts

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,31 @@ export class ExampleData {
1818
componentName = 'ButtonDemo';
1919

2020
constructor(example: string) {
21-
if (example && EXAMPLE_COMPONENTS[example]) {
22-
this.examplePath = `/assets/stackblitz/examples/${example}/`;
23-
24-
// TODO(tinayuangao): Do not hard-code extensions
25-
this.exampleFiles = ['html', 'ts', 'css']
26-
.map((extension) => `${example}-example.${extension}`);
27-
let exampleFilesSet = new Set(
28-
['html', 'ts', 'css'].map((extension) => `${example}-example.${extension}`));
29-
if (EXAMPLE_COMPONENTS[example].additionalFiles) {
30-
for (let file of EXAMPLE_COMPONENTS[example].additionalFiles) {
31-
exampleFilesSet.add(file);
32-
}
33-
}
34-
this.exampleFiles = Array.from(exampleFilesSet.values());
35-
36-
this.selectorName = this.indexFilename = `${example}-example`;
21+
if (!example || !EXAMPLE_COMPONENTS.hasOwnProperty(example)) {
22+
return;
23+
}
3724

38-
let exampleName = example.replace(/(?:^\w|\b\w)/g, letter => letter.toUpperCase());
25+
const exampleConfig = EXAMPLE_COMPONENTS[example];
26+
const exampleFilesSet = new Set(['html', 'ts', 'css'].map(extension => {
27+
return `${example}-example.${extension}`;
28+
}));
3929

40-
if (EXAMPLE_COMPONENTS[example].title) {
41-
this.description = EXAMPLE_COMPONENTS[example].title;
42-
} else {
43-
this.description = exampleName.replace(/[\-]+/g, ' ') + ' Example';
44-
}
30+
// TODO(tinayuangao): Do not hard-code extensions
31+
this.exampleFiles = ['html', 'ts', 'css'].map(extension => `${example}-example.${extension}`);
32+
this.examplePath = `/assets/stackblitz/examples/${example}/`;
33+
this.exampleFiles = Array.from(exampleFilesSet.values());
34+
this.selectorName = this.indexFilename = `${example}-example`;
4535

46-
if (EXAMPLE_COMPONENTS[example].selectorName) {
47-
this.componentName = EXAMPLE_COMPONENTS[example].selectorName;
48-
} else {
49-
this.componentName = exampleName.replace(/[\-]+/g, '') + 'Example';
36+
if (exampleConfig.additionalFiles) {
37+
for (let file of exampleConfig.additionalFiles) {
38+
exampleFilesSet.add(file);
5039
}
5140
}
41+
42+
const exampleName = example.replace(/(?:^\w|\b\w)/g, letter => letter.toUpperCase());
43+
44+
this.description = exampleConfig.title || exampleName.replace(/[\-]+/g, ' ') + ' Example';
45+
this.componentName = exampleConfig.selectorName ||
46+
exampleName.replace(/[\-]+/g, '') + 'Example';
5247
}
5348
}

0 commit comments

Comments
 (0)