Baris Soner Usakli 11 years ago
commit 214b74abc9

@ -385,8 +385,11 @@
} else if (data[d] instanceof Object) { } else if (data[d] instanceof Object) {
template = parse(data[d], d + '.', template); template = parse(data[d], d + '.', template);
} else { } else {
checkConditional(namespace + d, data[d]); var key = namespace + d,
checkConditional('!' + namespace + d, !data[d]); value = typeof data[d] === 'string' ? data[d].replace(/^\s+|\s+$/g, '') : data[d];
checkConditional(key, value);
checkConditional('!' + key, !value);
if (blockInfo && blockInfo.iterator) { if (blockInfo && blockInfo.iterator) {
checkConditional('@first', blockInfo.iterator === 0); checkConditional('@first', blockInfo.iterator === 0);
@ -395,7 +398,7 @@
checkConditional('!@last', blockInfo.iterator !== blockInfo.total); checkConditional('!@last', blockInfo.iterator !== blockInfo.total);
} }
template = replace(namespace + d, data[d], template); template = replace(key, value, template);
} }
} }
} }
@ -406,7 +409,8 @@
namespace = ''; namespace = '';
} else { } else {
// clean up all undefined conditionals // clean up all undefined conditionals
template = template.replace(/(<!-- IF([^@]*?)(ELSE -->| -->))|(<!-- ENDIF([^@]*?)-->)/gi, ''); template = template.replace(/<!-- ELSE -->/gi, 'ENDIF -->')
.replace(/<!-- IF([^@]*?)ENDIF([^@]*?)-->/gi, '');
} }
return template; return template;

@ -249,10 +249,10 @@ var fs = require('fs'),
jsPaths = scripts.map(function (jsPath) { jsPaths = scripts.map(function (jsPath) {
if (jsPath.substring(0, 7) === 'plugins') { if (jsPath.substring(0, 7) === 'plugins') {
var paths = jsPath.split('/'), var paths = jsPath.split('/'),
pluginID = paths[1]; mappedPath = paths[1];
jsPath = jsPath.replace(path.join('plugins', pluginID), ''); jsPath = jsPath.replace(path.join('plugins', mappedPath), '');
return path.join(plugins.staticDirs[pluginID], jsPath); return path.join(plugins.staticDirs[mappedPath], jsPath);
} else { } else {
return path.join(__dirname, '..', '/public', jsPath); return path.join(__dirname, '..', '/public', jsPath);
} }

@ -134,16 +134,41 @@ var fs = require('fs'),
}, },
function(next) { function(next) {
// Static Directories for Plugins // Static Directories for Plugins
var realPath,
validMappedPath = /^[\w\-_]+$/;
pluginData.staticDirs = pluginData.staticDirs || {};
// Deprecated, to be removed v0.5
if (pluginData.staticDir) { if (pluginData.staticDir) {
staticDir = path.join(pluginPath, pluginData.staticDir); winston.warn('[plugins/' + pluginData.id + '] staticDir is deprecated, use staticDirs instead');
Plugins.staticDirs[pluginData.id] = path.join(pluginPath, pluginData.staticDir);
}
fs.exists(staticDir, function(exists) { for(key in pluginData.staticDirs) {
if (exists) { (function(mappedPath) {
Plugins.staticDirs[pluginData.id] = staticDir; if (pluginData.staticDirs.hasOwnProperty(mappedPath)) {
next(); if (Plugins.staticDirs[mappedPath]) {
} else next(); winston.warn('[plugins/' + pluginData.id + '] Mapped path (' + mappedPath + ') already specified!');
}); } else if (!validMappedPath.test(mappedPath)) {
} else next(); winston.warn('[plugins/' + pluginData.id + '] Invalid mapped path specified: ' + mappedPath + '. Path must adhere to: ' + validMappedPath.toString());
} else {
realPath = pluginData.staticDirs[mappedPath];
staticDir = path.join(pluginPath, realPath);
(function(staticDir) {
fs.exists(staticDir, function(exists) {
if (exists) {
Plugins.staticDirs[mappedPath] = staticDir;
}
});
}(staticDir));
}
}
}(key));
}
next();
}, },
function(next) { function(next) {
// CSS Files for plugins // CSS Files for plugins
@ -152,9 +177,16 @@ var fs = require('fs'),
winston.info('[plugins] Found ' + pluginData.css.length + ' CSS file(s) for plugin ' + pluginData.id); winston.info('[plugins] Found ' + pluginData.css.length + ' CSS file(s) for plugin ' + pluginData.id);
} }
Plugins.cssFiles = Plugins.cssFiles.concat(pluginData.css.map(function(file) { if (!pluginData.staticDir) {
return path.join('/plugins', pluginData.id, file); Plugins.cssFiles = Plugins.cssFiles.concat(pluginData.css.map(function(file) {
})); return path.join('/plugins', file);
}));
} else {
winston.warn('[plugins/' + pluginData.id + '] staticDir is deprecated, define CSS files with new staticDirs instead.');
Plugins.cssFiles = Plugins.cssFiles.concat(pluginData.css.map(function(file) {
return path.join('/plugins', pluginData.id, file);
}));
}
next(); next();
} else { } else {

@ -31,7 +31,6 @@ var nconf = require('nconf'),
// Static Assets // Static Assets
app.get('/plugins/:id/*', function(req, res) { app.get('/plugins/:id/*', function(req, res) {
var relPath = req._parsedUrl.pathname.replace(nconf.get('relative_path') + '/plugins/' + req.params.id, ''); var relPath = req._parsedUrl.pathname.replace(nconf.get('relative_path') + '/plugins/' + req.params.id, '');
if (plugins.staticDirs[req.params.id]) { if (plugins.staticDirs[req.params.id]) {

Loading…
Cancel
Save