forked from ionic-team/ionic-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(): move demos out of source files
- Loading branch information
Showing
167 changed files
with
2,739 additions
and
1,379 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
var path = require('canonical-path'); | ||
var _ = require('lodash'); | ||
var staticSite = require('./static-site'); | ||
|
||
var projectBase = path.resolve(__dirname, '../..'); | ||
|
||
module.exports = function(config) { | ||
|
||
config = staticSite(config); | ||
|
||
config.merge('rendering.nunjucks.config.tags', { | ||
variableStart: '{$', | ||
variableEnd: '$}', | ||
blockStart: '{%', | ||
blockEnd: '%}' | ||
}); | ||
|
||
config.set('logging.level', 'info'); | ||
|
||
config.set('rendering.outputFolder', path.resolve(projectBase, 'dist/ionic-demo')); | ||
|
||
config.set('rendering.templateFolders', [ | ||
path.resolve(__dirname, 'templates') | ||
]); | ||
config.set('rendering.templatePatterns', [ | ||
'${ doc.template }', | ||
'${doc.area}/${ doc.id }.${ doc.docType }.template.html', | ||
'${doc.area}/${ doc.id }.template.html', | ||
'${doc.area}/${ doc.docType }.template.html', | ||
'${ doc.id }.${ doc.docType }.template.html', | ||
'${ doc.id }.template.html', | ||
'${ doc.docType }.template.html' | ||
]); | ||
|
||
config.append('processing.processors', [ | ||
require('../docs/processors/version-data'), | ||
require('./processors/demos') | ||
]); | ||
|
||
config.set('basePath', __dirname); | ||
config.set('source.projectPath', '.'); | ||
|
||
config.set('source.files', [ | ||
{ pattern: 'demos/**/*.html', basePath: projectBase }, | ||
{ pattern: 'demos/**/*.js', basePath: projectBase }, | ||
{ pattern: 'demos/**/*.css', basePath: projectBase } | ||
]); | ||
|
||
|
||
return config; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
var _ = require('lodash'); | ||
var log = require('dgeni').log; | ||
var path = require('canonical-path'); | ||
|
||
var typeTransform = { | ||
markdown: 'md' | ||
}; | ||
|
||
module.exports = { | ||
name: 'demos', | ||
description: 'Output demos to their files on ionic-demo website', | ||
runAfter: ['files-read'], | ||
runBefore: ['processing-docs'], | ||
process: function(docs, config) { | ||
|
||
var contentsFolder = config.rendering.contentsFolder; | ||
var assetOutputPath = path.join(contentsFolder, '${component}/${name}/${fileName}'); | ||
|
||
var pages = []; | ||
|
||
var demos = _(docs) | ||
.filter('yaml') | ||
.groupBy(function(doc) { | ||
return doc.yaml.component + '-' + doc.yaml.name; | ||
}) | ||
.map(function(fragmentsForId, id) { | ||
|
||
var demoData = { | ||
files: [] | ||
}; | ||
fragmentsForId.forEach(function(fragment) { | ||
var doc = fragment.yaml; | ||
if (!doc.name || !doc.component) { | ||
log.error('Doc ' + fragment.filePath + | ||
' expects yaml keys "name" and "component"!'); | ||
} | ||
|
||
doc.id = doc.component + '-' + doc.name; | ||
doc.fileType = typeTransform[fragment.fileType] || fragment.fileType; | ||
doc.fileName = fragment.fileName; | ||
doc.contents = fragment.contents; | ||
doc.extension = doc.fileType.replace(/^\./,''); | ||
|
||
doc.template = 'asset.contents.template', | ||
doc.outputPath = _.template(assetOutputPath, doc); | ||
|
||
demoData.files.push(doc); | ||
pages.push(doc); | ||
}); | ||
|
||
var firstDoc = demoData.files[0]; | ||
|
||
var indexOutputPath = _.template(assetOutputPath, _.assign({}, firstDoc, { | ||
fileName: 'index.html' | ||
})); | ||
var appOutputPath = _.template(assetOutputPath, _.assign({}, firstDoc, { | ||
fileName: 'index-ionic-demo-app.js' | ||
}, demoData)); | ||
|
||
|
||
demoData.files = _.groupBy(demoData.files, 'extension'); | ||
demoData.id = firstDoc.id; | ||
demoData.name = firstDoc.name; | ||
demoData.component = firstDoc.component; | ||
demoData.href = '/' + _.template(assetOutputPath, _.assign({}, firstDoc, { fileName: '' })); | ||
|
||
pages.push({ | ||
template: 'index.template.html', | ||
demoData: demoData, | ||
outputPath: indexOutputPath | ||
}); | ||
pages.push({ | ||
template: 'app.template.js', | ||
demoData: demoData, | ||
outputPath: appOutputPath | ||
}); | ||
|
||
return demoData; | ||
|
||
}) | ||
.value(); | ||
|
||
pages.push({ | ||
template: 'pages-data.template.js', | ||
demos: demos, | ||
outputPath: path.join(contentsFolder, 'pages-data.js') | ||
}); | ||
pages.push({ | ||
template: 'index.template.html', | ||
outputPath: path.join(contentsFolder, 'index.html') | ||
}); | ||
pages.push({ | ||
template: 'app.template.js', | ||
outputPath: path.join(contentsFolder, 'index-ionic-demo-app.js') | ||
}); | ||
|
||
return pages; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
var jsYaml = require('js-yaml'); | ||
var path = require('canonical-path'); | ||
var YAML_LINE_REGEX = /---+/; | ||
|
||
module.exports = { | ||
pattern: /\.*$/, | ||
processFile: function(filePath, contents, basePath) { | ||
|
||
contents = contents.trim(); | ||
|
||
var yamlStartMatch = contents.match(YAML_LINE_REGEX); | ||
if (!yamlStartMatch || yamlStartMatch.index !== 0) { | ||
return []; | ||
} | ||
|
||
var yamlContents = contents.substring(yamlStartMatch.index + yamlStartMatch[0].length + 1); | ||
|
||
var yamlEndMatch = yamlContents.match(YAML_LINE_REGEX); | ||
if (!yamlEndMatch) { | ||
return []; | ||
} | ||
|
||
contents = yamlContents.substring(yamlEndMatch.index + yamlEndMatch[0].length); | ||
yamlContents = yamlContents.substring(0, yamlEndMatch.index); | ||
|
||
var yamlJson = jsYaml.safeLoad(yamlContents); | ||
|
||
return [{ | ||
fileType: path.extname(filePath), | ||
file: filePath, | ||
basePath: basePath, | ||
contents: contents, | ||
yaml: yamlJson | ||
}]; | ||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module.exports = function(config) { | ||
|
||
require('dgeni-packages/base')(config); | ||
require('dgeni-packages/nunjucks')(config); | ||
|
||
config.append('source.fileReaders', [ | ||
require('./file-readers/yaml') | ||
]); | ||
|
||
config.append('processing.processors', [ | ||
]); | ||
|
||
return config; | ||
}; |
9 changes: 9 additions & 0 deletions
9
config/demos/static-site/spec/file-readers/_test-data/long-header.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
|
||
-------- | ||
car: is fast | ||
tortoise: is slow | ||
--- | ||
|
||
|
||
Some content |
2 changes: 2 additions & 0 deletions
2
config/demos/static-site/spec/file-readers/_test-data/markdown-title.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Here's a title | ||
-------------- |
5 changes: 5 additions & 0 deletions
5
config/demos/static-site/spec/file-readers/_test-data/no-closing-header.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
something: is here | ||
|
||
|
||
Hello there |
1 change: 1 addition & 0 deletions
1
config/demos/static-site/spec/file-readers/_test-data/no-header.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hello |
6 changes: 6 additions & 0 deletions
6
config/demos/static-site/spec/file-readers/_test-data/normal-header.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
hello: world | ||
works: true | ||
--- | ||
|
||
**Here's** some content. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
var fs = require('fs'); | ||
var path = require('canonical-path'); | ||
var processor = require('../../file-readers/yaml'); | ||
|
||
describe('yaml file-reader', function() { | ||
|
||
function readTestFile(name) { | ||
return fs.readFileSync(path.resolve(__dirname, '_test-data', name)).toString(); | ||
} | ||
|
||
it('normal yaml header should process', function() { | ||
var contents = readTestFile('normal-header.md'); | ||
|
||
var result = processor.processFile('some/file.md', contents); | ||
expect(result.contents.trim()).toEqual('**Here\'s** some content.'); | ||
expect(result.yaml).toEqual({hello: 'world', works: true}); | ||
}); | ||
|
||
it('long yaml header should process', function() { | ||
var contents = readTestFile('long-header.md'); | ||
|
||
var result = processor.processFile('cool/file.md', contents); | ||
expect(result.contents.trim()).toEqual('Some content'); | ||
expect(result.yaml).toEqual({car: 'is fast', tortoise: 'is slow'}); | ||
}); | ||
|
||
['markdown-title.md', 'no-closing-header.md', 'no-header.md'].forEach(function(file) { | ||
it(file + ' should not be processed', function() { | ||
var contents = readTestFile(file); | ||
var result = processor.processFile('cool/file.md', contents); | ||
expect(result).toBeFalsy(); | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{$ doc.contents $} |
Oops, something went wrong.