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

Commit 182493f

Browse files
authored
feat(cb-ts-to-js): add es6 examples (#2606)
* feat(cb-ts-to-js): add es6 examples update docshredder to shred .es6 optimized focus gulp task convert imports and metadate sections add DI section add host and query metadata section add intro fix capitalization and grammar * docs(ts-to-js): ward's edits (incomplete) * docs(ts-to-js): add separate template files for some components * docs(cb-ts-to-js): refactor sample code
2 parents 9e9666b + 53f5538 commit 182493f

File tree

101 files changed

+2711
-1330
lines changed

Some content is hidden

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

101 files changed

+2711
-1330
lines changed

gulpfile.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -247,15 +247,16 @@ function findAndRunE2eTests(filter, outputFile) {
247247
e2eSpecPaths.forEach(function(specPath) {
248248
// get all of the examples under each dir where a pcFilename is found
249249
localExamplePaths = getExamplePaths(specPath, true);
250-
// Filter by language
251-
localExamplePaths = localExamplePaths.filter(function (fn) {
252-
return fn.match('/'+lang+'$') != null;
253-
});
250+
// Filter by example name
254251
if (filter) {
255252
localExamplePaths = localExamplePaths.filter(function (fn) {
256253
return fn.match(filter) != null;
257254
})
258255
}
256+
// Filter by language, also supports variations like js-es6
257+
localExamplePaths = localExamplePaths.filter(function (fn) {
258+
return fn.match('/'+lang+'(?:-[^/]*)?$') != null;
259+
});
259260
localExamplePaths.forEach(function(examplePath) {
260261
examplePaths.push(examplePath);
261262
})
@@ -1270,7 +1271,7 @@ function apiExamplesWatch(postShredAction) {
12701271
}
12711272

12721273
function devGuideExamplesWatch(shredOptions, postShredAction, focus) {
1273-
var watchPattern = focus ? '**/{' + focus + ',cb-' + focus+ '}/**/*.*' : '**/*.*';
1274+
var watchPattern = focus ? '{' + focus + ',cb-' + focus+ '}/**/*.*' : '**/*.*';
12741275
var includePattern = path.join(shredOptions.examplesDir, watchPattern);
12751276
// removed this version because gulp.watch has the same glob issue that dgeni has.
12761277
// var excludePattern = '!' + path.join(shredOptions.examplesDir, '**/node_modules/**/*.*');

public/docs/_examples/.gitignore

+1
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

+1
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
},

public/docs/_examples/cb-ts-to-js/e2e-spec.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'use strict'; // necessary for es6 output in node
1+
'use strict'; // necessary for es6 output in node
22

33
import { browser, element, by } from 'protractor';
44

@@ -9,7 +9,7 @@ describe('TypeScript to Javascript tests', function () {
99
});
1010

1111
it('should display the basic component example', function () {
12-
testTag('hero-view', 'Hero: Windstorm');
12+
testTag('hero-view', 'Hero Detail: Windstorm');
1313
});
1414

1515
it('should display the component example with lifecycle methods', function () {
@@ -36,7 +36,7 @@ describe('TypeScript to Javascript tests', function () {
3636

3737
it('should support component with inputs and outputs', function () {
3838
let app = element(by.css('hero-io'));
39-
let confirmComponent = app.element(by.css('my-confirm'));
39+
let confirmComponent = app.element(by.css('app-confirm'));
4040

4141
confirmComponent.element(by.buttonText('OK')).click();
4242
expect(app.element(by.cssContainingText('span', 'OK clicked')).isPresent()).toBe(true);
@@ -46,11 +46,11 @@ describe('TypeScript to Javascript tests', function () {
4646
});
4747

4848
it('should support host bindings and host listeners', function() {
49-
let app = element(by.css('heroes-bindings'));
49+
let app = element(by.css('hero-host'));
5050
let h1 = app.element(by.css('h1'));
5151

5252
expect(app.getAttribute('class')).toBe('heading');
53-
expect(app.getAttribute('title')).toBe('Tooltip content');
53+
expect(app.getAttribute('title')).toContain('Tooltip');
5454

5555
h1.click();
5656
expect(h1.getAttribute('class')).toBe('active');
@@ -61,12 +61,12 @@ describe('TypeScript to Javascript tests', function () {
6161
});
6262

6363
it('should support content and view queries', function() {
64-
let app = element(by.css('heroes-queries'));
65-
let windstorm = app.element(by.css('a-hero:first-child'));
64+
let app = element(by.css('hero-queries'));
65+
let windstorm = app.element(by.css('view-child:first-child'));
6666

67-
app.element(by.buttonText('Activate')).click();
67+
app.element(by.css('button')).click();
6868
expect(windstorm.element(by.css('h2')).getAttribute('class')).toBe('active');
69-
expect(windstorm.element(by.css('active-label')).getText()).toBe('Active');
69+
expect(windstorm.element(by.css('content-child')).getText()).toBe('Active');
7070
});
7171

7272
function testTag(selector: string, expectedText: string) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"presets": [
3+
"es2015",
4+
"angular2"
5+
]
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
moduleId: module.id,
5+
selector: 'my-app',
6+
templateUrl: 'app.component.html',
7+
styles: [
8+
// See hero-di-inject-additional.component
9+
'hero-host, hero-host-meta { border: 1px dashed black; display: block; padding: 4px;}',
10+
'.heading {font-style: italic}'
11+
]
12+
})
13+
export class AppComponent {
14+
title = 'ES6 JavaScript with Decorators';
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<a id="toc"></a>
2+
<h1>{{title}}</h1>
3+
<a href="#class-metadata">Classes and Class Metadata</a><br>
4+
<a href="#io-metadata">Input and Output Decorators</a><br>
5+
<a href="#dependency-injection">Dependency Injection</a><br>
6+
<a href="#host-metadata">Host Metadata</a><br>
7+
<a href="#view-child-metadata">View and Child Metadata</a><br>
8+
9+
<hr>
10+
<h4 id="class-metadata">Classes and Class Metadata</h4>
11+
<hero-view></hero-view>
12+
<hero-lifecycle></hero-lifecycle>
13+
14+
<hr>
15+
<h4 id="io-metadata">Input and Output Metadata</h4>
16+
<hero-io></hero-io>
17+
18+
<hr>
19+
<h4 id="dependency-injection">Dependency Injection</h4>
20+
<hero-di></hero-di>
21+
<hero-di-inject></hero-di-inject>
22+
<hero-di-inject-additional></hero-di-inject-additional>
23+
24+
<hr>
25+
<h4 id="host-metadata">Host Metadata</h4>
26+
<hero-host></hero-host>
27+
<hero-host-meta></hero-host-meta>
28+
29+
<hr>
30+
<h4 id="view-child-metadata">View and Child Metadata</h4>
31+
<hero-queries></hero-queries>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
2+
import { BrowserModule } from '@angular/platform-browser';
3+
4+
import { AppComponent } from './app.component';
5+
import { ConfirmComponent } from './confirm.component';
6+
// #docregion appimport
7+
import { HeroComponent } from './hero.component';
8+
// #enddocregion appimport
9+
import { HeroComponent as HeroDIComponent } from './hero-di.component';
10+
import { HeroComponent as HeroDIInjectComponent } from './hero-di-inject.component';
11+
import { HeroComponent as HeroDIInjectAdditionalComponent } from './hero-di-inject-additional.component';
12+
import { HeroHostComponent } from './hero-host.component';
13+
import { HeroHostMetaComponent } from './hero-host-meta.component';
14+
import { HeroIOComponent } from './hero-io.component';
15+
import { HeroComponent as HeroLifecycleComponent } from './hero-lifecycle.component';
16+
import { HeroQueriesComponent, ViewChildComponent, ContentChildComponent } from './hero-queries.component';
17+
import { HeroTitleComponent } from './hero-title.component';
18+
19+
import { DataService } from './data.service';
20+
21+
@NgModule({
22+
imports: [
23+
BrowserModule
24+
],
25+
declarations: [
26+
AppComponent,
27+
ConfirmComponent,
28+
HeroComponent,
29+
HeroDIComponent,
30+
HeroDIInjectComponent,
31+
HeroDIInjectAdditionalComponent,
32+
HeroHostComponent, HeroHostMetaComponent,
33+
HeroIOComponent,
34+
HeroLifecycleComponent,
35+
HeroQueriesComponent, ViewChildComponent, ContentChildComponent,
36+
HeroTitleComponent
37+
],
38+
providers: [
39+
DataService,
40+
{ provide: 'heroName', useValue: 'Windstorm' }
41+
],
42+
bootstrap: [ AppComponent ],
43+
44+
// schemas: [ NO_ERRORS_SCHEMA ] // helpful for debugging
45+
})
46+
export class AppModule { }
47+
48+
/* tslint:disable no-unused-variable */
49+
// #docregion ng2import
50+
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
51+
import {
52+
LocationStrategy,
53+
HashLocationStrategy
54+
} from '@angular/common';
55+
// #enddocregion ng2import
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Component, EventEmitter, Input, Output } from '@angular/core';
2+
3+
// #docregion
4+
@Component({
5+
moduleId: module.id,
6+
selector: 'app-confirm',
7+
templateUrl: 'confirm.component.html'
8+
})
9+
export class ConfirmComponent {
10+
@Input() okMsg = '';
11+
@Input('cancelMsg') notOkMsg = '';
12+
@Output() ok = new EventEmitter();
13+
@Output('cancel') notOk = new EventEmitter();
14+
15+
onOkClick() {
16+
this.ok.emit(true);
17+
}
18+
onNotOkClick() {
19+
this.notOk.emit(true);
20+
}
21+
}
22+
// #enddocregion
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<button (click)="onOkClick()">
2+
{{okMsg}}
3+
</button>
4+
<button (click)="onNotOkClick()">
5+
{{notOkMsg}}
6+
</button>
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'hero-di-inject-additional',
5+
template: `<hero-title title="Tour of Heroes"></hero-title>`
6+
})
7+
export class HeroComponent { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Component, Inject } from '@angular/core';
2+
3+
// #docregion
4+
@Component({
5+
selector: 'hero-di-inject',
6+
template: `<h1>Hero: {{name}}</h1>`
7+
})
8+
export class HeroComponent {
9+
constructor(@Inject('heroName') name) {
10+
this.name = name;
11+
}
12+
}
13+
// #enddocregion
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Component } from '@angular/core';
2+
import { DataService } from './data.service';
3+
4+
// #docregion
5+
@Component({
6+
selector: 'hero-di',
7+
template: `<h1>Hero: {{name}}</h1>`
8+
})
9+
export class HeroComponent {
10+
name = '';
11+
constructor(dataService: DataService) {
12+
this.name = dataService.getHeroName();
13+
}
14+
}
15+
// #enddocregion
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { Component } from '@angular/core';
2+
3+
// #docregion
4+
@Component({
5+
selector: 'hero-host-meta',
6+
template: `
7+
<h1 [class.active]="active">Hero Host in Metadata</h1>
8+
<div>Heading clicks: {{clicks}}</div>
9+
`,
10+
host: {
11+
// HostBindings to the <hero-host-meta> element
12+
'[title]': 'title',
13+
'[class.heading]': 'headingClass',
14+
15+
// HostListeners on the entire <hero-host-meta> element
16+
'(click)': 'clicked()',
17+
'(mouseenter)': 'enter($event)',
18+
'(mouseleave)': 'leave($event)'
19+
},
20+
// Styles within (but excluding) the <hero-host-meta> element
21+
styles: ['.active {background-color: coral;}']
22+
})
23+
export class HeroHostMetaComponent {
24+
title = 'Hero Host in Metadata Tooltip';
25+
headingClass = true;
26+
27+
active = false;
28+
clicks = 0;
29+
30+
clicked() {
31+
this.clicks += 1;
32+
}
33+
34+
enter(event: Event) {
35+
this.active = true;
36+
this.headingClass = false;
37+
}
38+
39+
leave(event: Event) {
40+
this.active = false;
41+
this.headingClass = true;
42+
}
43+
}
44+
// #enddocregion
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { Component, HostBinding, HostListener } from '@angular/core';
2+
3+
// #docregion
4+
@Component({
5+
selector: 'hero-host',
6+
template: `
7+
<h1 [class.active]="active">Hero Host in Decorators</h1>
8+
<div>Heading clicks: {{clicks}}</div>
9+
`,
10+
// Styles within (but excluding) the <hero-host> element
11+
styles: ['.active {background-color: yellow;}']
12+
})
13+
export class HeroHostComponent {
14+
// HostBindings to the <hero-host> element
15+
@HostBinding() title = 'Hero Host in Decorators Tooltip';
16+
@HostBinding('class.heading') headingClass = true;
17+
18+
active = false;
19+
clicks = 0;
20+
21+
// HostListeners on the entire <hero-host> element
22+
@HostListener('click')
23+
clicked() {
24+
this.clicks += 1;
25+
}
26+
27+
@HostListener('mouseenter', ['$event'])
28+
enter(event: Event) {
29+
this.active = true;
30+
this.headingClass = false;
31+
}
32+
33+
@HostListener('mouseleave', ['$event'])
34+
leave(event: Event) {
35+
this.active = false;
36+
this.headingClass = true;
37+
}
38+
}
39+
// #enddocregion

0 commit comments

Comments
 (0)