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

Commit ad6f459

Browse files
committed
feat(cb-ts-to-js): add es6 examples
1 parent 14c01fb commit ad6f459

32 files changed

+1016
-6
lines changed

gulpfile.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,16 @@ function findAndRunE2eTests(filter, outputFile) {
246246
e2eSpecPaths.forEach(function(specPath) {
247247
// get all of the examples under each dir where a pcFilename is found
248248
localExamplePaths = getExamplePaths(specPath, true);
249-
// Filter by language
250-
localExamplePaths = localExamplePaths.filter(function (fn) {
251-
return fn.match('/'+lang+'$') != null;
252-
});
249+
// Filter by example name
253250
if (filter) {
254251
localExamplePaths = localExamplePaths.filter(function (fn) {
255252
return fn.match(filter) != null;
256253
})
257254
}
255+
// Filter by language, also supports variations like js-es6
256+
localExamplePaths = localExamplePaths.filter(function (fn) {
257+
return fn.match('/'+lang+'(?:-[^/]*)?$') != null;
258+
});
258259
localExamplePaths.forEach(function(examplePath) {
259260
examplePaths.push(examplePath);
260261
})

public/docs/_examples/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ wallaby.js
1111

1212
_test-output
1313
**/ts/**/*.js
14+
**/js-es6*/**/*.js
1415
**/ts-snippets/**/*.js
1516
*.d.ts
1617

public/docs/_examples/_boilerplate/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"build:webpack": "rimraf dist && webpack --config config/webpack.prod.js --bail",
1919
"build:cli": "ng build",
2020
"build:aot": "ngc -p tsconfig-aot.json && rollup -c rollup-config.js",
21+
"build:babel": "babel app -d app --extensions \".es6\" --source-maps",
2122
"copy-dist-files": "node ./copy-dist-files.js",
2223
"i18n": "ng-xi18n"
2324
},
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"presets": [
3+
"es2015",
4+
"angular2"
5+
]
6+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Injectable } from '@angular/core';
2+
3+
@Injectable()
4+
export class DataService {
5+
constructor() {
6+
}
7+
getHeroName() {
8+
return 'Windstorm';
9+
}
10+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import {
2+
Attribute,
3+
Component,
4+
Inject,
5+
Optional,
6+
NgModule
7+
} from '@angular/core';
8+
import { BrowserModule } from '@angular/platform-browser';
9+
10+
// #docregion
11+
@Component({
12+
selector: 'hero-title',
13+
template: `
14+
<h1>{{titlePrefix}} {{title}}</h1>
15+
<button (click)="ok()">OK</button>
16+
<p>{{ msg }}</p>
17+
`
18+
})
19+
class TitleComponent {
20+
msg = '';
21+
constructor(
22+
@Inject('titlePrefix') @Optional() titlePrefix,
23+
@Attribute('title') title) {
24+
this.titlePrefix = titlePrefix;
25+
this.title = title;
26+
}
27+
28+
ok() {
29+
this.msg = 'OK!';
30+
}
31+
}
32+
// #enddocregion
33+
34+
@Component({
35+
selector: 'hero-di-inject-additional',
36+
template: `<hero-title title="Tour of Heroes">
37+
</hero-title>`
38+
})
39+
class AppComponent { }
40+
41+
@NgModule({
42+
imports: [ BrowserModule ],
43+
declarations: [
44+
AppComponent,
45+
TitleComponent
46+
],
47+
bootstrap: [ AppComponent ]
48+
})
49+
export class HeroesDIInjectAdditionalModule { }
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Component, Inject, NgModule } from '@angular/core';
2+
import { BrowserModule } from '@angular/platform-browser';
3+
4+
// #docregion
5+
@Component({
6+
selector: 'hero-di-inject',
7+
template: `<h1>Hero: {{name}}</h1>`
8+
})
9+
class HeroComponent {
10+
constructor(@Inject('heroName') name) {
11+
this.name = name;
12+
}
13+
}
14+
// #enddocregion
15+
16+
@NgModule({
17+
imports: [ BrowserModule ],
18+
providers: [ { provide: 'heroName', useValue: 'Windstorm' } ],
19+
declarations: [ HeroComponent ],
20+
bootstrap: [ HeroComponent ]
21+
})
22+
export class HeroesDIInjectModule { }
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Component, NgModule } from '@angular/core';
2+
import { BrowserModule } from '@angular/platform-browser';
3+
4+
import { DataService } from './data.service';
5+
6+
// #docregion
7+
@Component({
8+
selector: 'hero-di',
9+
template: `<h1>Hero: {{name}}</h1>`
10+
})
11+
class HeroComponent {
12+
name;
13+
constructor(dataService: DataService) {
14+
this.name = dataService.getHeroName();
15+
}
16+
}
17+
// #enddocregion
18+
19+
@NgModule({
20+
imports: [ BrowserModule ],
21+
providers: [ DataService ],
22+
declarations: [ HeroComponent ],
23+
bootstrap: [ HeroComponent ]
24+
})
25+
export class HeroesDIModule { }
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import {
2+
Component,
3+
EventEmitter,
4+
Input,
5+
Output,
6+
NgModule
7+
} from '@angular/core';
8+
import { BrowserModule } from '@angular/platform-browser';
9+
10+
// #docregion
11+
@Component({
12+
selector: 'my-confirm',
13+
template: `
14+
<button (click)="onOkClick()">
15+
{{okMsg}}
16+
</button>
17+
<button (click)="onNotOkClick()">
18+
{{notOkMsg}}
19+
</button>
20+
`
21+
})
22+
class ConfirmComponent {
23+
@Input() okMsg;
24+
@Input('cancelMsg') notOkMsg;
25+
@Output() ok =
26+
new EventEmitter();
27+
@Output('cancel') notOk =
28+
new EventEmitter();
29+
30+
onOkClick() {
31+
this.ok.next(true);
32+
}
33+
onNotOkClick() {
34+
this.notOk.next(true);
35+
}
36+
}
37+
// #enddocregion
38+
39+
40+
@Component({
41+
selector: 'hero-io',
42+
template: `
43+
<my-confirm [okMsg]="'OK'"
44+
[cancelMsg]="'Cancel'"
45+
(ok)="onOk()"
46+
(cancel)="onCancel()">
47+
</my-confirm>
48+
<span *ngIf="okClicked">OK clicked</span>
49+
<span *ngIf="cancelClicked">Cancel clicked</span>
50+
`
51+
})
52+
class AppComponent {
53+
okClicked;
54+
cancelClicked;
55+
56+
onOk() {
57+
this.okClicked = true;
58+
}
59+
onCancel() {
60+
this.cancelClicked = true;
61+
}
62+
}
63+
64+
65+
@NgModule({
66+
imports: [ BrowserModule ],
67+
declarations: [
68+
AppComponent,
69+
ConfirmComponent
70+
],
71+
bootstrap: [ AppComponent ]
72+
})
73+
export class HeroesIOModule { }
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// #docplaster
2+
// #docregion
3+
import { Component, OnInit } from '@angular/core';
4+
// #enddocregion
5+
import { NgModule } from '@angular/core';
6+
import { BrowserModule } from '@angular/platform-browser';
7+
8+
@Component({
9+
selector: 'hero-lifecycle',
10+
template: `<h1>Hero: {{name}}</h1>`
11+
})
12+
// #docregion
13+
class HeroComponent
14+
implements OnInit {
15+
name;
16+
ngOnInit() {
17+
this.name = 'Windstorm';
18+
}
19+
}
20+
// #enddocregion
21+
22+
@NgModule({
23+
imports: [ BrowserModule ],
24+
declarations: [ HeroComponent ],
25+
bootstrap: [ HeroComponent ]
26+
})
27+
export class HeroesLifecycleModule { }
28+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// #docplaster
2+
// #docregion metadata
3+
import { Component } from '@angular/core';
4+
5+
@Component({
6+
selector: 'hero-view',
7+
template:
8+
'<h1>Hero: {{getName()}}</h1>'
9+
})
10+
// #docregion appexport
11+
// #docregion class
12+
export class HeroComponent {
13+
title = 'Hero Detail';
14+
getName() {return 'Windstorm'; }
15+
}
16+
// #enddocregion class
17+
// #enddocregion appexport
18+
// #enddocregion metadata
19+
20+
import { NgModule } from '@angular/core';
21+
import { BrowserModule } from '@angular/platform-browser';
22+
23+
@NgModule({
24+
imports: [ BrowserModule ],
25+
declarations: [ HeroComponent ],
26+
bootstrap: [ HeroComponent ]
27+
})
28+
export class HeroesModule { }
29+
30+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import {
2+
Component,
3+
HostBinding,
4+
HostListener,
5+
NgModule
6+
} from '@angular/core';
7+
import { BrowserModule } from '@angular/platform-browser';
8+
9+
// #docregion
10+
@Component({
11+
selector: 'heroes-bindings',
12+
template: `<h1 [class.active]="active">
13+
Tour of Heroes
14+
</h1>`
15+
})
16+
class HeroesComponent {
17+
@HostBinding() title = 'Tooltip content';
18+
@HostBinding('class.heading')
19+
hClass = true;
20+
active;
21+
22+
constructor() {}
23+
24+
@HostListener('click')
25+
clicked() {
26+
this.active = !this.active;
27+
}
28+
29+
@HostListener('dblclick', ['$event'])
30+
doubleClicked(evt) {
31+
this.active = true;
32+
}
33+
}
34+
// #enddocregion
35+
36+
@NgModule({
37+
imports: [ BrowserModule ],
38+
declarations: [ HeroesComponent ],
39+
bootstrap: [ HeroesComponent ]
40+
})
41+
export class HeroesHostBindingsModule { }

0 commit comments

Comments
 (0)