Skip to content

Instantly share code, notes, and snippets.

@tangrammer
Last active December 10, 2015 02:09
Show Gist options
  • Save tangrammer/4365493 to your computer and use it in GitHub Desktop.
Save tangrammer/4365493 to your computer and use it in GitHub Desktop.
core_node.js it is an utility to load javascript client libs into node code (only methods specified) In this case, the developer wants to use the public/javascript/persons.js lib, that it uses both public/javascript/core.js and public/javascript/i18n (so these others have to been loaded before persons.js)
var fs = require('fs');
exports.load_js_client=function(context, path_lib, method_names, subcontext){
(function(){
if(typeof subcontext !== "undefined"){
for(var v in subcontext){
this[v]=subcontext[v];
console.log(v+"="+this[v]);
}
}
eval(fs.readFileSync(path_lib,'utf8'));
for(var i=0; i<method_names.length; i++){
context[method_names[i]]=eval(method_names[i]);
}
})();
}
var core=require('./core_node.js');
var path_persons_lib='./public/javascripts/api/persons/model.js';
var path_core_lib='./public/javascripts/api/core/core.js';
var path_i18n_lib='./public/javascripts/api/persons/i18n.js';
var context={};
core.load_js_client(context, path_core_lib, ['getters', 'init']);
core.load_js_client(context, path_i18n_lib, ['date_printer', 'wage_printer']);
core.load_js_client(exports, path_persons_lib, ['webmaster','data_person_example', 'set_locale', 'create_person', 'internationalize', 'invoke_i18n_methods'], context);
var $persons=require('./load_persons_lib.js');
log("--------->>>>>>"+$persons.webmaster);
var person=$persons.create_person($persons.data_person_example);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment