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

Commit fb9edf9

Browse files
chalinwardbell
authored andcommitted
chore: fix "Invalid example" warnings from shred map builder
closes #1832 The shred map (xref) builder was issuing warnings. This fix includes - Adjustments to the shredder map builder itself so that it understands, e.g., app-project relative example paths. - `**/guide/glossary.jade` now (Jade) `includes` the shared parent `glossary.jade` rather than (Harp) importing (via `partial`). This fixes `makeExample` path issues in the glossary. - Adjusted some `makeExample` paths that were ok for site build, but confused the xref tool.
1 parent 0664a27 commit fb9edf9

File tree

6 files changed

+51
-31
lines changed

6 files changed

+51
-31
lines changed

public/docs/dart/latest/guide/dependency-injection.jade

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ block dart-map-alternative
101101
As an alternative to using a configuration `Map`, we can define
102102
a custom configuration class:
103103

104-
+makeExample('dependency-injection/ts/app/app.config.ts','config-alt','app/app-config.ts (alternative config)')(format='.')
104+
+makeExample('lib/app_config.dart (alternative config)','config-alt')
105105

106106
:marked
107107
Defining a configuration class has a few benefits. One key benefit
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
!= partial("../glossary")
1+
include ../glossary

public/docs/dart/latest/tutorial/toh-pt5.jade

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,6 @@ code-example(language="bash").
132132

133133
### Add a base tag
134134

135-
// Our Tour of Heroes needs routing,
136-
// so we load the library in the `index.html` in a script tag immediately *after* the angular script itself.
137-
//+makeExample('toh-5/dart/web/index.html', 'router', 'index.html (router)')(format=".")
138135
:marked
139136
First, edit `index.html` and add `<base href="/">` at the top of the `<head>` section.
140137
+makeExample('toh-5/dart/web/index.html', 'base-href', 'index.html (base href)')(format=".")

public/docs/ts/latest/glossary.jade

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ include _util-fns
5454
The barrel itself is a module file that re-exports *selected* exports of other modules.
5555

5656
Imagine three modules in a `heroes` folder:
57-
code-example(format='').
57+
code-example.
5858
// heroes/hero.component.ts
5959
export class HeroComponent {}
6060

