deprecated templates.ready, templates.init, templates.loadServer; start webserver immediately without having to wait for templates.js

v1.18.x
psychobunny 11 years ago
parent d471ea2d5b
commit 68d526b762

@ -134,14 +134,11 @@ function start() {
plugins.init();
translator.loadServer();
var customTemplates = meta.config['theme:templates'] ? path.join(nconf.get('themes_path'), meta.config['theme:id'], meta.config['theme:templates']) : false;
utils.walk(path.join(__dirname, 'public/templates'), function (err, tplsToLoad) {
templates.init(tplsToLoad, customTemplates);
});
nconf.set('base_templates_path', path.join(nconf.get('themes_path'), 'nodebb-theme-vanilla/templates'));
nconf.set('theme_templates_path', meta.config['theme:templates'] ? path.join(nconf.get('themes_path'), meta.config['theme:id'], meta.config['theme:templates']) : nconf.get('base_templates_path'));
plugins.ready(function() {
templates.ready(webserver.init);
webserver.init();
});
notifications.init();

@ -37,22 +37,6 @@
return $.inArray(tpl, available_templates) !== -1;
};
templates.ready = function (callback) {
if (callback == null) {
if (this.ready_callback) {
this.ready_callback();
} else {
this.loaded = true;
}
} else {
if (this.loaded == true) {
callback();
} else {
this.ready_callback = callback;
}
}
};
templates.prepare = function (raw_tpl) {
var template = {};
template.html = raw_tpl;
@ -63,74 +47,13 @@
};
function loadTemplates(templatesToLoad, customTemplateDir) {
function loadServer() {
return templates.ready();
var loaded = templatesToLoad.length,
templatesPath = __dirname + '/../templates';
function getTemplates(directory) {
for (var t in templatesToLoad) {
(function (file) {
function loadFile(html) {
var template = function () {
this.toString = function () {
return this.html;
};
}
template.prototype.file = file;
template.prototype.parse = parse;
template.prototype.html = String(html);
templates[file] = new template;
loaded--;
if (loaded === 0) {
templates.ready();
}
}
fs.readFile(directory + '/' + file + '.tpl', function (err, html) {
if (err && directory !== templatesPath) {
fs.readFile(templatesPath + '/' + file + '.tpl', function (err, html) {
loadFile(html);
});
} else {
loadFile(html);
}
});
}(templatesToLoad[t]));
}
}
if (customTemplateDir) {
fs.exists(customTemplateDir, function (exists) {
var directory = (exists ? customTemplateDir : templatesPath);
getTemplates(directory);
});
} else {
getTemplates(templatesPath);
}
}
function loadClient() {
$.when($.getJSON(RELATIVE_PATH + '/templates/config.json'), $.getJSON(RELATIVE_PATH + '/api/get_templates_listing')).done(function (config_data, templates_data) {
config = config_data[0];
available_templates = templates_data[0];
templates.ready();
});
}
if (fs === null) loadClient();
else loadServer();
$.when($.getJSON(RELATIVE_PATH + '/templates/config.json'), $.getJSON(RELATIVE_PATH + '/api/get_templates_listing')).done(function (config_data, templates_data) {
config = config_data[0];
available_templates = templates_data[0];
templates.ready();
});
}
templates.init = function (templates_to_load, custom_templates) {
loadTemplates(templates_to_load || [], custom_templates || false);
};
templates.render = function(filename, options, fn) {
if ('function' === typeof options) {
fn = options, options = false;

Loading…
Cancel
Save