@@ -53,10 +53,10 @@ mixin ifDocsFor(langPattern)
53
53
block
54
54
55
55
//- Use to map inlined (prose) TS paths into, say, Dart paths via the
56
- //- adjustExamplePath transformer function.
56
+ //- adjustTsExamplePathForDart transformer function.
57
57
mixin adjExPath(path )
58
- if adjustExamplePath
59
- | #{adjustExamplePath (path)}
58
+ if adjustTsExamplePathForDart
59
+ | #{adjustTsExamplePathForDart (path)}
60
60
else
61
61
| #{path}
62
62
@@ -65,8 +65,9 @@ mixin includeShared(filePath, region)
65
65
!= partial (newPath)
66
66
67
67
mixin makeExample(_filePath, region, _title, stylePatterns )
68
- - var filePath = adjustExamplePath ? adjustExamplePath (_filePath) : _filePath;
69
- - var title = adjustExampleTitle ? adjustExampleTitle (_title) : _title;
68
+ - var adjustments = adjustExamplePathAndTitle ({filePath: _filePath, title: _title});
69
+ - var filePath = adjustments .filePath ;
70
+ - var title = adjustments .title ;
70
71
- var language = attributes .language || getExtn (filePath);
71
72
- var frag = getFrag (filePath, region);
72
73
- var defaultFormat = frag .split (' \n ' ).length > 2 ? " linenums" : " " ;
@@ -82,35 +83,21 @@ mixin makeExample(_filePath, region, _title, stylePatterns)
82
83
code-example( language ="#{language} " format ="#{format} " )
83
84
!= styleString (frag, stylePatterns)
84
85
85
- //- Like makeExample, but the first argument is a path that is
86
- //- relative to the project root. Unless title is defined,
87
- //- the project relative path will be used.
88
- mixin makeProjExample(projRootRelativePath, region, title, stylePatterns )
89
- - var relPath = projRootRelativePath .trim ();
90
- - var filePath = getExampleName () + ' /ts/' + relPath;
91
- - if (! title) {
92
- - // Is path like styles.1.css? Then drop the '.1' qualifier:
93
- - var matches = relPath .match (/ ^ (. * )\. \d (\. \w + )$ / );
94
- - title = matches ? matches[1 ] + matches[2 ] : relPath;
95
- - }
96
- + makeExample(filePath, region, title, stylePatterns)
97
-
98
- //- Like makeExample, but doesn't show line numbers, and the first
99
- //- argument is a path that is relative to the example project root.
100
- //- Unless title is defined, the project relative path will be used.
101
- //- Title will always end with a phrase in parentheses; if no such
102
- //- ending is given, then the title will be suffixed with
103
- //- either "(excerpt)", or "(#{region})" when region is defined.
104
- mixin makeExcerpt(projRootRelativePath, region, title, stylePatterns )
105
- - var relPath = projRootRelativePath .trim ();
106
- - var filePath = getExampleName () + ' /ts/' + relPath;
107
- - if (! title) {
108
- - // Is path like styles.1.css? Then drop the '.1' qualifier:
109
- - var matches = relPath .match (/ ^ (. * )\. \d (\. \w + )$ / );
110
- - title = matches ? matches[1 ] + matches[2 ] : relPath;
111
- - }
112
- - var excerpt = region || ' excerpt' ;
113
- - if (title && ! title .match (/ \( [\w ] + \) $ / )) title = title + ' (' + excerpt + ' )' ;
86
+ //- Like makeExample, but: (1) doesn't show line numbers. (2) If region
87
+ //- is omitted and title is 'foo (r)' then region is taken as 'r'.
88
+ //- (3) Title will always end with a phrase in parentheses; if no such
89
+ //- ending is given or is just (), then the title will be suffixed with
90
+ //- either "(excerpt)", or "(#{_region})" when _region is defined.
91
+ mixin makeExcerpt(_filePath, _region, _title, stylePatterns )
92
+ - var matches = _filePath .match (/ (. * )\s + \( ([\w ] * )\) $ / );
93
+ - var parenText;
94
+ - if (matches) { _filePath = matches[1 ]; parenText = matches[2 ]; }
95
+ - var adjustments = adjustExamplePathAndTitle ({filePath: _filePath, title: _title});
96
+ - var filePath = adjustments .filePath ;
97
+ - var title = adjustments .title ;
98
+ - var region = _region || parenText;
99
+ - var excerpt = ! region || parenText === ' ' ? ' excerpt' : region;
100
+ - if (title) title = title + ' (' + excerpt + ' )' ;
114
101
+ makeExample(filePath, region, title, stylePatterns)( format ='.' )
115
102
116
103
//- Extract the doc example name from `current`.
@@ -121,10 +108,10 @@ mixin makeExcerpt(projRootRelativePath, region, title, stylePatterns)
121
108
122
109
mixin makeTabs(filePaths, regions, tabNames, stylePatterns )
123
110
- filePaths = strSplit (filePaths);
124
- - if (adjustExamplePath ) filePaths = filePaths .map (adjustExamplePath );
111
+ - if (adjustTsExamplePathForDart ) filePaths = filePaths .map (adjustTsExamplePathForDart );
125
112
- regions = strSplit (regions, filePaths .length );
126
113
- tabNames = strSplit (tabNames, filePaths .length );
127
- - if (adjustExampleTitle ) tabNames = tabNames .map (adjustExampleTitle );
114
+ - if (adjustTsExampleTitleForDart ) tabNames = tabNames .map (adjustTsExampleTitleForDart );
128
115
129
116
code-tabs
130
117
each filePath,index in filePaths
@@ -216,6 +203,43 @@ script.
216
203
return CCSstyle[style] = value
217
204
}
218
205
//---------------------------------------------------------------------------------------------------------
206
+ //- Converts the given project-relative path (like 'app/main.ts')
207
+ //- to a doc folder relative path (like 'quickstart/ts/app/main.ts')
208
+ //- by prefixing it with '<example-name>/ts/'. If title is not given,
209
+ //- then the project-relative path is used, adjusted to remove numeric
210
+ //- file version qualifiers; e.g. 'styles.1.css' becomes 'styles.css'.
211
+ - var adjExampleProjPathAndTitle = function (ex /* :{filePath,title}*/ ) {
212
+ - // E.g. of a project relative path is 'app/main.ts'
213
+ - if (ex .title === null || ex .title === undefined ) {
214
+ - // Title is not given so take it to be ex.filePath.
215
+ - // Is title like styles.1.css? Then drop the '.1' qualifier:
216
+ - var matches = ex .filePath .match (/ ^ (. * )\. \d (\. \w + )$ / );
217
+ - ex .title = matches ? matches[1 ] + matches[2 ] : ex .filePath ;
218
+ - }
219
+ - ex .filePath = getExampleName () + ' /' + _docsFor + ' /' + ex .filePath ;
220
+ - return ex;
221
+ - };
222
+
223
+ //- If the given path is project relative, then first convert it using
224
+ //- adjExampleProjPathAndTitle(ex). Then the path is adjusted to match
225
+ //- the documentation language.
226
+ - var adjustExamplePathAndTitle = function (ex /* :{filePath,title}*/ ) {
227
+ - // Not a doc folder relative path? Assume that it is app project relative.
228
+ - if (isProjRelDir (ex .filePath )) adjExampleProjPathAndTitle (ex);
229
+ - // Adjust doc folder relative paths if adjustment functions exist.
230
+ - if (adjustTsExamplePathForDart) ex .filePath = adjustTsExamplePathForDart (ex .filePath );
231
+ - if (adjustTsExampleTitleForDart) ex .title = adjustTsExampleTitleForDart (ex .title );
232
+ - return ex;
233
+ - };
234
+
235
+ //- Returns truthy iff path is example project relative.
236
+ - var isProjRelDir = function (path ) {
237
+ - return ! path .match (/ \/ (js| ts| dart)(-snippets)? \/ / ) && ! path .endsWith (' e2e-spec.js' );
238
+ - // Last conjunct handles case for shared project e2e test file like
239
+ - // cb-component-communication/e2e-spec.js (is shared between ts & dart)
240
+ - // TODO: generalize: compare start with getExampleName(); which needs to be fixed.
241
+ - };
242
+
219
243
- var translatePath = function (filePath , region ) {
220
244
- filePath = filePath .trim ();
221
245
- var regionPad = (region && region .length ) ? ' -' + region .toString () : ' ' ;
0 commit comments