mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-22 05:21:52 +08:00
chore(generators): update pipe generator
This commit is contained in:
@ -1,27 +1,30 @@
|
|||||||
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) {
|
|
||||||
Generate.createScaffoldDirectories({appDirectory: options.appDirectory, componentDirectory: 'pipes', fileName: options.fileName});
|
|
||||||
|
|
||||||
options.rootDirectory = options.rootDirectory || path.join('app', 'pipes');
|
var path = require('path'),
|
||||||
var savePath = path.join(options.appDirectory, options.rootDirectory, options.fileName);
|
fs = require('fs'),
|
||||||
|
shell = require('shelljs'),
|
||||||
|
Generator = require('../../generator');
|
||||||
|
|
||||||
var templates = Generate.loadGeneratorTemplates(__dirname);
|
module.exports = PipeGenerator;
|
||||||
|
|
||||||
|
function PipeGenerator(options) {
|
||||||
|
Generator.call(this, options);
|
||||||
|
this.directory = path.join('app', 'pipes');
|
||||||
|
}
|
||||||
|
|
||||||
|
PipeGenerator.prototype = Object.create(Generator.prototype);
|
||||||
|
|
||||||
|
PipeGenerator.prototype.makeDirectories = function(){
|
||||||
|
shell.mkdir('-p', path.join(this.appDirectory, this.directory));
|
||||||
|
}
|
||||||
|
|
||||||
|
PipeGenerator.prototype.renderTemplates = function renderTemplates() {
|
||||||
|
var templates = this.loadTemplates();
|
||||||
|
|
||||||
templates.forEach(function(template) {
|
templates.forEach(function(template) {
|
||||||
options.templatePath = template.file;
|
var renderedTemplate = this.renderTemplate(template);
|
||||||
var renderedTemplate = Generate.renderTemplateFromFile(options);
|
var renderedTemplateDest = path.join(this.appDirectory, this.directory, this.name + template.extension);
|
||||||
var saveFilePath = path.join(savePath, [options.fileName, template.type].join(''));
|
console.log('√ Create'.blue, path.relative(this.appDirectory, renderedTemplateDest));
|
||||||
// console.log('renderedTemplate', renderedTemplate, 'saving to', saveFilePath);
|
fs.writeFileSync(renderedTemplateDest, renderedTemplate);
|
||||||
console.log('√ Create'.blue, path.relative(options.appDirectory, saveFilePath));
|
}, this);
|
||||||
fs.writeFileSync(saveFilePath, renderedTemplate);
|
}
|
||||||
});
|
|
||||||
};
|
|
||||||
|
@ -1,11 +1,21 @@
|
|||||||
import {Injectable, Pipe} from 'angular2/angular2';
|
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({
|
@Pipe({
|
||||||
name: '<%= fileName %>'
|
name: '<%= fileName %>'
|
||||||
})
|
})
|
||||||
@Injectable()
|
@Injectable()
|
||||||
class <%= jsClassName %> {
|
export class <%= jsClassName %> {
|
||||||
transform(v, args) {
|
/*
|
||||||
return v.toLowerCase();
|
Takes a value and makes it lowercase.
|
||||||
|
*/
|
||||||
|
transform(value, args) {
|
||||||
|
value = value + ''; // make sure it's a string
|
||||||
|
return value.toLowerCase();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user