allow recursive base templates

ex. custom theme based off lavender which is based off vanilla
v1.18.x
psychobunny 9 years ago
parent 759b183967
commit da5494fdf1

@ -12,7 +12,8 @@ var mkdirp = require('mkdirp'),
plugins = require('../plugins'),
utils = require('../../public/src/utils'),
Templates = {};
Templates = {},
searchIndex = {};
Templates.compile = function(callback) {
callback = callback || function() {};
@ -27,21 +28,32 @@ Templates.compile = function(callback) {
return callback();
}
var coreTemplatesPath = nconf.get('core_templates_path'),
baseTemplatesPath = nconf.get('base_templates_path'),
viewsPath = nconf.get('views_dir'),
themeTemplatesPath = nconf.get('theme_templates_path'),
themeConfig = require(nconf.get('theme_config'));
compile(callback);
};
if (themeConfig.baseTheme) {
var pathToBaseTheme = path.join(nconf.get('themes_path'), themeConfig.baseTheme);
baseTemplatesPath = require(path.join(pathToBaseTheme, 'theme.json')).templates;
if (!baseTemplatesPath){
baseTemplatesPath = path.join(pathToBaseTheme, 'templates');
}
function getBaseTemplates(theme) {
var baseTemplatesPaths = [],
baseThemePath, baseThemeConfig;
while (theme) {
baseThemePath = path.join(nconf.get('themes_path'), theme);
baseThemeConfig = require(path.join(baseThemePath, 'theme.json'));
baseTemplatesPaths.push(path.join(baseThemePath, baseThemeConfig.templates || 'templates'));
theme = baseThemeConfig.baseTheme;
}
return baseTemplatesPaths.reverse();
}
function compile(callback) {
var coreTemplatesPath = nconf.get('core_templates_path'),
themeConfig = require(nconf.get('theme_config')),
baseTemplatesPaths = themeConfig.baseTheme ? getBaseTemplates(themeConfig.baseTheme) : [nconf.get('base_templates_path')],
viewsPath = nconf.get('views_dir');
plugins.getTemplates(function(err, pluginTemplates) {
if (err) {
return callback(err);
@ -54,27 +66,33 @@ Templates.compile = function(callback) {
coreTpls: function(next) {
utils.walk(coreTemplatesPath, next);
},
baseTpls: function(next) {
utils.walk(baseTemplatesPath, next);
baseThemes: function(next) {
async.map(baseTemplatesPaths, function(baseTemplatePath, next) {
utils.walk(baseTemplatePath, function(err, paths) {
paths = paths.map(function(tpl) {
return {
base: baseTemplatePath,
path: tpl.replace(baseTemplatePath, '')
};
});
next(err, paths);
});
}, next);
}
}, function(err, data) {
var coreTpls = data.coreTpls,
baseTpls = data.baseTpls,
var baseThemes = data.baseThemes,
coreTpls = data.coreTpls,
paths = {};
if (!baseTpls) {
winston.warn('[meta/templates] Could not find base template files at: ' + baseTemplatesPath);
}
coreTpls = !coreTpls ? [] : coreTpls.map(function(tpl) { return tpl.replace(coreTemplatesPath, ''); });
baseTpls = !baseTpls ? [] : baseTpls.map(function(tpl) { return tpl.replace(baseTemplatesPath, ''); });
coreTpls.forEach(function(el, i) {
paths[coreTpls[i]] = path.join(coreTemplatesPath, coreTpls[i]);
paths[coreTpls[i].replace(coreTemplatesPath, '')] = path.join(coreTemplatesPath, coreTpls[i]);
});
baseTpls.forEach(function(el, i) {
paths[baseTpls[i]] = path.join(baseTemplatesPath, baseTpls[i]);
baseThemes.forEach(function(baseTpls) {
baseTpls.forEach(function(el, i) {
paths[baseTpls[i].path] = path.join(baseTpls[i].base, baseTpls[i].path);
});
});
for (var tpl in pluginTemplates) {
@ -125,9 +143,8 @@ Templates.compile = function(callback) {
});
});
});
};
}
var searchIndex = {};
function addIndex(path, file) {
searchIndex[path] = file;

Loading…
Cancel
Save