UNPKG

wns-angular-package

Version:

Angular interface package/bundle for WNS Middleware

82 lines (66 loc) 1.6 kB
/** * WNS Angular Package -> wnAngularController * * @copyright: Copyright © 2013- Pedro Nasser ® * @page: http://github.com/pedronasser/wns-angular-package * @license: http://github.com/pedronasser/wns-angular-package/blob/master/LICENSE */ /** * No description yet. * * @author Pedro Nasser */ // Exports module.exports = { /** * Class Extension */ extend: ['wnAngularComponent'], /** * PRIVATE */ private: { _config: { moduleName: 'module', controllerName: 'MyCtrl' }, _dependencies: ['$scope'] }, /** * Public Variables */ public: {}, /** * Methods */ methods: { /** * Render component code; */ render: function (config,build) { var result = ''; var scopeMethod = /^\$/; result += 'angular.module("'+_config.moduleName+'").controller("'+_config.controllerName+'", ["'+_dependencies.join('","')+'",function ('+_dependencies.join(",")+') {\n\n'; var methods=''; for (b in build.methods) { var name = b; if (name=='render'||name=='init') continue; if (!scopeMethod.test(name)) methods += build.methods[b].toString().replace(/^function\s+\(/,"function "+b+"(")+"\n\n"; else { name = name.replace(scopeMethod,"") methods += "$scope."+name+" = "+build.methods[b].toString()+";\n\n"; } } result += methods; var init = this.init.toString().replace(/^function.+\{/,"").replace(/\}$/,"\n\n"); result+=init; result += '}]);'; this.renderedCode = result; } } };