1
0
Fork 0

fixed context

This commit is contained in:
Frank Celler 2013-03-24 17:53:53 +01:00
parent 0a488cd84b
commit eaa21cdfd1
3 changed files with 58 additions and 36 deletions

View File

@ -608,6 +608,8 @@ function stop_color_print () {
var content;
var fun;
var module;
var env;
var key;
// mark that we have seen the definition, used for debugging only
ModuleExistsCache[description.name] = true;
@ -624,9 +626,18 @@ function stop_color_print () {
pkg.defineModule(description.name, module);
// try to execute the module source code
content = "(function (module, exports, require, print) {"
+ description.content
+ "\n});";
content = "(function (module, exports, require, print, env) {";
env = pkg._environment;
if (env !== undefined) {
for (key in env) {
content += key + " = env['" + key + "'];";
}
}
content += description.content
+ "\n});";
fun = internal.execute(content, undefined, description.name);
@ -639,7 +650,8 @@ function stop_color_print () {
fun(module,
module.exports,
function(path) { return module.require(path); },
internal.print);
internal.print,
env);
}
catch (err) {
pkg.clearModule(description.name);
@ -856,7 +868,7 @@ function stop_color_print () {
/// @brief returns the app root module
////////////////////////////////////////////////////////////////////////////////
Module.prototype.appRootModule = function (name) {
Module.prototype.appRootModule = function (name, type, rootPackage) {
var description;
var libpath;
var pkg;
@ -867,8 +879,12 @@ function stop_color_print () {
return null;
}
if (description.manifest.hasOwnProperty("lib")) {
libpath = description.path + "/" + description.manifest.lib;
if (type === undefined) {
type = 'lib';
}
if (description.manifest.hasOwnProperty(type)) {
libpath = description.path + "/" + description.manifest[type];
}
else {
libpath = description.path;
@ -876,7 +892,7 @@ function stop_color_print () {
pkg = new Package("application",
{name: "application '" + name + "'"},
undefined,
rootPackage,
[ libpath ]);
mdl = new Module("application", 'application', pkg);

View File

@ -216,6 +216,7 @@ function lookupCallbackActionCallback (route, action) {
var func;
var key;
var appModule;
var modelModule;
defn = "func = (function() { var callback = " + action.callback + "; return callback;})();";
env = {};
@ -223,9 +224,39 @@ function lookupCallbackActionCallback (route, action) {
try {
if (action.hasOwnProperty("context")) {
appModule = module.appRootModule(action.context.name);
if (action.hasOwnProperty("requiresModels")) {
var cp = action.context.collectionPrefix;
var me;
modelModule = module.appRootModule(action.context.name,
'models',
appModule._package);
me = modelModule._package._environment = {};
if (cp !== "") {
me.appCollection = function (name) {
return cp + "_" + name;
};
}
else {
me.appCollection = function (name) {
return name;
};
}
me.requireModel = function (path) {
modelModule.require(path);
};
}
else {
modelModule = appModule;
}
}
else {
appModule = module.root;
modelModule = appModule;
}
if (action.hasOwnProperty("requiresLibs")) {
@ -233,9 +264,7 @@ function lookupCallbackActionCallback (route, action) {
for (key in requires) {
if (requires.hasOwnProperty(key)) {
var val = requires[key];
env[key] = appModule.require(val);
env[key] = appModule.require(requires[key]);
}
}
}
@ -245,30 +274,7 @@ function lookupCallbackActionCallback (route, action) {
for (key in models) {
if (models.hasOwnProperty(key)) {
var val = models[key];
if (action.hasOwnProperty("context")) {
var cp = action.collectionPrefix;
appModule = module.appRootModule(action.context.name);
if (cp !== "") {
appModule._environment = {
appCollection: function (name) {
return cp + "/" + name;
}
};
}
else {
appModule._environment = {
appCollection: function (name) {
return name;
}
};
}
}
env[key] = appModule.require(val);
env[key] = modelModule.require(models[key]);
}
}
}

View File

@ -627,7 +627,7 @@ exports.installApp = function (name, mount, options) {
}
if (prefix === undefined) {
context.collectionPrefix = mount.replace(/\\/g, "_");
context.collectionPrefix = mount.substr(1).replace(/\//g, "_");
} else {
context.collectionPrefix = prefix;
}