@@ -65,26 +65,26 @@ include _util-fns
6565
export class HeroService {}
6666
:marked
6767
Without a barrel, a consumer would need three import statements:
68-
code-example(format='').
68+
code-example.
6969
import { HeroComponent } from '../heroes/hero.component.ts';
7070
import { Hero } from '../heroes/hero.model.ts';
7171
import { HeroService } from '../heroes/hero.service.ts';
7272
:marked
7373
We can add a barrel to the `heroes` folder (called `index` by convention) that exports all of these items:
74-
code-example(format='').
74+
code-example.
7575
export * from './hero.model.ts'; // re-export all of its exports
7676
export * from './hero.service.ts'; // re-export all of its exports
7777
export { HeroComponent } from './hero.component.ts'; // re-export the named thing
7878
:marked
7979
Now a consumer can import what it needs from the barrel.
80-
code-example(format='').
80+
code-example.
8181
import { Hero, HeroService } from '../heroes'; // index is implied
8282
:marked
8383
The Angular [scoped packages](#scoped-package) each have a barrel named `index`.
8484
// #enddocregion b-c
8585
:marked
8686
That's why we can write this:
87-
+makeExample('../docs/_fragments/quickstart/ts/app/app.component.ts', 'import')(format=".")
87+
+makeExcerpt('quickstart/ts/app/app.component.ts', 'import', '')
8888
// #docregion b-c
8989
9090
:marked
@@ -584,7 +584,7 @@ include _util-fns
584584
The only difference, from a consumer perspective,
585585
is that the package name begins with the Angular *scope name*, `@angular`.
586586

587-
+makeExample('../docs/_fragments/architecture/ts/app/app.component.ts', 'import')(format=".")
587+
+makeExcerpt('architecture/ts/app/app.component.ts', 'import', '')
588588
// #docregion n-s-2
589589
590590
:marked
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
!= partial("../glossary")
1+
include ../glossary

tools/doc-shredder/processors/shredMapProcessor.js

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,37 @@ module.exports = function shredMapProcessor(log, createDocMessage) {
1818
var fragToJadeMap = {};
1919

2020
docs.forEach(function(doc) {
21-
var jadePath = path.join(options.jadeDir, doc.fileInfo.relativePath);
21+
var relativePath = doc.fileInfo.relativePath;
22+
var jadePath = path.join(options.jadeDir, relativePath);
23+
var lang = relativePath.substr(0, relativePath.indexOf('\/'));
24+
var appProjDirName = jadeBaseFileNameToExampleName(doc.fileInfo.baseName);
2225
var fragInfoSet = {};
2326
doc.fragItems.forEach(function(fragItem) {
2427
var mixinPath = fragItem.mixinPath;
2528
var fullExamplePath;
29+
// Normalize mixinPath: strip out optional trailing '(...)'
30+
var mixinPath = mixinPath.replace(/ \([^\)]*\)/,'');
2631
if ( mixinPath.indexOf('_api') >= 0) {
2732
var sourcePath = mixinPath.replace('_api/','');
2833
fullExamplePath = path.join(options.apiExamplesDir, sourcePath);
2934
} else {
3035
fullExamplePath = path.join(options.devguideExamplesDir, mixinPath);
3136
}
32-
var region = fragItem.region ? "-" + fragItem.region : '';
33-
var extn = path.extname(mixinPath);
34-
var basename = path.basename(mixinPath, extn);
35-
var fragDir = path.dirname(mixinPath);
36-
var fragPath = path.join(fragDir, basename + region + extn) + '.md';
37-
var fullFragPath = path.join(options.fragmentsDir, fragPath);
38-
39-
var fragInfo = { fragPath: fullFragPath, examplePath: fullExamplePath, exists: fs.existsSync(fullFragPath) };
37+
var fragInfo = makeFragInfo(options.fragmentsDir, fullExamplePath, fragItem, mixinPath);
38+
if (!fragInfo.exists) {
39+
var savedFragInfo = fragInfo;
40+
// Assume that mixinPath is actually app-project-folder relative and
41+
// prepend "lang/appProjDirName":
42+
var appProjRelPath = mixinPath;
43+
mixinPath = appProjDirName + '/' + lang + '/' + mixinPath;
44+
fragInfo = makeFragInfo(options.fragmentsDir, fullExamplePath, fragItem, mixinPath);
45+
if (fragInfo.exists) {
46+
log.info('Ajusted example path (' + doc.fileInfo.baseName + '): ' + appProjRelPath + ' -> ' + mixinPath);
47+
} else {
48+
fragInfo = savedFragInfo;
49+
}
50+
}
51+
var fragPath = fragInfo.relFragPath;
4052
fragInfoSet[fragPath] = fragInfo;
4153
if (fragInfo.exists) {
4254
var jadePathsSet = fragToJadeMap[fragPath];
@@ -46,7 +58,7 @@ module.exports = function shredMapProcessor(log, createDocMessage) {
4658
}
4759
jadePathsSet[jadePath] = jadePath;
4860
} else {
49-
var relativePath = path.relative(".", fullFragPath);
61+
var relativePath = path.relative(".", fragInfo.fragPath);
5062
log.warn(createDocMessage('Invalid example (unable to locate fragment file: "' + relativePath + '")', doc));
5163
}
5264
});
@@ -82,13 +94,24 @@ module.exports = function shredMapProcessor(log, createDocMessage) {
8294
}
8395
};
8496

85-
function getExampleName(fragPath) {
86-
// pattern to isolate base fileName and extension from fragment name
87-
var rx = /(.*)\-(.*)\.(.s)/;
88-
var r = rx.exec(fragPath);
89-
if (r) {
90-
return r[1] + '.' + r[3];
91-
} else {
92-
return fragPath;
93-
}
97+
// TODO: use the functionality in public/resources/js/util.js once it lands.
98+
function jadeBaseFileNameToExampleName(name) {
99+
// Adjust for known cases where chapter name is not the example name.
100+
var matches = name.match(/(toh-)pt(\d+)/);
101+
if (matches) name = matches[1] + matches[2];
102+
return name;
103+
}
104+
105+
function makeFragInfo(fragmentsDir, fullExamplePath, fragItem, mixinPath) {
106+
var region = fragItem.region ? "-" + fragItem.region : '';
107+
var extn = path.extname(mixinPath);
108+
var basename = path.basename(mixinPath, extn);
109+
var fragDir = path.dirname(mixinPath);
110+
var fragPath = path.join(fragDir, basename + region + extn) + '.md';
111+
var fullFragPath = path.join(fragmentsDir, fragPath);
112+
return {
113+
fragPath: fullFragPath,
114+
relFragPath: fragPath,
115+
examplePath: fullExamplePath,
116+
exists: fs.existsSync(fullFragPath) };
94117
}

0 commit comments

Comments
 (0)