Skip to content

Commit 75e3000

Browse files
committed
chore(): move demos out of source files
1 parent 2e8fd58 commit 75e3000

167 files changed

Lines changed: 2739 additions & 1379 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

config/demos/demos.config.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
var path = require('canonical-path');
2+
var _ = require('lodash');
3+
var staticSite = require('./static-site');
4+
5+
var projectBase = path.resolve(__dirname, '../..');
6+
7+
module.exports = function(config) {
8+
9+
config = staticSite(config);
10+
11+
config.merge('rendering.nunjucks.config.tags', {
12+
variableStart: '{$',
13+
variableEnd: '$}',
14+
blockStart: '{%',
15+
blockEnd: '%}'
16+
});
17+
18+
config.set('logging.level', 'info');
19+
20+
config.set('rendering.outputFolder', path.resolve(projectBase, 'dist/ionic-demo'));
21+
22+
config.set('rendering.templateFolders', [
23+
path.resolve(__dirname, 'templates')
24+
]);
25+
config.set('rendering.templatePatterns', [
26+
'${ doc.template }',
27+
'${doc.area}/${ doc.id }.${ doc.docType }.template.html',
28+
'${doc.area}/${ doc.id }.template.html',
29+
'${doc.area}/${ doc.docType }.template.html',
30+
'${ doc.id }.${ doc.docType }.template.html',
31+
'${ doc.id }.template.html',
32+
'${ doc.docType }.template.html'
33+
]);
34+
35+
config.append('processing.processors', [
36+
require('../docs/processors/version-data'),
37+
require('./processors/demos')
38+
]);
39+
40+
config.set('basePath', __dirname);
41+
config.set('source.projectPath', '.');
42+
43+
config.set('source.files', [
44+
{ pattern: 'demos/**/*.html', basePath: projectBase },
45+
{ pattern: 'demos/**/*.js', basePath: projectBase },
46+
{ pattern: 'demos/**/*.css', basePath: projectBase }
47+
]);
48+
49+
50+
return config;
51+
};

config/demos/processors/demos.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
var _ = require('lodash');
2+
var log = require('dgeni').log;
3+
var path = require('canonical-path');
4+
5+
var typeTransform = {
6+
markdown: 'md'
7+
};
8+
9+
module.exports = {
10+
name: 'demos',
11+
description: 'Output demos to their files on ionic-demo website',
12+
runAfter: ['files-read'],
13+
runBefore: ['processing-docs'],
14+
process: function(docs, config) {
15+
16+
var contentsFolder = config.rendering.contentsFolder;
17+
var assetOutputPath = path.join(contentsFolder, '${component}/${name}/${fileName}');
18+
19+
var pages = [];
20+
21+
var demos = _(docs)
22+
.filter('yaml')
23+
.groupBy(function(doc) {
24+
return doc.yaml.component + '-' + doc.yaml.name;
25+
})
26+
.map(function(fragmentsForId, id) {
27+
28+
var demoData = {
29+
files: []
30+
};
31+
fragmentsForId.forEach(function(fragment) {
32+
var doc = fragment.yaml;
33+
if (!doc.name || !doc.component) {
34+
log.error('Doc ' + fragment.filePath +
35+
' expects yaml keys "name" and "component"!');
36+
}
37+
38+
doc.id = doc.component + '-' + doc.name;
39+
doc.fileType = typeTransform[fragment.fileType] || fragment.fileType;
40+
doc.fileName = fragment.fileName;
41+
doc.contents = fragment.contents;
42+
doc.extension = doc.fileType.replace(/^\./,'');
43+
44+
doc.template = 'asset.contents.template',
45+
doc.outputPath = _.template(assetOutputPath, doc);
46+
47+
demoData.files.push(doc);
48+
pages.push(doc);
49+
});
50+
51+
var firstDoc = demoData.files[0];
52+
53+
var indexOutputPath = _.template(assetOutputPath, _.assign({}, firstDoc, {
54+
fileName: 'index.html'
55+
}));
56+
var appOutputPath = _.template(assetOutputPath, _.assign({}, firstDoc, {
57+
fileName: 'index-ionic-demo-app.js'
58+
}, demoData));
59+
60+
61+
demoData.files = _.groupBy(demoData.files, 'extension');
62+
demoData.id = firstDoc.id;
63+
demoData.name = firstDoc.name;
64+
demoData.component = firstDoc.component;
65+
demoData.href = '/' + _.template(assetOutputPath, _.assign({}, firstDoc, { fileName: '' }));
66+
67+
pages.push({
68+
template: 'index.template.html',
69+
demoData: demoData,
70+
outputPath: indexOutputPath
71+
});
72+
pages.push({
73+
template: 'app.template.js',
74+
demoData: demoData,
75+
outputPath: appOutputPath
76+
});
77+
78+
return demoData;
79+
80+
})
81+
.value();
82+
83+
pages.push({
84+
template: 'pages-data.template.js',
85+
demos: demos,
86+
outputPath: path.join(contentsFolder, 'pages-data.js')
87+
});
88+
pages.push({
89+
template: 'index.template.html',
90+
outputPath: path.join(contentsFolder, 'index.html')
91+
});
92+
pages.push({
93+
template: 'app.template.js',
94+
outputPath: path.join(contentsFolder, 'index-ionic-demo-app.js')
95+
});
96+
97+
return pages;
98+
}
99+
};
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
var jsYaml = require('js-yaml');
2+
var path = require('canonical-path');
3+
var YAML_LINE_REGEX = /---+/;
4+
5+
module.exports = {
6+
pattern: /\.*$/,
7+
processFile: function(filePath, contents, basePath) {
8+
9+
contents = contents.trim();
10+
11+
var yamlStartMatch = contents.match(YAML_LINE_REGEX);
12+
if (!yamlStartMatch || yamlStartMatch.index !== 0) {
13+
return [];
14+
}
15+
16+
var yamlContents = contents.substring(yamlStartMatch.index + yamlStartMatch[0].length + 1);
17+
18+
var yamlEndMatch = yamlContents.match(YAML_LINE_REGEX);
19+
if (!yamlEndMatch) {
20+
return [];
21+
}
22+
23+
contents = yamlContents.substring(yamlEndMatch.index + yamlEndMatch[0].length);
24+
yamlContents = yamlContents.substring(0, yamlEndMatch.index);
25+
26+
var yamlJson = jsYaml.safeLoad(yamlContents);
27+
28+
return [{
29+
fileType: path.extname(filePath),
30+
file: filePath,
31+
basePath: basePath,
32+
contents: contents,
33+
yaml: yamlJson
34+
}];
35+
}
36+
};
37+

