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

Commit 414e0db

Browse files
committed
docs(cb-di): ward's tweaks to Tors cookbook
1 parent dcdfad3 commit 414e0db

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1794
-352
lines changed

gulpfile.js

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ var _exampleBoilerplateFiles = [
7474
'package.json',
7575
'styles.css',
7676
'tsconfig.json',
77+
'tslint.json',
7778
'typings.json'
7879
];
7980

public/docs/_examples/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ package.json
66
karma.conf.js
77
karma-test-shim.js
88
tsconfig.json
9+
tslint.json
910
npm-debug*.
1011
**/protractor.config.js

public/docs/_examples/attribute-directives/ts/app/highlight.directive.2.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@ import {Directive, ElementRef, Input} from 'angular2/core';
1212
})
1313

1414
export class HighlightDirective {
15+
1516
// #docregion ctor
16-
constructor(private el: ElementRef) { }
17+
private _el:HTMLElement;
18+
constructor(el: ElementRef) { this._el = el.nativeElement; }
1719
// #enddocregion ctor
1820

1921
// #docregion mouse-methods
2022
onMouseEnter() { this._highlight("yellow"); }
2123
onMouseLeave() { this._highlight(null); }
2224

2325
private _highlight(color: string) {
24-
this.el.nativeElement.style.backgroundColor = color;
26+
this._el.style.backgroundColor = color;
2527
}
2628
// #enddocregion mouse-methods
2729

public/docs/_examples/attribute-directives/ts/app/highlight.directive.ts

+12-9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import {Directive, ElementRef, Input} from 'angular2/core';
1212

1313
// #docregion class-1
1414
export class HighlightDirective {
15+
16+
private _defaultColor = 'red';
17+
private _el:HTMLElement;
1518
// #enddocregion class-1
1619
// #enddocregion full
1720
/*
@@ -20,29 +23,29 @@ export class HighlightDirective {
2023
// #enddocregion highlight
2124
*/
2225
// #docregion full
26+
27+
// #docregion defaultColor
28+
@Input() set defaultColor(colorName:string){
29+
this._defaultColor = colorName || this._defaultColor;
30+
}
31+
// #enddocregion defaultColor
2332
// #docregion class-1
33+
2434
// #docregion color
2535
@Input('myHighlight') highlightColor: string;
2636
// #enddocregion color
2737

28-
private _defaultColor = 'red';
2938
// #enddocregion class-1
30-
// #docregion defaultColor
31-
@Input() set defaultColor(colorName:string){
32-
this._defaultColor = colorName || this._defaultColor;
33-
}
34-
// #enddocregion defaultColor
3539
// #docregion class-1
36-
37-
constructor(private el: ElementRef) { }
40+
constructor(el: ElementRef) { this._el = el.nativeElement; }
3841

3942
// #docregion mouse-enter
4043
onMouseEnter() { this._highlight(this.highlightColor || this._defaultColor); }
4144
// #enddocregion mouse-enter
4245
onMouseLeave() { this._highlight(null); }
4346

4447
private _highlight(color:string) {
45-
this.el.nativeElement.style.backgroundColor = color;
48+
this._el.style.backgroundColor = color;
4649
}
4750
}
4851
// #enddocregion class-1
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,98 @@
1-
describe('Dependency Injection', function () {
1+
describe('Dependency Injection Cookbook', function () {
22

33
beforeAll(function () {
44
browser.get('');
55
});
66

7-
it('should render DI samples', function () {
7+
it('should render Logged in User example', function () {
88
var loggedInUser = element.all(by.xpath('//h3[text()="Logged in user"]')).get(0);
99
expect(loggedInUser).toBeDefined();
10+
});
1011

12+
it('"Bombasto" should be the logged in user', function () {
1113
loggedInUser = element.all(by.xpath('//div[text()="Name: Bombasto"]')).get(0);
1214
expect(loggedInUser).toBeDefined();
13-
15+
});
16+
17+
it('should render sorted heroes', function () {
1418
var sortedHeroes = element.all(by.xpath('//h3[text()="Sorted Heroes" and position()=1]')).get(0);
1519
expect(sortedHeroes).toBeDefined();
16-
20+
});
21+
22+
it('Mr. Nice should be in sorted heroes', function () {
1723
var sortedHero = element.all(by.xpath('//sorted-heroes/[text()="Mr. Nice" and position()=2]')).get(0);
1824
expect(sortedHero).toBeDefined();
19-
25+
});
26+
27+
it('RubberMan should be in sorted heroes', function () {
2028
sortedHero = element.all(by.xpath('//sorted-heroes/[text()="RubberMan" and position()=3]')).get(0);
2129
expect(sortedHero).toBeDefined();
22-
30+
});
31+
32+
it('Magma should be in sorted heroes', function () {
2333
sortedHero = element.all(by.xpath('//sorted-heroes/[text()="Magma"]')).get(0);
2434
expect(sortedHero).toBeDefined();
25-
35+
});
36+
37+
it('should render Hero of the Month', function () {
2638
var heroOfTheMonth = element.all(by.xpath('//h3[text()="Hero of the month"]')).get(0);
2739
expect(heroOfTheMonth).toBeDefined();
28-
40+
});
41+
42+
it('should render Hero Bios', function () {
2943
var heroBios = element.all(by.xpath('//h3[text()="Hero Bios"]')).get(0);
3044
expect(heroBios).toBeDefined();
31-
45+
});
46+
47+
it('should render Magma\'s description in Hero Bios', function () {
3248
var magmaText = element.all(by.xpath('//textarea[text()="Hero of all trades"]')).get(0);
3349
expect(magmaText).toBeDefined();
34-
50+
});
51+
52+
it('should render Magma\'s phone in Hero Bios and Contacts', function () {
3553
var magmaPhone = element.all(by.xpath('//div[text()="Phone #: 555-555-5555"]')).get(0);
3654
expect(magmaPhone).toBeDefined();
55+
});
56+
57+
it('should render Hero-of-the-Month runner-ups', function () {
58+
var runnersUp = element(by.id('rups')).getText();
59+
expect(runnersUp).toContain('RubberMan, Mr. Nice');
60+
});
61+
62+
it('should render DateLogger log entry in Hero-of-the-Month', function () {
63+
var logs = element.all(by.id('logs')).get(0).getText();
64+
expect(logs).toContain('INFO: starting up at');
65+
});
66+
67+
it('should highlight Hero Bios and Contacts container when mouseover', function () {
68+
var target = element(by.css('div[myHighlight="yellow"]'))
69+
var yellow = "rgba(255, 255, 0, 1)";
3770

38-
var runnersUp = element.all(by.xpath('//h4[text()="Other candidates RubberMan, Mr. Nice"]')).get(0);
39-
expect(runnersUp).toBeDefined();
71+
expect(target.getCssValue('background-color')).not.toEqual(yellow);
72+
browser.actions().mouseMove(target).perform();
73+
expect(target.getCssValue('background-color')).toEqual(yellow);
4074
});
75+
76+
describe('in Parent Finder', function () {
77+
var cathy1 = element(by.css('alex cathy'));
78+
var craig1 = element(by.css('alex craig'));
79+
var carol1 = element(by.css('alex carol p'));
80+
var carol2 = element(by.css('barry carol p'));
81+
82+
it('"Cathy" should find "Alex" via the component class', function () {
83+
expect(cathy1.getText()).toContain('Found Alex via the component');
84+
});
85+
86+
it('"Craig" should not find "Alex" via the base class', function () {
87+
expect(craig1.getText()).toContain('Did not find Alex via the base');
88+
});
89+
90+
it('"Carol" within "Alex" should have "Alex" parent', function () {
91+
expect(carol1.getText()).toContain('Alex');
92+
});
93+
94+
it('"Carol" within "Barry" should have "Barry" parent', function () {
95+
expect(carol2.getText()).toContain('Barry');
96+
});
97+
})
4198
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<h1>DI Cookbook</h1>
2+
<div class="di-component">
3+
<h3>Logged in user</h3>
4+
<div>Name: {{userContext.name}}</div>
5+
<div>Role: {{userContext.role}}</div>
6+
</div>
7+
8+
<div class="di-component">
9+
<h3>Hero Bios</h3>
10+
<hero-bios></hero-bios>
11+
</div>
12+
13+
<!-- #docregion highlight -->
14+
<div id="highlight" class="di-component" myHighlight>
15+
<h3>Hero Bios and Contacts</h3>
16+
<div myHighlight="yellow">
17+
<hero-bios-and-contacts></hero-bios-and-contacts>
18+
</div>
19+
</div>
20+
<!-- #enddocregion highlight -->
21+
22+
<div class="di-component">
23+
<hero-of-the-month></hero-of-the-month>
24+
</div>
25+
26+
27+
<div class="di-component">
28+
<h3>Unsorted Heroes</h3>
29+
<unsorted-heroes></unsorted-heroes>
30+
</div>
31+
32+
<div class="di-component">
33+
<h3>Sorted Heroes</h3>
34+
<sorted-heroes></sorted-heroes>
35+
</div>
36+
37+
<div class="di-component">
38+
<parent-finder></parent-finder>
39+
</div>
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,46 @@
11
// #docregion
2-
import {Component,OnInit} from 'angular2/core';
3-
import {LoggerService} from './logger.service';
4-
import {UserContext} from './user-context.service';
5-
import {Heroes} from './hero-bios.component';
6-
import {SortedHeroes} from './sorted-heroes.component';
7-
import {HeroOfTheMonth} from './hero-of-the-month.component';
2+
import { Component } from 'angular2/core';
3+
4+
import { HeroBiosComponent,
5+
HeroBiosAndContactsComponent} from './hero-bios.component';
6+
import { HeroOfTheMonthComponent } from './hero-of-the-month.component';
7+
import { HeroesBaseComponent,
8+
SortedHeroesComponent } from './sorted-heroes.component';
9+
import { HighlightDirective } from './highlight.directive';
10+
import { ParentFinderComponent } from './parent-finder.component';
11+
12+
const DIRECTIVES = [
13+
HeroBiosComponent, HeroBiosAndContactsComponent,
14+
HeroesBaseComponent, SortedHeroesComponent,
15+
HeroOfTheMonthComponent,
16+
HighlightDirective,
17+
ParentFinderComponent
18+
];
19+
20+
// #docregion import-services
21+
import { LoggerService } from './logger.service';
22+
import { UserContextService } from './user-context.service';
23+
import { UserService } from './user.service';
824

925
@Component({
1026
selector: 'my-app',
11-
directives:[Heroes,SortedHeroes,HeroOfTheMonth],
12-
template:
13-
`<h1>DI Components</h1>
14-
<div class="di-component">
15-
<h3>Logged in user</h3>
16-
<div>Name: {{_userContext.name}}</div>
17-
<div>Role: {{_userContext.role}}</div>
18-
</div>
19-
20-
<div class="di-component">
21-
<h3>Sorted Heroes</h3>
22-
<sorted-heroes></sorted-heroes>
23-
</div>
24-
25-
<div class="di-component">
26-
<h3>Hero of the month</h3>
27-
<hero-of-the-month></hero-of-the-month>
28-
</div>
29-
30-
<div class="di-component">
31-
<h3>Hero Bios</h3>
32-
<hero-bios></hero-bios>
33-
</div>`
27+
templateUrl:'app/app.component.html',
28+
directives: DIRECTIVES,
29+
// #docregion providers
30+
providers: [LoggerService, UserContextService, UserService]
31+
// #enddocregion providers
3432
})
33+
export class AppComponent {
34+
// #enddocregion import-services
3535

36-
export class AppComponent implements OnInit {
37-
3836
private userId:number = 1;
39-
40-
constructor(private _logger:LoggerService, private _userContext:UserContext){
41-
this._userContext.loadUser(this.userId);
42-
}
43-
44-
ngOnInit(){
45-
this._logger.logInfo('AppComponent initialized');
37+
38+
// #docregion ctor
39+
constructor(logger:LoggerService, public userContext:UserContextService) {
40+
userContext.loadUser(this.userId);
41+
logger.logInfo('AppComponent initialized');
4642
}
43+
// #enddocregion ctor
44+
// #docregion import-services
4745
}
46+
// #enddocregion import-services

public/docs/_examples/cb-dependency-injection/ts/app/bio.component.ts

-27
This file was deleted.

public/docs/_examples/cb-dependency-injection/ts/app/contact-details.component.ts

-23
This file was deleted.

0 commit comments

Comments
 (0)