UNPKG

rutile

Version:

Factory automation for Mobile Enterprise.

63 lines (46 loc) 2.02 kB
var fs = require('fs'); var Mustache = require('mustache'); var template_file = 'MyAppClient_TMPL/app/Component/controllers/EditForm/Segment/Entity/Collection_Img.js'; /* view: { APP_NAME : app name, CLIENT_NAME : client application name, segment : segment name of this pseudo field, entity : entity name of this pseudo field, fieldName : primary key name of collected entity, used as a pseudo field of this entity in plural segment_collected : segment name collected entity entity_collected : entity name collected imageFieldName_collected : field name representing image expression of collected entity, featuredFieldName_collected : field name representing collected entity, } */ var generate = function(options){ var APP_NAME = options['APP_NAME']; var CLIENT_NAME = options['CLIENT_NAME']; var template_dir = options['template_dir']; var output_dir = options['output_dir']; var view = options['view']; var tools = options['tools']; // apply functions tools.apply(view); // remove trailing slash var t_match = template_dir.match(/\/$/); if( t_match ){ template_dir = template_dir.substr(0,t_match.index); } var o_match = output_dir.match(/\/$/); if( o_match ){ output_dir = output_dir.substr(0,o_match.index); } // make path var template_path = template_dir + '/' + template_file; var output_path = output_dir + '/' + CLIENT_NAME + '/app/controllers/Component/EditForm/' + view.segment + '/' + view.entity + '/Collection/' + view.entity_collected + '.js'; tools.confirmPath(output_dir + '/' + CLIENT_NAME + '/app/controllers/Component/EditForm/' + view.segment + '/' + view.entity + '/Collection'); // render and output var template = fs.readFileSync(template_path); var output = Mustache.render(template.toString(),view); fs.writeFileSync(output_path,output); }; module.exports = { generate : generate };