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

Commit 5b1a84b

Browse files
chalinkwalrath
authored andcommitted
chore(docs): revise makeExcerpt mixin, add makeProjExample mixin
Be more DRY when referencing examples and excerpts. E.g., ```jade +makeExcerpt('quickstart/ts/app/app.component.ts', 'import', 'app/app.component.ts (import)') ``` can now be just ```jade +makeExcerpt('app/app.component.ts', 'import') ``` Defined new mixin for examples named `makeProjExample` using this new scheme. The original `makeExample` has been left untouched. Applied new mixins to quickstart. closes #1420
1 parent d152ea2 commit 5b1a84b

File tree

3 files changed

+48
-18
lines changed

3 files changed

+48
-18
lines changed

public/_includes/_util-fns.jade

+37-7
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,43 @@ mixin makeExample(_filePath, region, _title, stylePatterns)
6868
.example-title #{title}
6969
code-example(language="#{language}" format="#{format}")
7070
!= styleString(frag, stylePatterns)
71-
72-
//- Like makeExample, but doesn't show line numbers and
73-
//- title is appened with `(excerpt)` if it doesn't already
74-
//- end with a parenthetical remark.
75-
mixin makeExcerpt(_filePath, region, _title, stylePatterns)
76-
- if (_title && !_title.match(/\([\w ]+\)$/)) _title = _title + ' (excerpt)';
77-
+makeExample(_filePath, region, _title, stylePatterns)(format='.')
71+
72+
//- Like makeExample, but the first argument is a path that is
73+
//- relative to the project root. Unless title is defined,
74+
//- the project relative path will be used.
75+
mixin makeProjExample(projRootRelativePath, region, title, stylePatterns)
76+
- var relPath = projRootRelativePath.trim();
77+
- var filePath = getExampleName() + '/ts/' + relPath;
78+
- if (!title) {
79+
- // Is path like styles.1.css? Then drop the '.1' qualifier:
80+
- var matches = relPath.match(/^(.*)\.\d(\.\w+)$/);
81+
- title = matches ? matches[1] + matches[2] : relPath;
82+
- }
83+
+makeExample(filePath, region, title, stylePatterns)
84+
85+
//- Like makeExample, but doesn't show line numbers, and the first
86+
//- argument is a path that is relative to the example project root.
87+
//- Unless title is defined, the project relative path will be used.
88+
//- Title will always end with a phrase in parentheses; if no such
89+
//- ending is given, then the title will be suffixed with
90+
//- either "(excerpt)", or "(#{region})" when region is defined.
91+
mixin makeExcerpt(projRootRelativePath, region, title, stylePatterns)
92+
- var relPath = projRootRelativePath.trim();
93+
- var filePath = getExampleName() + '/ts/' + relPath;
94+
- if (!title) {
95+
- // Is path like styles.1.css? Then drop the '.1' qualifier:
96+
- var matches = relPath.match(/^(.*)\.\d(\.\w+)$/);
97+
- title = matches ? matches[1] + matches[2] : relPath;
98+
- }
99+
- var excerpt = region || 'excerpt';
100+
- if (title && !title.match(/\([\w ]+\)$/)) title = title + ' (' + excerpt + ')';
101+
+makeExample(filePath, region, title, stylePatterns)(format='.')
102+
103+
//- Extract the doc example name from `current`.
104+
- var getExampleName = function() {
105+
- var dir = current.path[current.path.length - 1];
106+
- return dir == 'latest' ? current.source : dir;
107+
- };
78108

79109
mixin makeTabs(filePaths, regions, tabNames, stylePatterns)
80110
- filePaths = strSplit(filePaths);
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// #docregion
22
import { bootstrap } from '@angular/platform-browser-dynamic';
33

4-
// #docregion app-component
4+
// #docregion import
55
import { AppComponent } from './app.component';
6-
// #enddocregion app-component
6+
// #enddocregion import
77

88
bootstrap(AppComponent);

public/docs/ts/latest/quickstart.jade

+9-9
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ p.
208208
#[b Create the component file]
209209
#[code #[+adjExPath('app/app.component.ts')]] (in this newly created directory) with the following content:
210210

