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

Commit 903f59b

Browse files
committed
clean up regionExtractor to hoist nullLine pattern,
add examplesDir to xref info
1 parent 64ea3b6 commit 903f59b

File tree

8 files changed

+108
-65
lines changed

8 files changed

+108
-65
lines changed

public/doc-shredder/regionExtractor.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
module.exports = function regionExtractor() {
2+
3+
var nullLine = '###';
4+
var nullLinePattern = new RegExp(nullLine + '\n', 'g');
5+
26
// split out each fragment in {content} into a separate doc
37
// a fragment is a section of text surrounded by
48
// 1) In front: a comment marker followed by '#docregion' followed by an optional region name. For example:
@@ -12,7 +16,6 @@ module.exports = function regionExtractor() {
1216
var docs = [];
1317
var docStack = [];
1418
var doc = null;
15-
var nullLine = '###';
1619

1720
lines.forEach(function(line, ix) {
1821
if (isCommentLine(line, commentPrefixes)) {
@@ -29,7 +32,7 @@ module.exports = function regionExtractor() {
2932
}
3033
});
3134

32-
var rx = new RegExp(nullLine + '\n', 'g');
35+
3336
docs.forEach(function(doc) {
3437
var content;
3538
if (doc.endIx) {
@@ -38,7 +41,7 @@ module.exports = function regionExtractor() {
3841
content = lines.slice(doc.startIx + 1).join('\n');
3942
}
4043
// eliminate all #docregion lines
41-
content = content.replace(rx, '');
44+
content = content.replace(nullLinePattern, '');
4245
if (content.substr(-3) === nullLine) {
4346
content = content.substr(0, content.length-3);
4447
}

public/doc-shredder/shredMapProcessor.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ module.exports = function shredMapProcessor(log) {
1515
var options = this.options;
1616
var jadeToFragMap = {};
1717
var fragToJadeMap = {};
18+
1819
docs.forEach(function(doc) {
1920
var jadePath = path.join(options.jadeDir, doc.fileInfo.relativePath);
2021
var fragInfos = doc.fragPaths.map(function(fragPath) {
21-
fragPath = path.join(options.fragmentsDir, fragPath) + '.md';
22-
var fullPath = path.join(options.basePath, fragPath);
23-
var fragInfo = { fragPath: fragPath, exists: fs.existsSync(fullPath) };
22+
var relativeFragPath = path.join(options.fragmentsDir, fragPath) + '.md';
23+
var fullPath = path.join(options.basePath, relativeFragPath);
24+
var examplePath = getExampleName(fragPath);
25+
var relativeExamplePath = path.join(options.examplesDir, examplePath);
26+
var fragInfo = { fragPath: relativeFragPath, examplePath: relativeExamplePath, exists: fs.existsSync(fullPath) };
2427
if (fragInfo.exists) {
2528
var jadePaths = fragToJadeMap[fragInfo];
2629
if (!jadePaths) {
@@ -54,4 +57,15 @@ module.exports = function shredMapProcessor(log) {
5457
return newDocs;
5558
}
5659
};
57-
};
60+
};
61+
62+
function getExampleName(fragPath) {
63+
// pattern to isolate base fileName and extension from fragment name
64+
var rx = /(.*)\-(.*)\.(.s)/;
65+
var r = rx.exec(fragPath);
66+
if (r) {
67+
return r[1] + '.' + r[3];
68+
} else {
69+
return fragPath;
70+
}
71+
}

public/doc-shredder/test/xref-frag-to-jade.html

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,39 @@ <h1> Frament path to jade path cross reference report
44
<ol>
55

66
<li>
7-
Fragment file: <strong>test_fragments/gettingstarted/ts/index.html.md</strong>
7+
Fragment file: <strong>gettingstarted/ts/index.html</strong>
88
<p>Jade files</p>
99
<ul>
1010
<li>test_jade/guides/setupAlt2.jade</li>
1111
</ul>
1212
<br>
1313
</li>
1414
<li>
15-
Fragment file: <strong>test_fragments/gettingstarted/js/index.html.md</strong>
15+
Fragment file: <strong>gettingstarted/js/index.html</strong>
1616
<p>Jade files</p>
1717
<ul>
1818
<li>test_jade/setupAlt.jade</li>
1919
</ul>
2020
<br>
2121
</li>
2222
<li>
23-
Fragment file: <strong>test_fragments/gettingstarted/ts/main.ts.md</strong>
23+
Fragment file: <strong>gettingstarted/ts/main.ts</strong>
2424
<p>Jade files</p>
2525
<ul>
2626
<li>test_jade/setupAlt.jade</li>
2727
</ul>
2828
<br>
2929
</li>
3030
<li>
31-
Fragment file: <strong>test_fragments/gettingstarted/ts/main-import.ts.md</strong>
31+
Fragment file: <strong>gettingstarted/js/main.js</strong>
32+
<p>Jade files</p>
33+
<ul>
34+
<li>test_jade/guides/setupAlt2.jade</li>
35+
</ul>
36+
<br>
37+
</li>
38+
<li>
39+
Fragment file: <strong>gettingstarted/ts/main-import.ts</strong>
3240
<p>Jade files</p>
3341
<ul>
3442
<li>test_jade/setupAlt.jade</li>

public/doc-shredder/test/xref-jade-to-frag.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ <h1> Jade path to fragment path cross reference report
66
<li>
77
Jade file: <strong>test_jade/guides/setupAlt2.jade</strong>
88
<p>Fragment files</p>
9-
<ul><li>test_fragments/gettingstarted/ts/index.html.md</li><li>test_fragments/gettingstarted/js/index.html.md</li><li>test_fragments/gettingstarted/ts/main.ts.md</li><li> *** NOT FOUND*** : test_fragments/gettingstarted/ js/main.js.md</li><li>test_fragments/gettingstarted/ts/main-import.ts.md</li>
9+
<ul><li>test_fragments/gettingstarted/ts/index.html.md</li><li>test_fragments/gettingstarted/js/index.html.md</li><li>test_fragments/gettingstarted/ts/main.ts.md</li><li>test_fragments/gettingstarted/js/main.js.md</li><li>test_fragments/gettingstarted/ts/main-import.ts.md</li>
1010
</ul>
1111
<br>
1212
</li>
1313
<li>
1414
Jade file: <strong>test_jade/setupAlt.jade</strong>
1515
<p>Fragment files</p>
16-
<ul><li> *** NOT FOUND*** : test_fragments/gettingstarted/ts/index2.html.md</li><li>test_fragments/gettingstarted/js/index.html.md</li><li>test_fragments/gettingstarted/ts/main.ts.md</li><li> *** NOT FOUND*** : test_fragments/gettingstarted/ js/main2.js.md</li><li>test_fragments/gettingstarted/ts/main-import.ts.md</li>
16+
<ul><li> *** NOT FOUND*** : test_fragments/gettingstarted/ts/index2.html.md</li><li>test_fragments/gettingstarted/js/index.html.md</li><li>test_fragments/gettingstarted/ts/main.ts.md</li><li> *** NOT FOUND*** : test_fragments/gettingstarted/js/main2.js.md</li><li>test_fragments/gettingstarted/ts/main-import.ts.md</li>
1717
</ul>
1818
<br>
1919
</li>
Lines changed: 57 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,59 @@
11
{
2-
"test_jade/guides/setupAlt2.jade": [
3-
{
4-
"fragPath": "test_fragments/gettingstarted/ts/index.html.md",
5-
"exists": true
6-
},
7-
{
8-
"fragPath": "test_fragments/gettingstarted/js/index.html.md",
9-
"exists": true
10-
},
11-
{
12-
"fragPath": "test_fragments/gettingstarted/ts/main.ts.md",
13-
"exists": true
14-
},
15-
{
16-
"fragPath": "test_fragments/gettingstarted/ js/main.js.md",
17-
"exists": false
18-
},
19-
{
20-
"fragPath": "test_fragments/gettingstarted/ts/main-import.ts.md",
21-
"exists": true
22-
}
23-
],
24-
"test_jade/setupAlt.jade": [
25-
{
26-
"fragPath": "test_fragments/gettingstarted/ts/index2.html.md",
27-
"exists": false
28-
},
29-
{
30-
"fragPath": "test_fragments/gettingstarted/js/index.html.md",
31-
"exists": true
32-
},
33-
{
34-
"fragPath": "test_fragments/gettingstarted/ts/main.ts.md",
35-
"exists": true
36-
},
37-
{
38-
"fragPath": "test_fragments/gettingstarted/ js/main2.js.md",
39-
"exists": false
40-
},
41-
{
42-
"fragPath": "test_fragments/gettingstarted/ts/main-import.ts.md",
43-
"exists": true
44-
}
45-
]
2+
"basePath": "c:/GitHub/angular.io.ideablade/public/doc-shredder/test",
3+
"jadeToFragMap": {
4+
"test_jade/guides/setupAlt2.jade": [
5+
{
6+
"fragPath": "test_fragments/gettingstarted/ts/index.html.md",
7+
"examplePath": "test_source/gettingstarted/ts/index.html",
8+
"exists": true
9+
},
10+
{
11+
"fragPath": "test_fragments/gettingstarted/js/index.html.md",
12+
"examplePath": "test_source/gettingstarted/js/index.html",
13+
"exists": true
14+
},
15+
{
16+
"fragPath": "test_fragments/gettingstarted/ts/main.ts.md",
17+
"examplePath": "test_source/gettingstarted/ts/main.ts",
18+
"exists": true
19+
},
20+
{
21+
"fragPath": "test_fragments/gettingstarted/js/main.js.md",
22+
"examplePath": "test_source/gettingstarted/js/main.js",
23+
"exists": true
24+
},
25+
{
26+
"fragPath": "test_fragments/gettingstarted/ts/main-import.ts.md",
27+
"examplePath": "test_source/gettingstarted/ts/main.ts",
28+
"exists": true
29+
}
30+
],
31+
"test_jade/setupAlt.jade": [
32+
{
33+
"fragPath": "test_fragments/gettingstarted/ts/index2.html.md",
34+
"examplePath": "test_source/gettingstarted/ts/index2.html",
35+
"exists": false
36+
},
37+
{
38+
"fragPath": "test_fragments/gettingstarted/js/index.html.md",
39+
"examplePath": "test_source/gettingstarted/js/index.html",
40+
"exists": true
41+
},
42+
{
43+
"fragPath": "test_fragments/gettingstarted/ts/main.ts.md",
44+
"examplePath": "test_source/gettingstarted/ts/main.ts",
45+
"exists": true
46+
},
47+
{
48+
"fragPath": "test_fragments/gettingstarted/js/main2.js.md",
49+
"examplePath": "test_source/gettingstarted/js/main2.js",
50+
"exists": false
51+
},
52+
{
53+
"fragPath": "test_fragments/gettingstarted/ts/main-import.ts.md",
54+
"examplePath": "test_source/gettingstarted/ts/main.ts",
55+
"exists": true
56+
}
57+
]
58+
}
4659
}

public/docs/xref-frag-to-jade.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
<h1> Frament path to jade path cross reference report
22

3-
<p>Base path: c:\GitHub\angular.io.ideablade\public\docs</p>
3+
<p>Base path: C:\GitHub\angular.io.ideablade\public\docs</p>
44
<ol>
55

66
<li>
7-
Fragment file: <strong>_fragments/gettingstarted/ts/index.html.md</strong>
7+
Fragment file: <strong>gettingstarted/ts/index.html</strong>
88
<p>Jade files</p>
99
<ul>
1010
<li>js/latest/guide/setupAlt.jade</li>
1111
</ul>
1212
<br>
1313
</li>
1414
<li>
15-
Fragment file: <strong>_fragments/gettingstarted/js/index.html.md</strong>
15+
Fragment file: <strong>gettingstarted/js/index.html</strong>
1616
<p>Jade files</p>
1717
<ul>
1818
<li>js/latest/guide/setupAlt.jade</li>
1919
</ul>
2020
<br>
2121
</li>
2222
<li>
23-
Fragment file: <strong>_fragments/gettingstarted/ts/main.ts.md</strong>
23+
Fragment file: <strong>gettingstarted/ts/main.ts</strong>
2424
<p>Jade files</p>
2525
<ul>
2626
<li>js/latest/guide/setupAlt.jade</li>
2727
</ul>
2828
<br>
2929
</li>
3030
<li>
31-
Fragment file: <strong>_fragments/gettingstarted/js/main.js.md</strong>
31+
Fragment file: <strong>gettingstarted/js/main.js</strong>
3232
<p>Jade files</p>
3333
<ul>
3434
<li>js/latest/guide/setupAlt.jade</li>
3535
</ul>
3636
<br>
3737
</li>
3838
<li>
39-
Fragment file: <strong>_fragments/gettingstarted/ts/main-import.ts.md</strong>
39+
Fragment file: <strong>gettingstarted/ts/main-import.ts</strong>
4040
<p>Jade files</p>
4141
<ul>
4242
<li>js/latest/guide/setupAlt.jade</li>

public/docs/xref-jade-to-frag.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<h1> Jade path to fragment path cross reference report
22

3-
<p>Base path: c:\GitHub\angular.io.ideablade\public\docs</p>
3+
<p>Base path: C:\GitHub\angular.io.ideablade\public\docs</p>
44
<ol>
55

66
<li>

public/docs/xref-jade.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11
{
2-
"basePath": "c:\\GitHub\\angular.io.ideablade\\public\\docs",
2+
"basePath": "C:\\GitHub\\angular.io.ideablade\\public\\docs",
33
"jadeToFragMap": {
44
"js/latest/guide/setupAlt.jade": [
55
{
66
"fragPath": "_fragments/gettingstarted/ts/index.html.md",
7+
"examplePath": "_examples/gettingstarted/ts/index.html",
78
"exists": true
89
},
910
{
1011
"fragPath": "_fragments/gettingstarted/js/index.html.md",
12+
"examplePath": "_examples/gettingstarted/js/index.html",
1113
"exists": true
1214
},
1315
{
1416
"fragPath": "_fragments/gettingstarted/ts/main.ts.md",
17+
"examplePath": "_examples/gettingstarted/ts/main.ts",
1518
"exists": true
1619
},
1720
{
1821
"fragPath": "_fragments/gettingstarted/js/main.js.md",
22+
"examplePath": "_examples/gettingstarted/js/main.js",
1923
"exists": true
2024
},
2125
{
2226
"fragPath": "_fragments/gettingstarted/ts/main-import.ts.md",
27+
"examplePath": "_examples/gettingstarted/ts/main.ts",
2328
"exists": true
2429
}
2530
]

0 commit comments

Comments
 (0)