mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 12:29:55 +08:00
Typescript generators
* @Inject to parameters() Changed injection of Http to use parameters() instead of @Inject * import map operator Added import of map operator from rxjs * Typescript Generator Support Support for typescript generators * Tabs -> spaces * Changes From Tim's Feedback
This commit is contained in:

committed by
Tim Lancina

parent
6125e1c622
commit
f61a57b9ee
@ -9,6 +9,7 @@ function Generator(options) {
|
|||||||
this.name = options.name;
|
this.name = options.name;
|
||||||
this.type = options.generator;
|
this.type = options.generator;
|
||||||
this.appDirectory = options.appDirectory;
|
this.appDirectory = options.appDirectory;
|
||||||
|
this.isTS = options.isTS;
|
||||||
|
|
||||||
//templateVars
|
//templateVars
|
||||||
this.fileName = _.kebabCase(this.name);
|
this.fileName = _.kebabCase(this.name);
|
||||||
@ -49,6 +50,16 @@ Generator.prototype.loadTemplates = function() {
|
|||||||
if (template.indexOf('.tmpl') == -1) {
|
if (template.indexOf('.tmpl') == -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//If not using typescript, ignore .ts files
|
||||||
|
if(!this.isTS && template.indexOf('.ts') != -1){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//If using typescript, ignore .js files
|
||||||
|
if(this.isTS && template.indexOf('.js') != -1){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
templates.push({path: path.join(generatorPath, template), extension: path.extname(template)});
|
templates.push({path: path.join(generatorPath, template), extension: path.extname(template)});
|
||||||
}, this);
|
}, this);
|
||||||
|
19
tooling/generators/component/component.tmpl.ts
Normal file
19
tooling/generators/component/component.tmpl.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import {Component} from 'angular2/core';
|
||||||
|
import {IONIC_DIRECTIVES} from 'ionic-angular';
|
||||||
|
|
||||||
|
/*
|
||||||
|
Generated class for the <%= jsClassName %> component.
|
||||||
|
|
||||||
|
See https://angular.io/docs/ts/latest/api/core/ComponentMetadata-class.html
|
||||||
|
for more info on Angular 2 Components.
|
||||||
|
*/
|
||||||
|
@Component({
|
||||||
|
selector: '<%= fileName %>',
|
||||||
|
templateUrl: 'build/<%= directory %>/<%= fileName %>/<%= fileName %>.html',
|
||||||
|
directives: [IONIC_DIRECTIVES] // makes all Ionic directives available to your component
|
||||||
|
})
|
||||||
|
export class <%= jsClassName %> {
|
||||||
|
constructor() {
|
||||||
|
this.text = 'Hello World';
|
||||||
|
}
|
||||||
|
}
|
16
tooling/generators/directive/directive.tmpl.ts
Normal file
16
tooling/generators/directive/directive.tmpl.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import {Directive} from 'angular2/core';
|
||||||
|
|
||||||
|
/*
|
||||||
|
Generated class for the <%= jsClassName %> directive.
|
||||||
|
|
||||||
|
See https://angular.io/docs/ts/latest/api/core/DirectiveMetadata-class.html
|
||||||
|
for more info on Angular 2 Directives.
|
||||||
|
*/
|
||||||
|
@Directive({
|
||||||
|
selector: '[<%= fileName %>]' // Attribute selector
|
||||||
|
})
|
||||||
|
export class <%= jsClassName %> {
|
||||||
|
constructor() {
|
||||||
|
console.log('Hello World');
|
||||||
|
}
|
||||||
|
}
|
16
tooling/generators/page/page.tmpl.ts
Normal file
16
tooling/generators/page/page.tmpl.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import {Page, NavController} from 'ionic-angular';
|
||||||
|
|
||||||
|
/*
|
||||||
|
Generated class for the <%= jsClassName %> page.
|
||||||
|
|
||||||
|
See http://ionicframework.com/docs/v2/components/#navigation for more info on
|
||||||
|
Ionic pages and navigation.
|
||||||
|
*/
|
||||||
|
@Page({
|
||||||
|
templateUrl: 'build/<%= directory %>/<%= fileName %>/<%= fileName %>.html',
|
||||||
|
})
|
||||||
|
export class <%= jsClassName %> {
|
||||||
|
constructor(public nav: NavController) {
|
||||||
|
this.nav = nav;
|
||||||
|
}
|
||||||
|
}
|
21
tooling/generators/pipe/pipe.tmpl.ts
Normal file
21
tooling/generators/pipe/pipe.tmpl.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import {Injectable, Pipe} from 'angular2/core';
|
||||||
|
|
||||||
|
/*
|
||||||
|
Generated class for the <%= jsClassName %> pipe.
|
||||||
|
|
||||||
|
See https://angular.io/docs/ts/latest/guide/pipes.html for more info on
|
||||||
|
Angular 2 Pipes.
|
||||||
|
*/
|
||||||
|
@Pipe({
|
||||||
|
name: '<%= fileName %>'
|
||||||
|
})
|
||||||
|
@Injectable()
|
||||||
|
export class <%= jsClassName %> {
|
||||||
|
/*
|
||||||
|
Takes a value and makes it lowercase.
|
||||||
|
*/
|
||||||
|
transform(value: string, args: any[]) {
|
||||||
|
value = value + ''; // make sure it's a string
|
||||||
|
return value.toLowerCase();
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
import {Injectable, Inject} from 'angular2/core';
|
import {Injectable} from 'angular2/core';
|
||||||
import {Http} from 'angular2/http';
|
import {Http} from 'angular2/http';
|
||||||
|
import 'rxjs/add/operator/map';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Generated class for the <%= jsClassName %> provider.
|
Generated class for the <%= jsClassName %> provider.
|
||||||
@ -9,7 +10,11 @@ import {Http} from 'angular2/http';
|
|||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class <%= jsClassName %> {
|
export class <%= jsClassName %> {
|
||||||
constructor(@Inject(Http) http) {
|
static get parameters(){
|
||||||
|
return [[Http]]
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(http) {
|
||||||
this.http = http;
|
this.http = http;
|
||||||
this.data = null;
|
this.data = null;
|
||||||
}
|
}
|
||||||
|
39
tooling/generators/provider/provider.tmpl.ts
Normal file
39
tooling/generators/provider/provider.tmpl.ts
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import {Injectable} from 'angular2/core';
|
||||||
|
import {Http} from 'angular2/http';
|
||||||
|
import 'rxjs/add/operator/map';
|
||||||
|
|
||||||
|
/*
|
||||||
|
Generated class for the <%= jsClassName %> provider.
|
||||||
|
|
||||||
|
See https://angular.io/docs/ts/latest/guide/dependency-injection.html
|
||||||
|
for more info on providers and Angular 2 DI.
|
||||||
|
*/
|
||||||
|
@Injectable()
|
||||||
|
export class <%= jsClassName %> {
|
||||||
|
data: any = null;
|
||||||
|
|
||||||
|
constructor(public http: Http) {}
|
||||||
|
|
||||||
|
load() {
|
||||||
|
if (this.data) {
|
||||||
|
// already loaded data
|
||||||
|
return Promise.resolve(this.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
// don't have the data yet
|
||||||
|
return new Promise(resolve => {
|
||||||
|
// We're using Angular Http provider to request the data,
|
||||||
|
// then on the response it'll map the JSON data to a parsed JS object.
|
||||||
|
// Next we process the data and resolve the promise with the new data.
|
||||||
|
this.http.get('path/to/data.json')
|
||||||
|
.map(res => res.json())
|
||||||
|
.subscribe(data => {
|
||||||
|
// we've got back the raw data, now generate the core schedule data
|
||||||
|
// and save the data for later reference
|
||||||
|
this.data = data;
|
||||||
|
resolve(this.data);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
15
tooling/generators/tabs/tabs.tmpl.ts
Normal file
15
tooling/generators/tabs/tabs.tmpl.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import {NavController, Page} from 'ionic-angular';
|
||||||
|
<% _.forEach(tabs, function(tab) { %>import {<%= tab.jsClassName %>} from '../<%= tab.fileName %>/<%= tab.fileName %>';
|
||||||
|
<% }); %>
|
||||||
|
|
||||||
|
@Page({
|
||||||
|
templateUrl: 'build/<%= directory %>/<%= fileName %>/<%= fileName %>.html'
|
||||||
|
})
|
||||||
|
export class <%= jsClassName %> {
|
||||||
|
|
||||||
|
constructor(public nav: NavController) {
|
||||||
|
// set the root pages for each tab
|
||||||
|
<% _.forEach(tabs, function(tab, i) { %>this.tab<%= ++i %>Root = <%= tab.jsClassName %>;
|
||||||
|
<% }); %>
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user