mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
template compiling init; changing themes now finally works on this branch
This commit is contained in:
@@ -22,19 +22,19 @@
|
||||
};
|
||||
|
||||
templates.get_custom_map = function(tpl) {
|
||||
if (config['custom_mapping'] && tpl) {
|
||||
for (var pattern in config['custom_mapping']) {
|
||||
if (config.custom_mapping && tpl) {
|
||||
for (var pattern in config.custom_mapping) {
|
||||
if (tpl.match(pattern)) {
|
||||
return (config['custom_mapping'][pattern]);
|
||||
return (config.custom_mapping[pattern]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
templates.is_available = function(tpl) {
|
||||
return $.inArray(tpl, available_templates) !== -1;
|
||||
return $.inArray(tpl + '.tpl', available_templates) !== -1;
|
||||
};
|
||||
|
||||
templates.prepare = function(raw_tpl) {
|
||||
@@ -177,7 +177,7 @@
|
||||
case 'boolean':
|
||||
value = ($(element).val() === 'true' || $(element).val() === '1') ? true : false;
|
||||
break;
|
||||
case 'int': // Intentional fall-through
|
||||
case 'int':
|
||||
case 'integer':
|
||||
value = parseInt($(element).val());
|
||||
break;
|
||||
@@ -252,7 +252,6 @@
|
||||
var template = this.html,
|
||||
regex, block;
|
||||
|
||||
// registering globals
|
||||
for (var g in templates.globals) {
|
||||
if (templates.globals.hasOwnProperty(g)) {
|
||||
data[g] = data[g] || templates.globals[g];
|
||||
@@ -363,7 +362,14 @@
|
||||
module.exports.__express = module.exports.render;
|
||||
|
||||
if ('undefined' !== typeof window) {
|
||||
window.templates = module.exports;a
|
||||
window.templates = module.exports;
|
||||
|
||||
window.onload = function() {
|
||||
$.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];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
})('undefined' === typeof module ? {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
var templates = require('./../../public/src/templates'),
|
||||
translator = require('./../../public/src/translator'),
|
||||
utils = require('./../../public/src/utils'),
|
||||
meta = require('./../meta'),
|
||||
db = require('./../database'),
|
||||
auth = require('./../routes/authentication'),
|
||||
@@ -128,6 +129,42 @@ module.exports = function(app, data) {
|
||||
middleware = require('./middleware')(app);
|
||||
|
||||
app.configure(function() {
|
||||
|
||||
utils.walk(nconf.get('base_templates_path'), function(err, baseTpls) {
|
||||
utils.walk(nconf.get('theme_templates_path'), function (err, themeTpls) {
|
||||
var tpls = [];
|
||||
|
||||
baseTpls = baseTpls.map(function(tpl) {
|
||||
return tpl.replace(nconf.get('base_templates_path'), '');
|
||||
});
|
||||
|
||||
themeTpls = themeTpls.map(function(tpl) {
|
||||
return tpl.replace(nconf.get('theme_templates_path'), '');
|
||||
});
|
||||
|
||||
baseTpls.forEach(function(el, i) {
|
||||
var relative_path = (themeTpls.indexOf(el) !== -1 ? themeTpls[themeTpls.indexOf(el)] : baseTpls[i]),
|
||||
full_path = path.join(themeTpls.indexOf(el) !== -1 ? nconf.get('theme_templates_path') : nconf.get('base_templates_path'), relative_path);
|
||||
|
||||
tpls.push({
|
||||
relative_path: relative_path,
|
||||
path: full_path
|
||||
});
|
||||
});
|
||||
|
||||
async.each(tpls, function(tpl, next) {
|
||||
fs.writeFile(path.join(nconf.get('views_dir'), tpl.relative_path), fs.readFileSync(tpl.path), next);
|
||||
}, function(err) {
|
||||
if (err) {
|
||||
winston.error(err);
|
||||
} else {
|
||||
winston.info('Successfully compiled templates.');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
app.engine('tpl', templates.__express);
|
||||
app.set('view engine', 'tpl');
|
||||
app.set('views', nconf.get('views_dir'));
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
var path = require('path'),
|
||||
async = require('async'),
|
||||
fs = require('fs'),
|
||||
nconf = require('nconf'),
|
||||
|
||||
db = require('./../database'),
|
||||
user = require('./../user'),
|
||||
@@ -22,10 +23,15 @@ module.exports = function(app, middleware, controllers) {
|
||||
app.get('/user/uid/:uid', middleware.checkGlobalPrivacySettings, controllers.accounts.getUserByUID);
|
||||
|
||||
app.get('/get_templates_listing', function (req, res) {
|
||||
utils.walk(path.join(__dirname, '../../', 'public/templates'), function (err, data) {
|
||||
res.json(data.concat(app.get_custom_templates()).filter(function(value, index, self) {
|
||||
utils.walk(nconf.get('views_dir'), function (err, data) {
|
||||
data = data.concat(app.get_custom_templates())
|
||||
.filter(function(value, index, self) {
|
||||
return self.indexOf(value) === index;
|
||||
}));
|
||||
}).map(function(el) {
|
||||
return el.replace(nconf.get('views_dir') + '/', '');
|
||||
});
|
||||
|
||||
res.json(data);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -144,7 +144,7 @@ module.exports = function(app, middleware) {
|
||||
|
||||
app.get_custom_templates = function() {
|
||||
return custom_routes.templates.map(function(tpl) {
|
||||
return tpl.template.split('.tpl')[0];
|
||||
return tpl.template;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user