config/demos/static-site/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = function(config) {
2+
3+
require('dgeni-packages/base')(config);
4+
require('dgeni-packages/nunjucks')(config);
5+
6+
config.append('source.fileReaders', [
7+
require('./file-readers/yaml')
8+
]);
9+
10+
config.append('processing.processors', [
11+
]);
12+
13+
return config;
14+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
3+
--------
4+
car: is fast
5+
tortoise: is slow
6+
---
7+
8+
9+
Some content
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Here's a title
2+
--------------
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
something: is here
3+
4+
5+
Hello there
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
hello: world
3+
works: true
4+
---
5+
6+
**Here's** some content.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
var fs = require('fs');
2+
var path = require('canonical-path');
3+
var processor = require('../../file-readers/yaml');
4+
5+
describe('yaml file-reader', function() {
6+
7+
function readTestFile(name) {
8+
return fs.readFileSync(path.resolve(__dirname, '_test-data', name)).toString();
9+
}
10+
11+
it('normal yaml header should process', function() {
12+
var contents = readTestFile('normal-header.md');
13+
14+
var result = processor.processFile('some/file.md', contents);
15+
expect(result.contents.trim()).toEqual('**Here\'s** some content.');
16+
expect(result.yaml).toEqual({hello: 'world', works: true});
17+
});
18+
19+
it('long yaml header should process', function() {
20+
var contents = readTestFile('long-header.md');
21+
22+
var result = processor.processFile('cool/file.md', contents);
23+
expect(result.contents.trim()).toEqual('Some content');
24+
expect(result.yaml).toEqual({car: 'is fast', tortoise: 'is slow'});
25+
});
26+
27+
['markdown-title.md', 'no-closing-header.md', 'no-header.md'].forEach(function(file) {
28+
it(file + ' should not be processed', function() {
29+
var contents = readTestFile(file);
30+
var result = processor.processFile('cool/file.md', contents);
31+
expect(result).toBeFalsy();
32+
});
33+
});
34+
35+
});

0 commit comments

Comments
 (0)