Skip to content

Commit 4d90a9f

Browse files
committed
wip: demo with stackblitz
1 parent 07a20e8 commit 4d90a9f

10 files changed

Lines changed: 127 additions & 27 deletions

File tree

docs/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = {
2727
{ text: 'Github', link: 'https://github.com/jasonshin/kalimdorjs' }
2828
],
2929
sidebar: {
30-
'/api/': extra.apiSidebar
30+
'/api/': extra.apiSidebar,
3131
}
3232
}
3333
}

docs/override.styl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,16 @@ $codeBgColor = #282c34
3333
#app .active.sidebar-link {
3434
color: $highlightColor;
3535
border-left-color: $highlightColor;
36+
}
37+
38+
// Examples
39+
.example-page .page .content {
40+
max-width: 100%;
41+
padding: 0;
42+
height: 90vh;
43+
}
44+
45+
.example-page .page .content iframe {
46+
width: 100%;
47+
height: 100%;
3648
}

docs/pages/examples/README.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

docs/processor/DemoProcessor.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

docs/processor/ExampleProcessor.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import * as fs from 'fs';
2+
import { forEach } from 'lodash';
3+
import { BaseProcesser } from "./BaseProcesser";
4+
import exampleConfig from './exampleConfig';
5+
import * as path from "path";
6+
// import * as path from 'path';
7+
8+
export class ExampleProcessor extends BaseProcesser {
9+
private themePath = path.join(__dirname, '../themes/markdown');
10+
private exampleOutputPath = path.join(__dirname, '../md_out/examples');
11+
private homePageFile = 'examples_readme.hbs';
12+
private srcExampleHomeTheme = path.join(this.themePath, this.homePageFile);
13+
private destExampleHomePage = path.join(__dirname, '../md_out/examples/README.md');
14+
private examplePageFile = 'example_entity_page.hbs';
15+
private srcExamplePageTheme = path.join(this.themePath, this.examplePageFile);
16+
17+
/**
18+
* Run the processor
19+
* @param hbs
20+
*/
21+
public run(hbs): void {
22+
this.createDir();
23+
this.createReadMe(hbs);
24+
this.createExamplePage(hbs);
25+
}
26+
27+
/**
28+
* Create example directory if not exist
29+
*/
30+
private createDir(): void {
31+
if (!fs.existsSync(this.exampleOutputPath)) {
32+
fs.mkdirSync(this.exampleOutputPath);
33+
}
34+
}
35+
36+
/**
37+
* Create example category directory if not exist
38+
* @param fullPath
39+
*/
40+
private createDirByName(fullPath): void {
41+
if (!fs.existsSync(fullPath)) {
42+
fs.mkdirSync(fullPath);
43+
}
44+
}
45+
46+
/**
47+
* Creates the readme file for examples
48+
* @param hbs
49+
*/
50+
private createReadMe(hbs): void {
51+
const exampleHomePageThemeContent = fs.readFileSync(this.srcExampleHomeTheme, 'utf8');
52+
const template = hbs.compile(exampleHomePageThemeContent);
53+
const compiledPage = template(exampleConfig);
54+
fs.appendFileSync(this.destExampleHomePage, compiledPage, { flag: 'a' });
55+
}
56+
57+
private createExamplePage(hbs): void {
58+
const examplePageThemeContent = fs.readFileSync(this.srcExamplePageTheme, 'utf8');
59+
const template = hbs.compile(examplePageThemeContent);
60+
forEach(exampleConfig, (category) => {
61+
const categoryKey = category.key;
62+
const categoryDir = path.join(this.exampleOutputPath, categoryKey);
63+
64+
// Creates the category dir
65+
this.createDirByName(categoryDir);
66+
67+
const categoryChildren = category.children;
68+
forEach(categoryChildren, (child) => {
69+
const childKey = child.key;
70+
const examplePageName = path.join(categoryDir, `${childKey}.md`);
71+
const compiledPage = template(child);
72+
fs.appendFileSync(examplePageName, compiledPage, { flag: 'a' });
73+
});
74+
});
75+
}
76+
}

docs/processor/exampleConfig.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Configuration for demo pages
3+
*/
4+
export default [
5+
{
6+
key: 'general',
7+
title: 'General examples',
8+
description: 'General-purpose and introductory examples for Kalimdor.js',
9+
children: [
10+
{
11+
key: 'random_forest_with_titanic_datasets',
12+
title: 'Random Forest with Titanic Datasets',
13+
blitz: 'https://stackblitz.com/edit/kalimdor-random-forest-titanic-dataset?embed=1&file=index.ts'
14+
}
15+
]
16+
}
17+
];

docs/processor/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as path from 'path';
55
import { APIProcessor } from './APIProcessor';
66
import { ConfigProcessor } from './ConfigProcessor';
77
import * as consts from './const';
8+
import { ExampleProcessor } from './ExampleProcessor';
89
import { PagesProcessor } from './PagesProcessor';
910
const docsJson = JSON.parse(fs.readFileSync(path.join(__dirname, '../docs.json'), 'utf8'));
1011
const pjson = JSON.parse(fs.readFileSync(path.join(__dirname, '../../package.json'), 'utf8'));
@@ -396,5 +397,8 @@ apiProcessor.run(Handlebars);
396397
const pagesProcessor = new PagesProcessor();
397398
pagesProcessor.run();
398399

400+
const exampleProcessor = new ExampleProcessor();
401+
exampleProcessor.run(Handlebars);
402+
399403
const configProcessor = new ConfigProcessor();
400404
configProcessor.run({ apiChildren: apiProcessor.apiChildren });

docs/processor/play.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { DemoProcessor } from "./DemoProcessor";
1+
import * as Handlebars from 'handlebars';
2+
import { ExampleProcessor } from "./ExampleProcessor";
23

3-
const dp = new DemoProcessor();
4-
dp.run();
4+
const dp = new ExampleProcessor();
5+
dp.run(Handlebars);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
pageClass: example-page
3+
---
4+
<iframe src="{{{ blitz }}}"></iframe>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Examples
2+
3+
{{#each this}}
4+
{{newLine}}### {{ title }}
5+
{{newLine}}{{ description }}
6+
{{#each this.children}}
7+
{{newLine}}- [{{ title }}](./{{../key}}/{{key}}.md)
8+
{{/each}}
9+
{{/each}}

0 commit comments

Comments
 (0)