211-
+makeExample('quickstart/ts/app/app.component.ts', '', 'app/app.component.ts')(format='.')
211+
+makeProjExample('app/app.component.ts')
212212

213213
.l-verbose-section
214214
:marked
@@ -241,7 +241,7 @@ p.
241241
Here we import the Angular 2 core so that our component code can have access to
242242
the `@Component` #{_decorator}.
243243

244-
+makeExcerpt('quickstart/ts/app/app.component.ts', 'import', 'app/app.component.ts (import)')
244+
+makeExcerpt('app/app.component.ts', 'import')
245245

246246
h3#component-decorator @Component #{_decorator}
247247
+ifDocsFor('ts')
@@ -254,7 +254,7 @@ p.
254254
component class.
255255
The metadata tells Angular how to create and use this component.
256256

257-
+makeExcerpt('quickstart/ts/app/app.component.ts', 'metadata', 'app/app.component.ts (metadata)')(format='.')
257+
+makeExcerpt('app/app.component.ts', 'metadata')
258258

259259
block annotation-fields
260260
:marked
@@ -279,7 +279,7 @@ p.
279279
:marked
280280
### Component class
281281
At the bottom of the file is an empty, do-nothing class named `AppComponent`.
282-
+makeExcerpt('quickstart/ts/app/app.component.ts', 'class', 'app/app.component.ts (class)')
282+
+makeExcerpt('app/app.component.ts', 'class')
283283
:marked
284284
When we're ready to build a substantive application,
285285
we can expand this class with properties and application logic.
@@ -297,7 +297,7 @@ block create-main
297297
Now we need something to tell Angular to load the root component.
298298
Create the file #[code #[+adjExPath('app/main.ts')]] with the following content:
299299

300-
+makeExample('quickstart/ts/app/main.ts', '', 'app/main.ts')(format='.')
300+
+makeProjExample('app/main.ts')
301301

302302
.l-verbose-section
303303
:marked
@@ -342,7 +342,7 @@ h2#index Step 4: Add #[code index.html]
342342
In the *#{_indexHtmlDir}* folder
343343
create an `index.html` file and paste the following lines into it:
344344

345-
+makeExample('quickstart/ts/index.html', '', 'index.html')(format='.')
345+
+makeProjExample('index.html')
346346

347347
.l-verbose-section
348348
:marked
@@ -360,7 +360,7 @@ h2#index Step 4: Add #[code index.html]
360360
:marked
361361
### Libraries
362362
We loaded the following scripts
363-
+makeExcerpt('quickstart/ts/index.html', 'libraries', 'index.html')
363+
+makeExcerpt('index.html', 'libraries')
364364
:marked
365365
We begin with es6-shim which monkey patches the global context (window) with essential features of ES2015 (ES6).
366366
Next are the polyfills for Angular2, `zone.js` and `reflect-metadata`.
@@ -407,7 +407,7 @@ h2#index Step 4: Add #[code index.html]
407407

408408
Our QuickStart makes such requests when one of its
409409
application TypeScript files has an import statement like this:
410-
+makeExcerpt('quickstart/ts/app/main.ts', 'app-component', 'main.ts (excerpt)')
410+
+makeExcerpt('app/main.ts', 'import')
411411
:marked
412412
Notice that the module name (after `from`) does not mention a filename extension.
413413
In the configuration we tell SystemJS to default the extension to `js`, a JavaScript file.
@@ -463,7 +463,7 @@ h2#index Step 4: Add #[code index.html]
463463
Create a `styles.css` file in the *#{_indexHtmlDir}* folder and start styling, perhaps with the minimal
464464
styles shown below. For the full set of master styles used by the documentation samples,
465465
see [styles.css](https://github.com/angular/angular.io/blob/master/public/docs/_examples/styles.css).
466-
+makeExcerpt('quickstart/ts/styles.1.css', '', 'styles.css')
466+
+makeExcerpt('styles.1.css')
467467

468468
.l-main-section
469469
h2#build-and-run Step 5: Build and run the app!

0 commit comments

Comments
 (0)