@@ -60,8 +60,9 @@ mixin includeShared(filePath, region)
6060 != partial (newPath)
6161
6262mixin makeExample(_filePath, region, _title, stylePatterns )
63- - var filePath = adjustTsExamplePath4Dart ? adjustTsExamplePath4Dart (_filePath) : _filePath;
64- - var title = adjustTsExampleTitle4Dart ? adjustTsExampleTitle4Dart (_title) : _title;
63+ - var adjustments = adjustExamplePathAndTitle ({filePath: _filePath, title: _title});
64+ - var filePath = adjustments .filePath ;
65+ - var title = adjustments .title ;
6566 - var language = attributes .language || getExtn (filePath);
6667 - var frag = getFrag (filePath, region);
6768 - var defaultFormat = frag .split (' \n ' ).length > 2 ? " linenums" : " " ;
@@ -77,35 +78,21 @@ mixin makeExample(_filePath, region, _title, stylePatterns)
7778 code-example( language ="#{language} " format ="#{format} " )
7879 != styleString (frag, stylePatterns)
7980
80- //- Like makeExample, but the first argument is a path that is
81- //- relative to the project root. Unless title is defined,
82- //- the project relative path will be used.
83- mixin makeProjExample(projRootRelativePath, region, title, stylePatterns )
84- - var relPath = projRootRelativePath .trim ();
85- - var filePath = getExampleName () + ' /ts/' + relPath;
86- - if (! title) {
87- - // Is path like styles.1.css? Then drop the '.1' qualifier:
88- - var matches = relPath .match (/ ^ (. * )\. \d (\. \w + )$ / );
89- - title = matches ? matches[1 ] + matches[2 ] : relPath;
90- - }
91- + makeExample(filePath, region, title, stylePatterns)
92-
93- //- Like makeExample, but doesn't show line numbers, and the first
94- //- argument is a path that is relative to the example project root.
95- //- Unless title is defined, the project relative path will be used.
96- //- Title will always end with a phrase in parentheses; if no such
97- //- ending is given, then the title will be suffixed with
98- //- either "(excerpt)", or "(#{region})" when region is defined.
99- mixin makeExcerpt(projRootRelativePath, region, title, stylePatterns )
100- - var relPath = projRootRelativePath .trim ();
101- - var filePath = getExampleName () + ' /ts/' + relPath;
102- - if (! title) {
103- - // Is path like styles.1.css? Then drop the '.1' qualifier:
104- - var matches = relPath .match (/ ^ (. * )\. \d (\. \w + )$ / );
105- - title = matches ? matches[1 ] + matches[2 ] : relPath;
106- - }
107- - var excerpt = region || ' excerpt' ;
108- - if (title && ! title .match (/ \( [\w ] + \) $ / )) title = title + ' (' + excerpt + ' )' ;
81+ //- Like makeExample, but: (1) doesn't show line numbers. (2) If region
82+ //- is omitted and title is 'foo (r)' then region is taken as 'r'.
83+ //- (3) Title will always end with a phrase in parentheses; if no such
84+ //- ending is given or is just (), then the title will be suffixed with
85+ //- either "(excerpt)", or "(#{_region})" when _region is defined.
86+ mixin makeExcerpt(_filePath, _region, _title, stylePatterns )
87+ - var matches = _filePath .match (/ (. * )\s + \( ([\w ] * )\) $ / );
88+ - var parenText;
89+ - if (matches) { _filePath = matches[1 ]; parenText = matches[2 ]; }
90+ - var adjustments = adjustExamplePathAndTitle ({filePath: _filePath, title: _title});
91+ - var filePath = adjustments .filePath ;
92+ - var title = adjustments .title ;
93+ - var region = _region || parenText;
94+ - var excerpt = ! region || parenText === ' ' ? ' excerpt' : region;
95+ - if (title) title = title + ' (' + excerpt + ' )' ;
10996 + makeExample(filePath, region, title, stylePatterns)( format ='.' )
11097
11198//- Extract the doc example name from `current`.
@@ -211,6 +198,43 @@ script.
211198 return CCSstyle[style] = value
212199 }
213200//---------------------------------------------------------------------------------------------------------
201+ //- Converts the given project-relative path (like 'app/main.ts')
202+ //- to a doc folder relative path (like 'quickstart/ts/app/main.ts')
203+ //- by prefixing it with '<example-name>/ts/'. If title is not given,
204+ //- then the project-relative path is used, adjusted to remove numeric
205+ //- file version qualifiers; e.g. 'styles.1.css' becomes 'styles.css'.
206+ - var adjExampleProjPathAndTitle = function (ex /* :{filePath,title}*/ ) {
207+ - // E.g. of a proj relative path is 'app/main.ts'
208+ - if (ex .title === null || ex .title === undefined ) {
209+ - // Title is not given so take it to be ex.filePath.
210+ - // Is title like styles.1.css? Then drop the '.1' qualifier:
211+ - var matches = ex .filePath .match (/ ^ (. * )\. \d (\. \w + )$ / );
212+ - ex .title = matches ? matches[1 ] + matches[2 ] : ex .filePath ;
213+ - }
214+ - ex .filePath = getExampleName () + ' /' + _docsFor + ' /' + ex .filePath ;
215+ - return ex;
216+ - };
217+
218+ //- If the given path is project relative, then first convert it using
219+ //- adjExampleProjPathAndTitle(ex). Then the path is adjusted to match
220+ //- the documentation language.
221+ - var adjustExamplePathAndTitle = function (ex /* :{filePath,title}*/ ) {
222+ - // Not a doc folder relative path? Assume that it is app project relative.
223+ - if (isProjRelDir (ex .filePath )) adjExampleProjPathAndTitle (ex);
224+ - // Adjust doc folder relative paths if adjustment functions exist.
225+ - if (adjustTsExamplePath4Dart) ex .filePath = adjustTsExamplePath4Dart (ex .filePath );
226+ - if (adjustTsExampleTitle4Dart) ex .title = adjustTsExampleTitle4Dart (ex .title );
227+ - return ex;
228+ - };
229+
230+ //- Returns truthy iff path is example project relative.
231+ - var isProjRelDir = function (path ) {
232+ - return ! path .match (/ \/ (js| ts| dart)(-snippets)? \/ / ) && ! path .endsWith (' e2e-spec.js' );
233+ - // Last conjunct handles case for shared project e2e test file like
234+ - // cb-component-communication/e2e-spec.js (is shared between ts & dart)
235+ - // TODO: generalize: compare start with getExampleName(); which needs to be fixed.
236+ - };
237+
214238- var translatePath = function (filePath , region ) {
215239- filePath = filePath .trim ();
216240- var regionPad = (region && region .length ) ? ' -' + region .toString () : ' ' ;
0 commit comments