Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit 826e3da

Browse files
committed
Building shredMap tooling
1 parent df077c1 commit 826e3da

File tree

12 files changed

+507
-63
lines changed

12 files changed

+507
-63
lines changed

README.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,8 @@ Angular.io is currently the preview site for Angular 2. This site also includes
2020

2121
## Development setup with watches and browser reload
2222
1. cd into root directory `angular.io/`
23-
2. install `browser-sync`
24-
25-
`npm install -g browser-sync`<br/>
26-
27-
*or on Windows*<br/>
28-
29-
`npm install -g browser-sync --msvs_version=2013`
30-
31-
3. run `gulp serve-and-sync`
32-
4. browser will launch ( on localhost:3000 instead of localhost:9000) and stay refreshed automatically.
23+
2. run `gulp serve-and-sync`
24+
3. browser will launch ( on localhost:3000 instead of localhost:9000) and stay refreshed automatically.
3325

3426
## Technology Used
3527
- Angular 1.x: The production ready version of Angular

public/doc-shredder/doc-shredder.js

Lines changed: 136 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,7 @@ var delPromise = Q.denodeify(del);
77
var Dgeni = require('dgeni');
88
var _ = require('lodash');
99

10-
var createPackage = function(shredOptions) {
11-
var shredder = new Dgeni.Package('doc-shredder', [
12-
// require('dgeni-packages/base') - doesn't work
13-
]);
14-
shredder.options = resolveOptions(shredOptions);
15-
return configure(shredder);
16-
};
17-
18-
var resolveOptions = function(shredOptions) {
10+
var resolveShredOptions = function(shredOptions) {
1911
return _.defaults({}, shredOptions, {
2012
basePath: path.resolve('.'),
2113
// read files from any subdir under here
@@ -27,9 +19,20 @@ var resolveOptions = function(shredOptions) {
2719
});
2820
}
2921

22+
var resolveMapOptions = function(mapOptions) {
23+
return _.defaults({}, mapOptions, {
24+
basePath: path.resolve('.'),
25+
// read files from any subdir under here
26+
sourceDir: "docs",
27+
destDir: "docs",
28+
// whether to include subdirectories when shredding.
29+
includeSubdirs: true
30+
});
31+
}
32+
3033
var shred = function(shredOptions) {
3134
try {
32-
var pkg = createPackage(shredOptions);
35+
var pkg = createShredPackage(shredOptions);
3336
var dgeni = new Dgeni([ pkg]);
3437
return dgeni.generate();
3538
} catch(x) {
@@ -58,53 +61,41 @@ var shredSingleDir = function(shredOptions, filePath) {
5861
});
5962
}
6063

64+
var getShredMap = function(shredMapOptions) {
65+
try {
66+
var pkg = createShredMapPackage(shredMapOptions);
67+
var dgeni = new Dgeni([ pkg]);
68+
return dgeni.generate();
69+
} catch(x) {
70+
console.log(x.stack);
71+
throw x;
72+
}
73+
}
74+
75+
6176
module.exports = {
6277
shred: shred,
6378
shredSingleDir: shredSingleDir,
64-
createPackage: createPackage,
65-
resolveOptions: resolveOptions
79+
resolveShredOptions: resolveShredOptions,
80+
getShredMap: getShredMap
6681
};
6782

68-
function configure(shredder) {
69-
var options = shredder.options;
70-
shredder
71-
.processor(require('dgeni-packages/base/processors/read-files'))
72-
.processor(require('dgeni-packages/base/processors/write-files'))
73-
.factory(require('dgeni-packages/base/services/writefile'))
74-
75-
// Ugh... Boilerplate that dgeni needs to sequence operations
76-
.processor({ name: 'reading-files' })
77-
.processor({ name: 'files-read', $runAfter: ['reading-files'] })
78-
.processor({ name: 'processing-docs', $runAfter: ['files-read'] })
79-
.processor({ name: 'docs-processed', $runAfter: ['processing-docs'] })
80-
.processor({ name: 'adding-extra-docs', $runAfter: ['docs-processed'] })
81-
.processor({ name: 'extra-docs-added', $runAfter: ['adding-extra-docs'] })
82-
.processor({ name: 'computing-ids', $runAfter: ['extra-docs-added'] })
83-
.processor({ name: 'ids-computed', $runAfter: ['computing-ids'] })
84-
.processor({ name: 'computing-paths', $runAfter: ['ids-computed'] })
85-
.processor({ name: 'paths-computed', $runAfter: ['computing-paths'] })
86-
.processor({ name: 'rendering-docs', $runAfter: ['paths-computed'] })
87-
.processor({ name: 'docs-rendered', $runAfter: ['rendering-docs'] })
88-
.processor({ name: 'writing-files', $runAfter: ['docs-rendered'] })
89-
.processor({ name: 'files-written', $runAfter: ['writing-files'] })
83+
function createShredPackage(shredOptions) {
84+
var pkg = new Dgeni.Package('doc-shredder', [
85+
// require('dgeni-packages/base') - doesn't work
86+
]);
87+
var options = resolveShredOptions(shredOptions);
9088

89+
initializePackage(pkg)
9190
.factory(require('./fileShredder'))
9291
.factory(require('./regionExtractor'))
9392
.processor(require('./mdWrapperProcessor'))
9493

95-
.config(function(log) {
96-
// Set logging level
97-
log.level = 'info';
98-
})
99-
100-
10194
.config(function(readFilesProcessor, fileShredder ) {
10295
readFilesProcessor.fileReaders = [ fileShredder];
10396
})
104-
10597
// default configs - may be overriden
10698
.config(function(readFilesProcessor) {
107-
10899
// Specify the base path used when resolving relative paths to source and output files
109100
readFilesProcessor.basePath = options.basePath;
110101

@@ -117,20 +108,113 @@ function configure(shredder) {
117108
return path.join(options.sourceDir, extn);
118109
}
119110
});
120-
readFilesProcessor.sourceFiles = [
121-
{
122-
// Process all candidate files in `src` and its subfolders ...
123-
include: includeFiles,
124-
125-
// When calculating the relative path to these files use this as the base path.
126-
// So `src/foo/bar.js` will have relative path of `foo/bar.js`
127-
basePath: options.sourceDir
111+
readFilesProcessor.sourceFiles = [ {
112+
// Process all candidate files in `src` and its subfolders ...
113+
include: includeFiles,
114+
// When calculating the relative path to these files use this as the base path.
115+
// So `src/foo/bar.js` will have relative path of `foo/bar.js`
116+
basePath: options.sourceDir
117+
} ];
118+
})
119+
.config(function(writeFilesProcessor) {
120+
// Specify where the writeFilesProcessor will write our generated doc files
121+
writeFilesProcessor.outputFolder = options.destDir;
122+
});
123+
return pkg;
124+
}
125+
126+
var createShredMapPackage = function(mapOptions) {
127+
var pkg = new Dgeni.Package('docshred-mapper', [
128+
require('dgeni-packages/base'),
129+
require('dgeni-packages/nunjucks')
130+
]);
131+
var options = resolveMapOptions(mapOptions);
132+
133+
initializePackage(pkg)
134+
.factory(require('./extractPathsReader'))
135+
.processor(require('./shredMapProcessor'))
136+
137+
.config(function(readFilesProcessor, extractPathsReader ) {
138+
readFilesProcessor.fileReaders = [ extractPathsReader];
139+
})
140+
// default configs - may be overriden
141+
.config(function(readFilesProcessor) {
142+
// Specify the base path used when resolving relative paths to source and output files
143+
readFilesProcessor.basePath = options.basePath;
144+
145+
// Specify collections of source files that should contain the documentation to extract
146+
var extns = ['*.jade' ];
147+
var includeFiles = extns.map(function(extn) {
148+
if (options.includeSubdirs) {
149+
return path.join(options.sourceDir, '**', extn);
150+
} else {
151+
return path.join(options.sourceDir, extn);
128152
}
129-
];
153+
});
154+
readFilesProcessor.sourceFiles = [ {
155+
// Process all candidate files in `src` and its subfolders ...
156+
include: includeFiles,
157+
// When calculating the relative path to these files use this as the base path.
158+
// So `src/foo/bar.js` will have relative path of `foo/bar.js`
159+
basePath: options.sourceDir
160+
} ];
130161
})
131162
.config(function(writeFilesProcessor) {
132163
// Specify where the writeFilesProcessor will write our generated doc files
133164
writeFilesProcessor.outputFolder = options.destDir;
165+
})
166+
.config(function(templateFinder) {
167+
// Add a folder to search for our own templates to use when rendering docs
168+
templateFinder.templateFolders = [ path.resolve(__dirname) ];
169+
170+
// Specify how to match docs to templates.
171+
// In this case we just use the same static template for all docs
172+
templateFinder.templatePatterns = [ '${ doc.docType }.template' ];
173+
})
174+
.config(function(computePathsProcessor, computeIdsProcessor) {
175+
computePathsProcessor.$enabled = false;
176+
computeIdsProcessor.$enabled = false;
177+
//computePathsProcessor.pathTemplates.push({
178+
// docTypes: ['foo'],
179+
// pathTemplate: '',
180+
// getOutputPath: function () {
181+
// },
182+
//});
183+
//
184+
//computeIdsProcessor.idTemplates.push({
185+
// docTypes: ['foo'],
186+
// getAliases: function (doc) {
187+
// return [doc.id];
188+
// }
189+
//});
134190
});
135-
return shredder;
191+
192+
return pkg;
136193
}
194+
195+
function initializePackage(pkg) {
196+
return pkg
197+
.processor(require('dgeni-packages/base/processors/read-files'))
198+
.processor(require('dgeni-packages/base/processors/write-files'))
199+
.factory(require('dgeni-packages/base/services/writefile'))
200+
201+
// Ugh... Boilerplate that dgeni needs to sequence operations
202+
.processor({ name: 'reading-files' })
203+
.processor({ name: 'files-read', $runAfter: ['reading-files'] })
204+
.processor({ name: 'processing-docs', $runAfter: ['files-read'] })
205+
.processor({ name: 'docs-processed', $runAfter: ['processing-docs'] })
206+
.processor({ name: 'adding-extra-docs', $runAfter: ['docs-processed'] })
207+
.processor({ name: 'extra-docs-added', $runAfter: ['adding-extra-docs'] })
208+
.processor({ name: 'computing-ids', $runAfter: ['extra-docs-added'] })
209+
.processor({ name: 'ids-computed', $runAfter: ['computing-ids'] })
210+
.processor({ name: 'computing-paths', $runAfter: ['ids-computed'] })
211+
.processor({ name: 'paths-computed', $runAfter: ['computing-paths'] })
212+
.processor({ name: 'rendering-docs', $runAfter: ['paths-computed'] })
213+
.processor({ name: 'docs-rendered', $runAfter: ['rendering-docs'] })
214+
.processor({ name: 'writing-files', $runAfter: ['docs-rendered'] })
215+
.processor({ name: 'files-written', $runAfter: ['writing-files'] })
216+
.config(function(log) {
217+
// Set logging level
218+
log.level = 'info';
219+
})
220+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @dgService htmlFileShredder
3+
* @description
4+
*/
5+
6+
var path = require('canonical-path');
7+
8+
module.exports = function extractPathsReader(log) {
9+
var rx = /\s*\+makeTabs\(\s*["'](.*?)["']\s*,\s*["'](.*?)["'].*?\)/g
10+
return {
11+
name: 'extractPathsReader',
12+
13+
getDocs: function (fileInfo) {
14+
var content = fileInfo.content;
15+
var refPaths = [];
16+
var r;
17+
while ((r = rx.exec(content)) !== null) {
18+
var basePath = r[1];
19+
var fileNames = r[2].split(',');
20+
fileNames.forEach(function(fn) {
21+
refPaths.push(path.join(basePath, fn));
22+
})
23+
}
24+
if (refPaths.length) {
25+
return [{
26+
refPaths: refPaths
27+
}];
28+
} else {
29+
return [];
30+
}
31+
}
32+
}
33+
}
34+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* dgProcessor shredMapProcessor
3+
* @description
4+
*
5+
*/
6+
module.exports = function shredMapProcessor(log) {
7+
return {
8+
$runAfter: ['readFilesProcessor'],
9+
$runBefore: ['rendering-docs'],
10+
$process: function(docs) {
11+
var docMaps = []
12+
docs.forEach(function(doc) {
13+
var docMap = {
14+
jadePath: doc.fileInfo.filePath,
15+
jadeRelativePath: doc.fileInfo.projectRelativePath,
16+
refPaths: doc.refPaths
17+
}
18+
docMaps.push(docMap);
19+
});
20+
var newDocs = [{
21+
docType: 'xref-doc.html',
22+
docMaps: docMaps,
23+
outputPath: 'xref-doc.html'
24+
}, {
25+
docType: 'xref-doc.js',
26+
json: JSON.stringify(docMaps),
27+
outputPath: 'xref-doc.js'
28+
}]
29+
return newDocs;
30+
}
31+
};
32+
};

public/doc-shredder/test/gulpfile.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var watch = require('gulp-watch');
66

77
var docShredder = require('../doc-shredder');
88

9-
var shredOptions = docShredder.resolveOptions({
9+
var shredOptions = docShredder.resolveShredOptions({
1010
sourceDir: "test_source",
1111
destDir: "test_fragments"
1212
});
@@ -32,6 +32,16 @@ gulp.task('watch', function (cb) {
3232
});
3333
});
3434

35+
gulp.task('map', function() {
36+
var options = {
37+
sourceDir: 'test_jade',
38+
destDir: 'test_jade'
39+
}
40+
return docShredder.getShredMap(options).then(function(x) {
41+
var docMaps = x.docMaps;
42+
})
43+
44+
});
3545

3646
gulp.task('default', ['shred']);
3747

public/doc-shredder/test/report.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Jade file -> Example file cross references
2+
3+
Jade file: - C:/xxx/yyy/zzz
4+
References:
5+
- a/b/c
6+
- b/d/e

0 commit comments

Comments
 (0)