mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 03:32:21 +08:00
Feature(generate): Add generator for pipes
This commit is contained in:
27
tooling/generators/pipe/index.js
Normal file
27
tooling/generators/pipe/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);
|
||||||
|
});
|
||||||
|
};
|
11
tooling/generators/pipe/pipe.tmpl.js
Normal file
11
tooling/generators/pipe/pipe.tmpl.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import {Injectable, Pipe} from 'angular2/angular2';
|
||||||
|
|
||||||
|
@Pipe({
|
||||||
|
name: '<%= fileAndClassName %>'
|
||||||
|
})
|
||||||
|
@Injectable()
|
||||||
|
class <%= javascriptClassName %> {
|
||||||
|
transform(v, args) {
|
||||||
|
return v.toLowerCase();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user