mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 19:57:22 +08:00
Feature(generators): Add generators for components, directives, and injectables
This commit is contained in:
3
tooling/generators/component/component.tmpl.html
Normal file
3
tooling/generators/component/component.tmpl.html
Normal file
@ -0,0 +1,3 @@
|
||||
<div *ng-if="value">
|
||||
<%= javascriptClassName %>
|
||||
</div>
|
15
tooling/generators/component/component.tmpl.js
Normal file
15
tooling/generators/component/component.tmpl.js
Normal file
@ -0,0 +1,15 @@
|
||||
import {Component, NgIf} from 'angular2/angular2';
|
||||
|
||||
@Component({
|
||||
directives: [NgIf],
|
||||
properties: ['value'], //Change to be whatever properties you want, ex: <<%= fileAndClassName %> value="5">
|
||||
selector: '<%= fileAndClassName %>',
|
||||
templateUrl: 'app/<%= fileAndClassName %>/<%= fileAndClassName %>.html'
|
||||
})
|
||||
export class <%= javascriptClassName %> {
|
||||
constructor() {
|
||||
this.nav = nav;
|
||||
this.popup = popup;
|
||||
this.dataService = dataService;
|
||||
}
|
||||
}
|
26
tooling/generators/component/index.js
Normal file
26
tooling/generators/component/index.js
Normal file
@ -0,0 +1,26 @@
|
||||
var fs = require('fs'),
|
||||
Generator = module.exports,
|
||||
Generate = require('../../generate'),
|
||||
path = require('path'),
|
||||
Q = require('q');
|
||||
/*
|
||||
@options
|
||||
name: Page name
|
||||
appDirectory: App directory of where to save file
|
||||
*/
|
||||
Generator.run = function run(options) {
|
||||
options.rootDirectory = options.rootDirectory || path.join('www', 'app');
|
||||
var savePath = path.join(options.appDirectory, options.rootDirectory, options.fileAndClassName);
|
||||
|
||||
var templates = Generate.loadGeneratorTemplates(__dirname);
|
||||
|
||||
templates.forEach(function(template) {
|
||||
var templatePath = path.join(__dirname, template.file);
|
||||
options.templatePath = templatePath;
|
||||
var renderedTemplate = Generate.renderTemplateFromFile(options);
|
||||
var saveFilePath = path.join(savePath, [options.fileAndClassName, template.type].join(''));
|
||||
// console.log('renderedTemplate', renderedTemplate, 'saving to', saveFilePath);
|
||||
console.log('√ Create'.blue, path.relative(options.appDirectory, saveFilePath));
|
||||
fs.writeFileSync(saveFilePath, renderedTemplate);
|
||||
});
|
||||
};
|
11
tooling/generators/directive/directive.tmpl.js
Normal file
11
tooling/generators/directive/directive.tmpl.js
Normal file
@ -0,0 +1,11 @@
|
||||
import {Directive, ElementRef} from 'angular2/angular2';
|
||||
|
||||
@Directive({
|
||||
properties: ['<%= fileAndClassName %>'], //Change to be whatever properties you want, ex: <<%= fileAndClassName %> value="5">
|
||||
inputs: ['<%= fileAndClassName %>']
|
||||
})
|
||||
export class <%= javascriptClassName %> {
|
||||
constructor(elementRef: ElementRef) {
|
||||
this.ele = elementRef;
|
||||
}
|
||||
}
|
26
tooling/generators/directive/index.js
Normal file
26
tooling/generators/directive/index.js
Normal file
@ -0,0 +1,26 @@
|
||||
var fs = require('fs'),
|
||||
Generator = module.exports,
|
||||
Generate = require('../../generate'),
|
||||
path = require('path'),
|
||||
Q = require('q');
|
||||
/*
|
||||
@options
|
||||
name: Page name
|
||||
appDirectory: App directory of where to save file
|
||||
*/
|
||||
Generator.run = function run(options) {
|
||||
options.rootDirectory = options.rootDirectory || path.join('www', 'app');
|
||||
var savePath = path.join(options.appDirectory, options.rootDirectory, options.fileAndClassName);
|
||||
|
||||
var templates = Generate.loadGeneratorTemplates(__dirname);
|
||||
|
||||
templates.forEach(function(template) {
|
||||
var templatePath = path.join(__dirname, template.file);
|
||||
options.templatePath = templatePath;
|
||||
var renderedTemplate = Generate.renderTemplateFromFile(options);
|
||||
var saveFilePath = path.join(savePath, [options.fileAndClassName, template.type].join(''));
|
||||
// console.log('renderedTemplate', renderedTemplate, 'saving to', saveFilePath);
|
||||
console.log('√ Create'.blue, path.relative(options.appDirectory, saveFilePath));
|
||||
fs.writeFileSync(saveFilePath, renderedTemplate);
|
||||
});
|
||||
};
|
27
tooling/generators/injectable/index.js
Normal file
27
tooling/generators/injectable/index.js
Normal file
@ -0,0 +1,27 @@
|
||||
var fs = require('fs'),
|
||||
Generator = module.exports,
|
||||
Generate = require('../../generate'),
|
||||
path = require('path'),
|
||||
Q = require('q');
|
||||
/*
|
||||
@options
|
||||
name: Page name
|
||||
appDirectory: App directory of where to save file
|
||||
*/
|
||||
Generator.run = function run(options) {
|
||||
|
||||
options.rootDirectory = options.rootDirectory || path.join('www', 'app');
|
||||
var savePath = path.join(options.appDirectory, options.rootDirectory, options.fileAndClassName);
|
||||
|
||||
var templates = Generate.loadGeneratorTemplates(__dirname);
|
||||
|
||||
templates.forEach(function(template) {
|
||||
var templatePath = path.join(__dirname, template.file);
|
||||
options.templatePath = templatePath;
|
||||
var renderedTemplate = Generate.renderTemplateFromFile(options);
|
||||
var saveFilePath = path.join(savePath, [options.fileAndClassName, template.type].join(''));
|
||||
// console.log('renderedTemplate', renderedTemplate, 'saving to', saveFilePath);
|
||||
console.log('√ Create'.blue, path.relative(options.appDirectory, saveFilePath));
|
||||
fs.writeFileSync(saveFilePath, renderedTemplate);
|
||||
});
|
||||
};
|
21
tooling/generators/injectable/injectable.tmpl.js
Normal file
21
tooling/generators/injectable/injectable.tmpl.js
Normal file
@ -0,0 +1,21 @@
|
||||
import {Injectable} from 'angular2/angular2';
|
||||
import {Http} from 'angular2/http';
|
||||
|
||||
@Injectable()
|
||||
export class <%= javascriptClassName %> {
|
||||
constructor(http: Http) {
|
||||
this.http = http;
|
||||
this.data = null;
|
||||
}
|
||||
|
||||
retrieveData() {
|
||||
//Here, we're going to get a JSON data file, use the `map` call to parse json
|
||||
// and finally subscribe to the observable and set our data
|
||||
//to the value it provides once the http request is complete.
|
||||
this.http.get('path/to/data.json')
|
||||
.map(res => res.json())
|
||||
.subscribe(data => {
|
||||
this.data = data;
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user