clean up regionExtractor to hoist nullLine pattern,

add examplesDir to xref info
This commit is contained in:
Jay Traband 2015-08-11 11:55:22 -07:00
parent 64ea3b6f9a
commit 903f59b8ee
8 changed files with 108 additions and 65 deletions

View File

@ -1,4 +1,8 @@
module.exports = function regionExtractor() {
var nullLine = '###';
var nullLinePattern = new RegExp(nullLine + '\n', 'g');
// split out each fragment in {content} into a separate doc
// a fragment is a section of text surrounded by
// 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() {
var docs = [];
var docStack = [];
var doc = null;
var nullLine = '###';
lines.forEach(function(line, ix) {
if (isCommentLine(line, commentPrefixes)) {
@ -29,7 +32,7 @@ module.exports = function regionExtractor() {
}
});
var rx = new RegExp(nullLine + '\n', 'g');
docs.forEach(function(doc) {
var content;
if (doc.endIx) {
@ -38,7 +41,7 @@ module.exports = function regionExtractor() {
content = lines.slice(doc.startIx + 1).join('\n');
}
// eliminate all #docregion lines
content = content.replace(rx, '');
content = content.replace(nullLinePattern, '');
if (content.substr(-3) === nullLine) {
content = content.substr(0, content.length-3);
}

View File

@ -15,12 +15,15 @@ module.exports = function shredMapProcessor(log) {
var options = this.options;
var jadeToFragMap = {};
var fragToJadeMap = {};
docs.forEach(function(doc) {
var jadePath = path.join(options.jadeDir, doc.fileInfo.relativePath);
var fragInfos = doc.fragPaths.map(function(fragPath) {
fragPath = path.join(options.fragmentsDir, fragPath) + '.md';
var fullPath = path.join(options.basePath, fragPath);
var fragInfo = { fragPath: fragPath, exists: fs.existsSync(fullPath) };
var relativeFragPath = path.join(options.fragmentsDir, fragPath) + '.md';
var fullPath = path.join(options.basePath, relativeFragPath);
var examplePath = getExampleName(fragPath);
var relativeExamplePath = path.join(options.examplesDir, examplePath);
var fragInfo = { fragPath: relativeFragPath, examplePath: relativeExamplePath, exists: fs.existsSync(fullPath) };
if (fragInfo.exists) {
var jadePaths = fragToJadeMap[fragInfo];
if (!jadePaths) {
@ -55,3 +58,14 @@ module.exports = function shredMapProcessor(log) {
}
};
};
function getExampleName(fragPath) {
// pattern to isolate base fileName and extension from fragment name
var rx = /(.*)\-(.*)\.(.s)/;
var r = rx.exec(fragPath);
if (r) {
return r[1] + '.' + r[3];
} else {
return fragPath;
}
}

View File

@ -4,7 +4,7 @@
<ol>
<li>
Fragment file: <strong>test_fragments/gettingstarted/ts/index.html.md</strong>
Fragment file: <strong>gettingstarted/ts/index.html</strong>
<p>Jade files</p>
<ul>
<li>test_jade/guides/setupAlt2.jade</li>
@ -12,7 +12,7 @@
<br>
</li>
<li>
Fragment file: <strong>test_fragments/gettingstarted/js/index.html.md</strong>
Fragment file: <strong>gettingstarted/js/index.html</strong>
<p>Jade files</p>
<ul>
<li>test_jade/setupAlt.jade</li>
@ -20,7 +20,7 @@
<br>
</li>
<li>
Fragment file: <strong>test_fragments/gettingstarted/ts/main.ts.md</strong>
Fragment file: <strong>gettingstarted/ts/main.ts</strong>
<p>Jade files</p>
<ul>
<li>test_jade/setupAlt.jade</li>
@ -28,7 +28,15 @@
<br>
</li>
<li>
Fragment file: <strong>test_fragments/gettingstarted/ts/main-import.ts.md</strong>
Fragment file: <strong>gettingstarted/js/main.js</strong>
<p>Jade files</p>
<ul>
<li>test_jade/guides/setupAlt2.jade</li>
</ul>
<br>
</li>
<li>
Fragment file: <strong>gettingstarted/ts/main-import.ts</strong>
<p>Jade files</p>
<ul>
<li>test_jade/setupAlt.jade</li>

View File

@ -6,14 +6,14 @@
<li>
Jade file: <strong>test_jade/guides/setupAlt2.jade</strong>
<p>Fragment files</p>
<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>
<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>
</ul>
<br>
</li>
<li>
Jade file: <strong>test_jade/setupAlt.jade</strong>
<p>Fragment files</p>
<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>
<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>
</ul>
<br>
</li>

View File

@ -1,46 +1,59 @@
{
"test_jade/guides/setupAlt2.jade": [
{
"fragPath": "test_fragments/gettingstarted/ts/index.html.md",
"exists": true
},
{
"fragPath": "test_fragments/gettingstarted/js/index.html.md",
"exists": true
},
{
"fragPath": "test_fragments/gettingstarted/ts/main.ts.md",
"exists": true
},
{
"fragPath": "test_fragments/gettingstarted/ js/main.js.md",
"exists": false
},
{
"fragPath": "test_fragments/gettingstarted/ts/main-import.ts.md",
"exists": true
}
],
"test_jade/setupAlt.jade": [
{
"fragPath": "test_fragments/gettingstarted/ts/index2.html.md",
"exists": false
},
{
"fragPath": "test_fragments/gettingstarted/js/index.html.md",
"exists": true
},
{
"fragPath": "test_fragments/gettingstarted/ts/main.ts.md",
"exists": true
},
{
"fragPath": "test_fragments/gettingstarted/ js/main2.js.md",
"exists": false
},
{
"fragPath": "test_fragments/gettingstarted/ts/main-import.ts.md",
"exists": true
}
]
"basePath": "c:/GitHub/angular.io.ideablade/public/doc-shredder/test",
"jadeToFragMap": {
"test_jade/guides/setupAlt2.jade": [
{
"fragPath": "test_fragments/gettingstarted/ts/index.html.md",
"examplePath": "test_source/gettingstarted/ts/index.html",
"exists": true
},
{
"fragPath": "test_fragments/gettingstarted/js/index.html.md",
"examplePath": "test_source/gettingstarted/js/index.html",
"exists": true
},
{
"fragPath": "test_fragments/gettingstarted/ts/main.ts.md",
"examplePath": "test_source/gettingstarted/ts/main.ts",
"exists": true
},
{
"fragPath": "test_fragments/gettingstarted/js/main.js.md",
"examplePath": "test_source/gettingstarted/js/main.js",
"exists": true
},
{
"fragPath": "test_fragments/gettingstarted/ts/main-import.ts.md",
"examplePath": "test_source/gettingstarted/ts/main.ts",
"exists": true
}
],
"test_jade/setupAlt.jade": [
{
"fragPath": "test_fragments/gettingstarted/ts/index2.html.md",
"examplePath": "test_source/gettingstarted/ts/index2.html",
"exists": false
},
{
"fragPath": "test_fragments/gettingstarted/js/index.html.md",
"examplePath": "test_source/gettingstarted/js/index.html",
"exists": true
},
{
"fragPath": "test_fragments/gettingstarted/ts/main.ts.md",
"examplePath": "test_source/gettingstarted/ts/main.ts",
"exists": true
},
{
"fragPath": "test_fragments/gettingstarted/js/main2.js.md",
"examplePath": "test_source/gettingstarted/js/main2.js",
"exists": false
},
{
"fragPath": "test_fragments/gettingstarted/ts/main-import.ts.md",
"examplePath": "test_source/gettingstarted/ts/main.ts",
"exists": true
}
]
}
}

View File

@ -1,10 +1,10 @@
<h1> Frament path to jade path cross reference report
<p>Base path: c:\GitHub\angular.io.ideablade\public\docs</p>
<p>Base path: C:\GitHub\angular.io.ideablade\public\docs</p>
<ol>
<li>
Fragment file: <strong>_fragments/gettingstarted/ts/index.html.md</strong>
Fragment file: <strong>gettingstarted/ts/index.html</strong>
<p>Jade files</p>
<ul>
<li>js/latest/guide/setupAlt.jade</li>
@ -12,7 +12,7 @@
<br>
</li>
<li>
Fragment file: <strong>_fragments/gettingstarted/js/index.html.md</strong>
Fragment file: <strong>gettingstarted/js/index.html</strong>
<p>Jade files</p>
<ul>
<li>js/latest/guide/setupAlt.jade</li>
@ -20,7 +20,7 @@
<br>
</li>
<li>
Fragment file: <strong>_fragments/gettingstarted/ts/main.ts.md</strong>
Fragment file: <strong>gettingstarted/ts/main.ts</strong>
<p>Jade files</p>
<ul>
<li>js/latest/guide/setupAlt.jade</li>
@ -28,7 +28,7 @@
<br>
</li>
<li>
Fragment file: <strong>_fragments/gettingstarted/js/main.js.md</strong>
Fragment file: <strong>gettingstarted/js/main.js</strong>
<p>Jade files</p>
<ul>
<li>js/latest/guide/setupAlt.jade</li>
@ -36,7 +36,7 @@
<br>
</li>
<li>
Fragment file: <strong>_fragments/gettingstarted/ts/main-import.ts.md</strong>
Fragment file: <strong>gettingstarted/ts/main-import.ts</strong>
<p>Jade files</p>
<ul>
<li>js/latest/guide/setupAlt.jade</li>

View File

@ -1,6 +1,6 @@
<h1> Jade path to fragment path cross reference report
<p>Base path: c:\GitHub\angular.io.ideablade\public\docs</p>
<p>Base path: C:\GitHub\angular.io.ideablade\public\docs</p>
<ol>
<li>

View File

@ -1,25 +1,30 @@
{
"basePath": "c:\\GitHub\\angular.io.ideablade\\public\\docs",
"basePath": "C:\\GitHub\\angular.io.ideablade\\public\\docs",
"jadeToFragMap": {
"js/latest/guide/setupAlt.jade": [
{
"fragPath": "_fragments/gettingstarted/ts/index.html.md",
"examplePath": "_examples/gettingstarted/ts/index.html",
"exists": true
},
{
"fragPath": "_fragments/gettingstarted/js/index.html.md",
"examplePath": "_examples/gettingstarted/js/index.html",
"exists": true
},
{
"fragPath": "_fragments/gettingstarted/ts/main.ts.md",
"examplePath": "_examples/gettingstarted/ts/main.ts",
"exists": true
},
{
"fragPath": "_fragments/gettingstarted/js/main.js.md",
"examplePath": "_examples/gettingstarted/js/main.js",
"exists": true
},
{
"fragPath": "_fragments/gettingstarted/ts/main-import.ts.md",
"examplePath": "_examples/gettingstarted/ts/main.ts",
"exists": true
}
]