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

Commit 0c0c6f6

Browse files
chalinkwalrath
authored andcommitted
docs(toh-5): TS/Dart review, and Dart resync (#2115)
* docs(toh-5): review and update/resync Dart **NOTE: run `gulp add-example-boilerplate` after pulling in the commit.** This is preparatory work for #2035. As part of the the chapter review, the Dart .jade was enhanced to use Jade extends (#2018). By the same token it contributed to a post-RC5 resync (#2077). Other key changes: Dart and TS code: - Eliminated `styles.1.css` in favor of docregions in `styles.css`. - `docregion` tags renamed in a few places. - **No other code changes**. TS prose - Fixed: misnamed variable `routing` -> `appRoutes`. - All other changes are **minor copy edits**, or changes to support Dart via Jade extends. Diff of generated HTML for TS chapter was inspected to ensure only minor copy edits prevailed (i.e., that the support for Jade extends had no impact on the generated HTML). * docs(toh-5): edits after doing tutorial - Some adjustments following actually doing the tutorial. In some cases code shown (e.g. this is what file foo should look like now) didn't match what the user would have. E.g., lingering @input on the hero property. - Fixed some lingering deprecated-router prose elements on TS side (e.g., still referring to a route by the old string names like `HeroDetail`). - Added extra step to `app.component.ts` creation rather than having a critical-call-out later on. - Reorder some prose for better harmony between TS and Dart prose (also improves the flow). - Moved the `styleUrls` call-out to the point of first use. * post-review changes * more post-review changes * toh-6 cache update
1 parent 9869bf5 commit 0c0c6f6

32 files changed

+1257
-1582
lines changed

public/_includes/_util-fns.jade

+2-2
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ script.
222222
- // E.g. of a project relative path is 'app/main.ts'
223223
- if (ex.title === null || ex.title === undefined) {
224224
- // Title is not given so take it to be ex.filePath.
225-
- // Is title like styles.1.css? Then drop the '.1' qualifier:
226-
- var matches = ex.filePath.match(/^(.*)\.\d(\.\w+)$/);
225+
- // Title like styles.1.css or foo_1.dart? Then drop the '.1' or '_1' qualifier:
226+
- var matches = ex.filePath.match(/^(.*)[\._]\d(\.\w+)$/);
227227
- ex.title = matches ? matches[1] + matches[2] : ex.filePath;
228228
- }
229229
- ex.filePath = getExampleName() + '/' + _docsFor + '/' + ex.filePath;

public/docs/_examples/styles.css

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* #docregion , quickstart */
1+
/* #docregion , quickstart, toh */
22
/* Master Styles */
33
h1 {
44
color: #369;
@@ -18,6 +18,7 @@ body, input[text], button {
1818
color: #888;
1919
font-family: Cambria, Georgia;
2020
}
21+
/* #enddocregion toh */
2122
a {
2223
cursor: pointer;
2324
cursor: hand;
@@ -137,7 +138,7 @@ nav a.active {
137138
margin-right: .8em;
138139
border-radius: 4px 0 0 4px;
139140
}
140-
141+
/* #docregion toh */
141142
/* everywhere else */
142143
* {
143144
font-family: Arial, Helvetica, sans-serif;
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,51 @@
11
// #docplaster
22
// #docregion
33
import 'package:angular2/core.dart';
4+
// #docregion import-router
45
import 'package:angular2/router.dart';
6+
// #enddocregion import-router
57

6-
import 'package:angular2_tour_of_heroes/heroes_component.dart';
7-
import 'package:angular2_tour_of_heroes/hero_service.dart';
8-
import 'package:angular2_tour_of_heroes/dashboard_component.dart';
9-
// #docregion hero-detail-import
10-
import 'package:angular2_tour_of_heroes/hero_detail_component.dart';
11-
// #enddocregion hero-detail-import
8+
import 'dashboard_component.dart';
9+
import 'hero_detail_component.dart';
10+
import 'hero_service.dart';
11+
import 'heroes_component.dart';
1212

1313
@Component(
1414
selector: 'my-app',
15-
// #docregion template
15+
// #docregion template, template-v3
1616
template: '''
1717
<h1>{{title}}</h1>
1818
<nav>
1919
<a [routerLink]="['Dashboard']">Dashboard</a>
2020
<a [routerLink]="['Heroes']">Heroes</a>
2121
</nav>
2222
<router-outlet></router-outlet>''',
23-
// #enddocregion template
24-
// #docregion style-urls
23+
// #enddocregion template, template-v3
24+
// #docregion styleUrls
2525
styleUrls: const ['app_component.css'],
26-
// #enddocregion style-urls
26+
// #enddocregion styleUrls
27+
// #docregion directives-and-providers
2728
directives: const [ROUTER_DIRECTIVES],
2829
providers: const [HeroService, ROUTER_PROVIDERS])
30+
// #enddocregion directives-and-providers
31+
// #docregion heroes
2932
@RouteConfig(const [
30-
// #docregion dashboard-route
33+
// #enddocregion heroes
34+
// #docregion dashboard
3135
const Route(
3236
path: '/dashboard',
3337
name: 'Dashboard',
3438
component: DashboardComponent,
3539
useAsDefault: true),
36-
// #enddocregion dashboard-route
37-
// #docregion hero-detail-route
40+
// #enddocregion dashboard
41+
// #docregion hero-detail
3842
const Route(
3943
path: '/detail/:id', name: 'HeroDetail', component: HeroDetailComponent),
40-
// #enddocregion hero-detail-route
44+
// #enddocregion hero-detail
45+
// #docregion heroes
4146
const Route(path: '/heroes', name: 'Heroes', component: HeroesComponent)
4247
])
48+
// #enddocregion heroes
4349
class AppComponent {
4450
String title = 'Tour of Heroes';
4551
}
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,40 @@
11
// #docplaster
2-
// #docregion
2+
// #docregion , v2
33
import 'package:angular2/core.dart';
4-
// #enddocregion
5-
import 'package:angular2/router.dart'; // for testing only
4+
// #enddocregion ,
5+
// #docregion v2
6+
import 'package:angular2/router.dart';
67
// #docregion
78

89
import 'hero_service.dart';
910
import 'heroes_component.dart';
1011

12+
// #enddocregion v2
1113
@Component(
1214
selector: 'my-app',
1315
template: '''
1416
<h1>{{title}}</h1>
1517
<my-heroes></my-heroes>''',
1618
directives: const [HeroesComponent],
17-
providers: const [
18-
// #enddocregion
19-
ROUTER_PROVIDERS,
20-
// #docregion
21-
HeroService
22-
])
19+
providers: const [HeroService])
20+
// #enddocregion ,
21+
class Bogus {}
22+
23+
// #docregion v2
24+
@Component(
25+
selector: 'my-app',
26+
// #docregion template-v2
27+
template: '''
28+
<h1>{{title}}</h1>
29+
<a [routerLink]="['Heroes']">Heroes</a>
30+
<router-outlet></router-outlet>''',
31+
// #enddocregion template-v2
32+
directives: const [ROUTER_DIRECTIVES],
33+
providers: const [HeroService, ROUTER_PROVIDERS])
34+
@RouteConfig(const [
35+
const Route(path: '/heroes', name: 'Heroes', component: HeroesComponent)
36+
])
37+
// #docregion ,
2338
class AppComponent {
2439
String title = 'Tour of Heroes';
2540
}

public/docs/_examples/toh-5/dart/lib/app_component_2.dart

-31
This file was deleted.

public/docs/_examples/toh-5/dart/lib/dashboard_component.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import 'hero_service.dart';
1212

1313
@Component(
1414
selector: 'my-dashboard',
15-
// #docregion template-url
15+
// #docregion templateUrl
1616
templateUrl: 'dashboard_component.html',
17-
// #enddocregion template-url
17+
// #enddocregion templateUrl
1818
// #docregion css
1919
styleUrls: const ['dashboard_component.css']
2020
// #enddocregion css
@@ -35,13 +35,13 @@ class DashboardComponent implements OnInit {
3535
heroes = (await _heroService.getHeroes()).skip(1).take(4).toList();
3636
}
3737

38-
// #docregion goto-detail
38+
// #docregion gotoDetail
3939
void gotoDetail(Hero hero) {
4040
var link = [
4141
'HeroDetail',
4242
{'id': hero.id.toString()}
4343
];
4444
_router.navigate(link);
4545
}
46-
// #enddocregion goto-detail
46+
// #enddocregion gotoDetail
4747
}

public/docs/_examples/toh-5/dart/lib/dashboard_component_2.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ class DashboardComponent implements OnInit {
2222
heroes = (await _heroService.getHeroes()).skip(1).take(4).toList();
2323
}
2424

25-
gotoDetail() {/* not implemented yet */}
25+
gotoDetail(Hero hero) {/* not implemented yet */}
2626
}
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
11
// #docplaster
22
// #docregion , v2
3+
// #docregion added-imports
34
import 'dart:async';
4-
import 'dart:html';
5+
import 'dart:html' show window;
56

6-
// #docregion import-oninit
7+
// #enddocregion added-imports
78
import 'package:angular2/core.dart';
8-
// #enddocregion import-oninit
9-
// #docregion import-route-params
9+
// #docregion added-imports
1010
import 'package:angular2/router.dart';
11-
// #enddocregion import-route-params
1211

12+
// #enddocregion added-imports
1313
import 'hero.dart';
14-
// #docregion import-hero-service
14+
// #docregion added-imports
1515
import 'hero_service.dart';
16-
// #enddocregion import-hero-service
16+
// #enddocregion added-imports
1717

18-
// #docregion extract-template
1918
@Component(
2019
selector: 'my-hero-detail',
21-
// #docregion template-url
20+
// #docregion templateUrl
2221
templateUrl: 'hero_detail_component.html',
23-
// #enddocregion template-url, v2
22+
// #enddocregion templateUrl, v2
2423
styleUrls: const ['hero_detail_component.css']
2524
// #docregion v2
2625
)
27-
// #enddocregion extract-template
2826
// #docregion implement
2927
class HeroDetailComponent implements OnInit {
3028
// #enddocregion implement
@@ -36,19 +34,17 @@ class HeroDetailComponent implements OnInit {
3634
HeroDetailComponent(this._heroService, this._routeParams);
3735
// #enddocregion ctor
3836

39-
// #docregion ng-oninit
37+
// #docregion ngOnInit
4038
Future<Null> ngOnInit() async {
41-
// #docregion get-id
4239
var idString = _routeParams.get('id');
43-
var id = int.parse(idString, onError: (_) => null);
44-
// #enddocregion get-id
40+
var id = int.parse(idString ?? '', onError: (_) => null);
4541
if (id != null) hero = await (_heroService.getHero(id));
4642
}
47-
// #enddocregion ng-oninit
43+
// #enddocregion ngOnInit
4844

49-
// #docregion go-back
45+
// #docregion goBack
5046
void goBack() {
5147
window.history.back();
5248
}
53-
// #enddocregion go-back
49+
// #enddocregion goBack
5450
}

public/docs/_examples/toh-5/dart/lib/hero_service.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class HeroService {
1616
const Duration(seconds: 2), () => mockHeroes);
1717
}
1818

19-
// #docregion get-hero
19+
// #docregion getHero
2020
Future<Hero> getHero(int id) async =>
2121
(await getHeroes()).firstWhere((hero) => hero.id == id);
22-
// #enddocregion get-hero
22+
// #enddocregion getHero
2323
}

public/docs/_examples/toh-5/dart/lib/heroes_component.dart

+11-10
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,28 @@ import 'package:angular2/core.dart';
66
import 'package:angular2/router.dart';
77

88
import 'hero.dart';
9-
import 'hero_detail_component.dart';
109
import 'hero_service.dart';
1110

12-
// #docregion metadata, heroes-component-renaming
11+
// #docregion metadata, renaming
1312
@Component(
1413
selector: 'my-heroes',
15-
// #enddocregion heroes-component-renaming
14+
// #enddocregion renaming
1615
templateUrl: 'heroes_component.html',
17-
styleUrls: const ['heroes_component.css'],
18-
directives: const [HeroDetailComponent])
19-
// #docregion heroes-component-renaming
20-
// #enddocregion heroes-component-renaming, metadata
21-
// #docregion class, heroes-component-renaming
16+
styleUrls: const ['heroes_component.css']
17+
// #docregion renaming
18+
)
19+
// #enddocregion metadata
20+
// #docregion class
2221
class HeroesComponent implements OnInit {
23-
// #enddocregion heroes-component-renaming
22+
// #enddocregion renaming
2423
final Router _router;
2524
final HeroService _heroService;
2625
List<Hero> heroes;
2726
Hero selectedHero;
2827

28+
// #docregion renaming
2929
HeroesComponent(this._heroService, this._router);
30+
// #enddocregion renaming
3031

3132
Future<Null> getHeroes() async {
3233
heroes = await _heroService.getHeroes();
@@ -44,5 +45,5 @@ class HeroesComponent implements OnInit {
4445
'HeroDetail',
4546
{'id': selectedHero.id.toString()}
4647
]);
47-
// #docregion heroes-component-renaming
48+
// #docregion renaming
4849
}

public/docs/_examples/toh-5/dart/web/styles_1.css

-24
This file was deleted.

0 commit comments

Comments
 (0)