Node.js based forum software built for the modern web
allow express to serve parsed tpls via res.render
psychobunnyaee2b2ecd098
diff --git a/public/src/templates.js b/public/src/templates.jsindex 243bc59d68..2ac8f0b7fb 100644--- a/public/src/templates.js+++ b/public/src/templates.js@@ -3,6 +3,7 @@var config = {},templates,fs = null,+ path = null,available_templates = [],parsed_variables = {},apiXHR;@@ -12,7 +13,8 @@};try {- fs = require('fs');+ fs = require('fs'),+ path = require('path');} catch (e) {}templates.force_refresh = function (tpl) {@@ -127,6 +129,27 @@loadTemplates(templates_to_load || [], custom_templates || false);}+ templates.render = function(filename, options, fn) {+ if ('function' === typeof options) {+ fn = options, options = false;+ }++ var tpl = filename+ .replace(path.join(__dirname + '/../templates/'), '')+ .replace('.' + options.settings['view engine'], '');++ if (!templates[tpl]) {+ fs.readFile(filename, function (err, html) {+ templates[tpl] = html.toString();+ templates.prepare(templates[tpl]);++ return fn(err, templates[tpl].parse(options));+ });+ } else {+ return fn(null, templates[tpl].parse(options));+ }+ }+templates.getTemplateNameFromUrl = function (url) {var parts = url.split('?')[0].split('/');@@ -419,6 +442,8 @@})(data, "", template);}+ module.exports.__express = module.exports.render;+if ('undefined' !== typeof window) {window.templates = module.exports;templates.init();diff --git a/src/webserver.js b/src/webserver.jsindex 9999c1a22e..530f434105 100644--- a/src/webserver.js+++ b/src/webserver.js@@ -226,6 +226,10 @@ process.on('uncaughtException', function(err) {// Middlewaresapp.configure(function() {+ app.engine('tpl', templates.__express);+ app.set('view engine', 'tpl');+ app.set('views', path.join(__dirname, '../public/templates'));+async.series([function(next) {// Pre-router middlewares