widget-loader
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -15,7 +15,5 @@ "use strict"; | ||
var App = opts.App; | ||
var AppCMS = opts.App; | ||
var widgetDir = opts.widgetDir; | ||
var SlimAppCopy = App.widgetAPI(); | ||
// Load apps through a psuedo sandbox | ||
@@ -25,7 +23,7 @@ function loadWidget(widgetPath) { | ||
var sandbox = new WidgetSandbox(opts); | ||
return sandbox.loadWidget(widgetPath); | ||
} | ||
function getWidget(name) { | ||
@@ -35,3 +33,3 @@ // Grab the app class to instantiate | ||
var app; | ||
// Check for an actual class, otherwise just use whatever was returned | ||
@@ -43,18 +41,18 @@ if (_.isFunction(AppClass)) { | ||
} | ||
return app; | ||
} | ||
function getTemplate(widgetName) { | ||
var templatePath = path.join(widgetDir, widgetName, 'template.hbs'); | ||
return fs.readFileSync(templatePath, 'utf8'); | ||
} | ||
// loop through the widgets directory and load widgets with templates | ||
function buildWidgets() { | ||
var currentWidget; | ||
function build(widgetName) { | ||
@@ -69,3 +67,3 @@ fs.lstat(path.join(widgetDir, widgetName), function(err, stat) { | ||
} | ||
// loops through the widgets directory | ||
@@ -76,26 +74,26 @@ fs.readdir(widgetDir, function(err, widgets) { | ||
} | ||
function matchPaths(urlPath, widgetPath) { | ||
if (urlPath === widgetPath) { | ||
return true; | ||
} | ||
var urlArr = urlPath.split('/'); | ||
var widgetArr = widgetPath.split('/'); | ||
var isMatch = false; | ||
if (urlArr.length !== widgetArr.length) { | ||
return false; | ||
} | ||
if (widgetArr[widgetArr.length - 1] === ':any') { | ||
widgetArr[widgetArr.length - 1] = urlArr[urlArr.length - 1]; | ||
} | ||
return urlArr.join('') === widgetArr.join(''); | ||
} | ||
function matchRoute(routes, page) { | ||
@@ -105,9 +103,9 @@ if (routes.length === 0 || routes.indexOf(page) > -1) { | ||
} | ||
var isMatch = false; | ||
var i; | ||
for (i = 0; i < routes.length; i++) { | ||
isMatch = matchPaths(page, routes[i]); | ||
if (isMatch) { | ||
@@ -117,10 +115,10 @@ break; | ||
} | ||
return isMatch; | ||
} | ||
function sortWidgets (widgetCollection) { | ||
var widgetPositions = _.keys(widgetCollection); | ||
_.each(widgetPositions, function (key) { | ||
@@ -131,7 +129,7 @@ widgetCollection[key].sort(function (obj1, obj2) { | ||
}); | ||
return widgetCollection; | ||
} | ||
// load widgets before any requests can come | ||
@@ -157,3 +155,3 @@ buildWidgets(); | ||
return function () { | ||
return widget.exec(SlimAppCopy) | ||
return widget.exec(AppCMS) | ||
.then(function (collection) { | ||
@@ -202,2 +200,1 @@ | ||
}; | ||
{ | ||
"name": "widget-loader", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Widget loader for WidGet CMS", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
NPM Shrinkwrap
Supply chain riskPackage contains a shrinkwrap file. This may allow the package to bypass normal install procedures.
Found 1 instance in 1 package
0
9222
9
196