wns-angular-package
Version:
Angular interface package/bundle for WNS Middleware
81 lines (65 loc) • 1.48 kB
JavaScript
/**
* WNS Angular Package -> wnAngularResource
*
* @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',
resourceName: 'MyResource'
}
},
/**
* Public Variables
*/
public: {},
/**
* Methods
*/
methods: {
/**
* Render component code;
*/
render: function (config,build)
{
var result = '';
var scopeMethod = /^\$/;
result += 'angular.module("'+_config.moduleName+'").factory("'+_config.resourceName+'", ["$resource",';
var init = this.init.toString().replace(/\}$/,"\n\n");
result+=init;
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 += "$resource."+name+" = "+build.methods[b].toString()+"\n\n";
}
}
result += methods;
result += '}]);';
this.renderedCode = result;
}
}
};