1
0
Fork 0

Fixed Foxx preprocessing

This commit is contained in:
Alan Plum 2015-09-22 14:17:43 +02:00
parent 252cba5e9f
commit f8ef55f437
3 changed files with 12 additions and 18 deletions

View File

@ -125,7 +125,8 @@ function Module(id, parent) {
};
if (parent) {
Object.keys(parent.context).forEach(function (key) {
this.preprocess = parent.preprocess;
Object.keys(parent.context).forEach(function (key) {
if (!hasOwnProperty(this.context, key)) {
this.context[key] = parent.context[key];
}
@ -482,6 +483,9 @@ Module.prototype.require = function(path) {
Module.prototype._compile = function(content, filename) {
// remove shebang
content = content.replace(/^\#\!.*/, '');
if (this.preprocess) {
content = this.preprocess(content);
}
// test for parse errors first and fail early if a parse error detected
if (!internal.parse(content, filename)) {

View File

@ -261,20 +261,6 @@ var installAssets = function (app, routes) {
};
////////////////////////////////////////////////////////////////////////////////
/// @brief returns the transform script
////////////////////////////////////////////////////////////////////////////////
var transformScript = function (file) {
if (/\.coffee$/.test(file)) {
return function (content) {
return preprocess(content, "coffee");
};
}
return preprocess;
};
////////////////////////////////////////////////////////////////////////////////
/// @brief create middleware matchers
////////////////////////////////////////////////////////////////////////////////
@ -668,18 +654,18 @@ var mountController = function (service, routes, mount, filename) {
validateRoute(mount);
// set up a context for the application start function
var tmpContext = {
var appContext = {
prefix: arangodb.normalizeURL(`/${mount}`), // app mount
foxxes: []
};
service.run(filename, {appContext: tmpContext});
service.run(filename, {appContext, preprocess});
// .............................................................................
// routingInfo
// .............................................................................
var foxxes = tmpContext.foxxes;
var foxxes = appContext.foxxes;
for (var i = 0; i < foxxes.length; i++) {
var foxx = foxxes[i];
var ri = foxx.routingInfo;

View File

@ -348,6 +348,10 @@ class FoxxService {
options.appContext
);
if (options.preprocess) {
module.preprocess = options.preprocess;
}
if (options.context) {
Object.keys(options.context).forEach(function (key) {
module.context[key] = options.context[key];