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

Commit ce6c645

Browse files
chalinthso
authored andcommitted
docs(dev guide): structural-directives - ts minor edits, dart first versiondocs(dev guide): structural-directives - ts minor edits, dart first version (#1277)
Copyedits and other minor edits for TS + first version of the chapter for Dart
1 parent 8a29e50 commit ce6c645

File tree

4 files changed

+47
-36
lines changed

4 files changed

+47
-36
lines changed

public/_includes/_util-fns.jade

+2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ mixin makeExample(_filePath, region, _title, stylePatterns)
2323

2424
mixin makeTabs(filePaths, regions, tabNames, stylePatterns)
2525
- filePaths = strSplit(filePaths);
26+
- if (adjustExamplePath) filePaths = filePaths.map(adjustExamplePath);
2627
- regions = strSplit(regions, filePaths.length);
2728
- tabNames = strSplit(tabNames, filePaths.length);
29+
- if (adjustExampleTitle) tabNames = tabNames.map(adjustExampleTitle);
2830

2931
code-tabs
3032
each filePath,index in filePaths

public/docs/dart/latest/_util-fns.jade

+15-9
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ mixin liveExLinks(name)
55
[Run the live example](https://angular-examples.github.io/#{name}) |
66
[View its source code](https://github.com/angular-examples/#{name})
77

8-
- var adjustExamplePath = function(path) {
8+
- var adjustExamplePath = function(_path) {
9+
- if(!_path) return _path;
10+
- var path = _path.trim();
911
- var folder = getFolder(path);
1012
- var extn = getExtn(path);
1113
- // if(extn == 'dart') return path;
12-
- var baseName = getBaseFileName(path);
14+
- var baseName = getBaseFileName(path) || path; // TODO: have getBaseFileName() return path
1315
- var baseNameNoExt = baseName.substr(0,baseName.length - (extn.length + 1));
1416
- var inWebFolder = baseNameNoExt.match(/^(main|index)$/);
1517
- // Adjust the folder path, e.g., ts -> dart
@@ -18,15 +20,19 @@ mixin liveExLinks(name)
1820
- baseNameNoExt = baseNameNoExt.replace(/[\-\.]/g, '_');
1921
- // Adjust the file extension
2022
- if(extn == 'ts') extn = 'dart';
21-
- return folder + '/' + baseNameNoExt + '.' + extn;
23+
- return (folder ? folder + '/' : '') + baseNameNoExt + (extn ? '.' + extn : '');
2224
- };
2325

24-
- var adjustExampleTitle = function(title) {
25-
- // Assume title is a path if it ends with an extension like '.foo'.
26-
- if(title && title.match(/\.\w+$/) && adjustExamplePath) {
27-
- var isAbsolutePath = title.match(/^\//);
28-
- title = adjustExamplePath(title);
29-
- if(!isAbsolutePath && title.match(/^\//)) title = title.substring(1);
26+
- var adjustExampleTitle = function(_title) {
27+
- if(!_title || !adjustExamplePath) return _title;
28+
- var title = _title.trim();
29+
- // Assume title is a path if it ends with an extension like '.foo',
30+
- // optionally followed by '(excerpt)' with or without parentheses.
31+
- var matches = title.match(/(.*\.\w+)($|\s*\(?excerpt\)?$)/);
32+
- if(matches && matches.length == 3) {
33+
- // e.g. matches == ['abc.ts (excerpt)', 'abc.ts', ' (excerpt)']
34+
- var path = adjustExamplePath(matches[1]);
35+
- title = path + matches[2];
3036
- }
3137
- return title;
3238
- }
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
include ../_util-fns
1+
extends ../../../ts/latest/guide/structural-directives.jade
22

3-
:marked
4-
We're working on the Dart version of this chapter.
5-
In the meantime, please see these resources:
3+
block includes
4+
include ../_util-fns
65

7-
* [Structural Directives](/docs/ts/latest/guide/structural-directives.html):
8-
The TypeScript version of this chapter
6+
block liveExample
7+
+liveExLinks('structural-directives')
98

10-
* [Dart source code](https://github.com/angular/angular.io/tree/master/public/docs/_examples/structural-directives/dart):
11-
A preliminary version of the example code that will appear in this chapter
12-
9+
block unless-intro
10+
:marked
11+
Creating a directive is similar to creating a component.
12+
Here is how we begin:

public/docs/ts/latest/guide/structural-directives.jade

+21-18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
include ../_util-fns
1+
block includes
2+
include ../_util-fns
23

34
:marked
45
One of the defining features of a single page application is its manipulation
@@ -9,12 +10,14 @@ include ../_util-fns
910

1011
In this chapter we will
1112
- [learn what structural directives are](#definition)
12-
- [study *ngIf*](#ng-if)
13+
- [study *ngIf*](#ngIf)
1314
- [discover the <template> element](#template)
1415
- [understand the asterisk (\*) in **ngFor*](#asterisk)
1516
- [write our own structural directive](#unless)
1617

17-
[Live example](/resources/live-examples/structural-directives/ts/plnkr.html)
18+
block liveExample
19+
:marked
20+
[Live example](/resources/live-examples/structural-directives/ts/plnkr.html)
1821

1922
<a id="definition"></a>
2023
.l-main-section
@@ -42,7 +45,7 @@ include ../_util-fns
4245
+makeExample('structural-directives/ts/app/structural-directives.component.html', 'structural-directives')(format=".")
4346

4447

45-
<a id="ng-if"></a>
48+
<a id="ngIf"></a>
4649
.l-main-section
4750
:marked
4851
## NgIf Case Study
@@ -163,7 +166,7 @@ figure.image-display
163166
We can confirm these effects by wrapping the middle "hip" of the phrase "Hip! Hip! Hooray!" within a `<template>` tag.
164167
+makeExample('structural-directives/ts/app/structural-directives.component.html', 'template-tag')(format=".")
165168
:marked
166-
The display is a 'Hip!' short of perfect enthusiasm. The DOM effects are different when Angular is control.
169+
The display is a 'Hip! Hooray!', short of perfect enthusiasm. The DOM effects are different when Angular is in control.
167170
figure.image-display
168171
img(src='/resources/images/devguide/structural-directives/template-in-out-of-a2.png' alt="template outside angular")
169172

@@ -225,18 +228,19 @@ figure.image-display
225228
Unlike `ngIf` which displays the template content when `true`,
226229
our directive displays the content when the condition is ***false***.
227230

228-
:marked
229-
Creating a directive is similar to creating a component.
230-
* import the `Directive` decorator.
231+
block unless-intro
232+
:marked
233+
Creating a directive is similar to creating a component.
234+
* import the `Directive` decorator.
231235

232-
* add a CSS **attribute selector** (in brackets) that identifies our directive.
236+
* add a CSS **attribute selector** (in brackets) that identifies our directive.
233237

234-
* specify the name of the public `input` property for binding
235-
(typically the name of the directive itself).
238+
* specify the name of the public `input` property for binding
239+
(typically the name of the directive itself).
236240

237-
* apply the decorator to our implementation class.
241+
* apply the decorator to our implementation class.
238242

239-
Here is how we begin:
243+
Here is how we begin:
240244

241245
+makeExample('structural-directives/ts/app/unless.directive.ts', 'unless-declaration', 'unless.directive.ts (excerpt)')(format=".")
242246
.l-sub-section
@@ -264,11 +268,10 @@ figure.image-display
264268
+makeExample('structural-directives/ts/app/unless.directive.ts', 'unless-constructor')(format=".")
265269

266270
:marked
267-
The consumer of our directive will bind a `true` | `false` value to our directive's `myUnless` input property.
271+
The consumer of our directive will bind a boolean value to our directive's `myUnless` input property.
268272
The directive adds or removes the template based on that value.
269273

270-
Let's add the `myUnless` property now as a setter-only
271-
[definedProperty](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty).
274+
Let's add the `myUnless` property now as a setter-only property.
272275

273276
+makeExample('structural-directives/ts/app/unless.directive.ts', 'unless-set')(format=".")
274277
.l-sub-section
@@ -278,7 +281,7 @@ figure.image-display
278281
Nothing fancy here: if the condition is false,
279282
we render the template, otherwise we clear the element content.
280283

281-
The end result should look like below:
284+
The end result should look like this:
282285

283286
+makeExample('structural-directives/ts/app/unless.directive.ts', null, 'unless.directive.ts')
284287

@@ -297,7 +300,7 @@ figure.image-display
297300
Our `myUnless` directive is dead simple. Surely we left something out.
298301
Surely `ngIf` is more complex?
299302

300-
[Look at the source code](https://github.com/angular/angular/blob/master/modules/angular2/src/common/directives/ng_if.ts).
303+
[Look at the source code](https://github.com/angular/angular/blob/master/modules/%40angular/common/src/directives/ng_if.ts).
301304
It's well documented and we shouldn't be shy
302305
about consulting the source when we want to know how something works.
303306

0 commit comments

Comments
 (0)