Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

carbon-framework

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

carbon-framework - npm Package Compare versions

Comparing version 0.1.21 to 0.1.22

179

lib/index.js

@@ -472,2 +472,4 @@ var async = require("async");

var traversedControllers = [];
_.forEach(routes, function(route, routeName) {

@@ -480,73 +482,45 @@ var modulePath = _options.paths.base + "/" + _.map(route.module.split(":"), function(module) {

var controller = require(controllerPath);
var controllerBody = controller();
var resourceId = controller.resourceId;
var actionName = changeCase.camelCase(route.action) + "Action";
if (controllerBody[actionName])
if (traversedControllers.indexOf(controllerPath) == -1)
{
var setupRoute = function(req, res, next) {
var routeName = _.findKey(app.Router.getRoutes(), function(route) {
return (route.route == req.route.path);
});
traversedControllers.push(controllerPath);
req.currentRoute = app.Router.getRoute(routeName);
var controller = require(controllerPath);
var controllerBody = controller();
var resourceId = controller.resourceId;
var actionName = changeCase.camelCase(route.action) + "Action";
if (req.currentRoute)
{
req.currentRoute.name = routeName;
req.currentRoute.params = req.params;
}
if (controllerBody[actionName])
{
var setupRoute = function(req, res, next) {
var routeName = _.findKey(app.Router.getRoutes(), function(route) {
return (route.route == req.route.path);
});
next();
};
req.currentRoute = app.Router.getRoute(routeName);
/**
* Setup helper paths based on current request
*/
var initHelperPaths = function(req, res, next) {
var helperPath = modulePath + "/helpers";
if (req.currentRoute)
{
req.currentRoute.name = routeName;
req.currentRoute.params = req.params;
}
if (_utils.filesystem.isFile(modulePath))
helperPath = helperPath.replace("/" + name, "");
next();
};
var helpersPath = [_options.paths.base + "/helpers"];
/**
* Setup helper paths based on current request
*/
var initHelperPaths = function(req, res, next) {
var helperPath = modulePath + "/helpers";
var helpers = helpersPath.slice();
if (_utils.filesystem.isFile(modulePath))
helperPath = helperPath.replace("/" + name, "");
var regex = /(\/modules\/\w+)/g;
var parts = helperPath.match(/(\/modules\/[a-zA-Z0-9-_.]+)/g);
var path = helperPath.replace(/(\/modules\/[a-zA-Z0-9-_.]+)+/g, "%placeholder%");
var helpersPath = [_options.paths.base + "/helpers"];
for (var i = 1; i <= parts.length; i++)
{
var part = parts.slice(0, i).join("");
helpers.unshift(path.replace("%placeholder%", part));
}
var helpers = helpersPath.slice();
for (i = 0; i < helpers.length; i++)
{
if (_utils.filesystem.isDirectory(helpers[i]))
_utils.loadHelpers(helpers[i], req, res);
}
next();
};
/**
* Setup view paths based on current request
*/
var initViewPaths = function(req, res, next) {
var viewPath = modulePath + "/views";
if (_utils.filesystem.isFile(modulePath))
viewPath = viewPath.replace("/" + name, "");
if (_utils.filesystem.isDirectory(viewPath))
{
var views = app.express.get("views").slice();
var regex = /(\/modules\/\w+)/g;
var parts = viewPath.match(/(\/modules\/[a-zA-Z0-9-_.]+)/g);
var path = viewPath.replace(/(\/modules\/[a-zA-Z0-9-_.]+)+/g, "%placeholder%");
var parts = helperPath.match(/(\/modules\/[a-zA-Z0-9-_.]+)/g);
var path = helperPath.replace(/(\/modules\/[a-zA-Z0-9-_.]+)+/g, "%placeholder%");

@@ -556,43 +530,76 @@ for (var i = 1; i <= parts.length; i++)

var part = parts.slice(0, i).join("");
views.unshift(path.replace("%placeholder%", part));
helpers.unshift(path.replace("%placeholder%", part));
}
res.viewPaths = views;
}
for (i = 0; i < helpers.length; i++)
{
if (_utils.filesystem.isDirectory(helpers[i]))
_utils.loadHelpers(helpers[i], req, res);
}
next();
};
next();
};
var initFunction = controllerBody[actionName].init;
var initAction = null;
/**
* Setup view paths based on current request
*/
var initViewPaths = function(req, res, next) {
var viewPath = modulePath + "/views";
if (_.isFunction(initFunction))
{
delete controllerBody[actionName].init;
if (_utils.filesystem.isFile(modulePath))
viewPath = viewPath.replace("/" + name, "");
initAction = function(req, res, next) {
if (initFunction.length == 2)
if (_utils.filesystem.isDirectory(viewPath))
{
initFunction(req, res);
next();
var views = app.express.get("views").slice();
var regex = /(\/modules\/\w+)/g;
var parts = viewPath.match(/(\/modules\/[a-zA-Z0-9-_.]+)/g);
var path = viewPath.replace(/(\/modules\/[a-zA-Z0-9-_.]+)+/g, "%placeholder%");
for (var i = 1; i <= parts.length; i++)
{
var part = parts.slice(0, i).join("");
views.unshift(path.replace("%placeholder%", part));
}
res.viewPaths = views;
}
else
initFunction(req, res, next);
next();
};
}
_.each(controllerBody[actionName], function(action, method) {
var args = [route.route, setupRoute, initViewPaths, initHelperPaths];
var initFunction = controllerBody[actionName].init;
var initAction = null;
_.each(app.hooks.preAction, function(preAction) {
args.push(preAction);
});
if (_.isFunction(initFunction))
{
delete controllerBody[actionName].init;
if (initAction)
args.push(initAction);
initAction = function(req, res, next) {
if (initFunction.length == 2)
{
initFunction(req, res);
next();
}
else
initFunction(req, res, next);
};
}
args.push(action);
_.each(controllerBody[actionName], function(action, method) {
var args = [route.route, setupRoute, initViewPaths, initHelperPaths];
app.express[method].apply(app.express, args);
});
_.each(app.hooks.preAction, function(preAction) {
args.push(preAction);
});
if (initAction)
args.push(initAction);
args.push(action);
app.express[method].apply(app.express, args);
});
}
}

@@ -599,0 +606,0 @@ });

{
"name": "carbon-framework",
"version": "0.1.21",
"version": "0.1.22",
"description": " Modular MVC framework for Node.js based on Zend Framework ",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/carbonjs/carbon-framework",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc