Merge branch 'master' of github.com:designcreateplay/NodeBB

v1.18.x
Julian Lam 11 years ago
commit 5d7f38f99f

@ -96,6 +96,8 @@
global.translator = translator;
translator.loadServer();
var customTemplates = meta.config['theme:templates'] ? path.join(__dirname, 'node_modules', meta.config['theme:id'], meta.config['theme:templates']) : false;
// todo: replace below with read directory code, derp.
templates.init([
@ -104,7 +106,8 @@
'emails/header', 'emails/footer',
'noscript/header', 'noscript/home', 'noscript/category', 'noscript/topic'
]);
], customTemplates);
templates.ready(webserver.init);

@ -59,6 +59,7 @@ define(function() {
topicsListEl.innerHTML += html;
btnEl.innerHTML = 'Load More Topics';
$('span.timeago').timeago();
} else {
// Exhausted all topics
btnEl.className += ' disabled';

@ -57,30 +57,41 @@
return template;
};
function loadTemplates(templatesToLoad) {
function loadTemplates(templatesToLoad, customTemplateDir) {
function loadServer() {
var loaded = templatesToLoad.length;
for (var t in templatesToLoad) {
(function (file) {
fs.readFile(__dirname + '/../templates/' + file + '.tpl', function (err, html) {
var template = function () {
this.toString = function () {
return this.html;
};
}
template.prototype.file = file;
template.prototype.parse = parse;
template.prototype.html = String(html);
global.templates[file] = new template;
loaded--;
if (loaded == 0) templates.ready();
});
}(templatesToLoad[t]));
function getTemplates(directory) {
for (var t in templatesToLoad) {
(function (file) {
fs.readFile(directory + '/' + file + '.tpl', function (err, html) {
var template = function () {
this.toString = function () {
return this.html;
};
}
template.prototype.file = file;
template.prototype.parse = parse;
template.prototype.html = String(html);
global.templates[file] = new template;
loaded--;
if (loaded == 0) templates.ready();
});
}(templatesToLoad[t]));
}
}
if (customTemplateDir) {
fs.exists(customTemplateDir, function (exists) {
var directory = (exists ? customTemplateDir : __dirname + '/../templates');
getTemplates(directory);
});
} else {
getTemplates(__dirname + '/../templates');
}
}
function loadClient() {
@ -96,8 +107,8 @@
}
templates.init = function (templates_to_load) {
loadTemplates(templates_to_load || []);
templates.init = function (templates_to_load, custom_templates) {
loadTemplates(templates_to_load || [], custom_templates || false);
}
templates.getTemplateNameFromUrl = function (url) {
@ -227,6 +238,10 @@
return new RegExp("<!-- BEGIN " + block + " -->[\\s\\S]*<!-- END " + block + " -->", 'g');
}
function makeConditionalRegex(block) {
return new RegExp("<!-- IF " + block + " -->[\\s\\S]*<!-- ENDIF " + block + " -->", 'g');
}
function getBlock(regex, block, template) {
data = template.match(regex);
if (data == null) return;
@ -240,6 +255,19 @@
return data;
}
function getConditionalBlock(regex, block, template) {
data = template.match(regex);
if (data == null) return;
if (self.blocks && block !== undefined) self.blocks[block] = data[0];
data = data[0]
.replace("<!-- IF " + block + " -->", "")
.replace("<!-- ENDIF " + block + " -->", "");
return data;
}
function setBlock(regex, block, template) {
return template.replace(regex, block);
}
@ -289,6 +317,14 @@
block = parse(data[d], namespace, block);
template = setBlock(regex, block, template);
} else {
var conditional = makeConditionalRegex(d),
block = getConditionalBlock(conditional, namespace, template);
if (block && !data[d]) {
template = template.replace(conditional, '');
}
template = replace(namespace + d, data[d], template);
}
}

@ -11,7 +11,7 @@
</div>
<a target="_blank" href="{relative_path}/topic/{topics.slug}">{topics.title}</a>
<ul>
<li><i class="icon-time"></i> Posted {topics.relativeTime} ago by {topics.username}</li>
<li><i class="icon-time"></i> Posted <span class="timeago" title="{topics.relativeTime}"></span> by {topics.username}</li>
<li><i class="icon-comments"></i> {topics.postcount} post(s)</li>
</ul>
<div class="clear"></div>

@ -130,9 +130,8 @@ var utils = require('./../public/src/utils.js'),
});
},
function(config, next) {
if (config.staticDir) {
themeData['theme:staticDir'] = config.staticDir;
}
themeData['theme:staticDir'] = config.staticDir ? config.staticDir : '';
themeData['theme:templates'] = config.templates ? config.templates : '';
RDB.hmset('config', themeData, next);
}

@ -22,8 +22,12 @@ var RDB = require('./redis.js'),
Topics.getTopicData = function(tid, callback) {
RDB.hgetall('topic:' + tid, function(err, data) {
if (err === null) {
if(data)
if(data) {
data.title = validator.sanitize(data.title).escape();
if(data.timestamp) {
data.relativeTime = new Date(parseInt(data.timestamp, 10)).toISOString();
}
}
callback(data);
} else {
@ -327,8 +331,6 @@ var RDB = require('./redis.js'),
topicData['lock-icon'] = topicData.locked === '1' ? 'icon-lock' : 'none';
topicData['deleted-class'] = topicData.deleted === '1' ? 'deleted' : '';
topicData.relativeTime = new Date(parseInt(topicData.timestamp, 10)).toISOString();
topicData.username = topicInfo.username;
topicData.badgeclass = (topicInfo.hasread && current_user != 0) ? '' : 'badge-important';
topicData.teaser_text = topicInfo.teaserInfo.text || '',
@ -455,7 +457,6 @@ var RDB = require('./redis.js'),
hasRead = results[1],
teaser = results[2];
topicData.relativeTime = new Date(parseInt(topicData.timestamp,10)).toISOString();
topicData.badgeclass = hasRead ? '' : 'badge-important';
topicData.teaser_text = teaser.text || '';
topicData.teaser_username = teaser.username || '';

@ -74,6 +74,7 @@ var express = require('express'),
cssSrc: meta.config['theme:src'] || nconf.get('relative_path') + '/vendor/bootstrap/css/bootstrap.min.css',
pluginCSS: plugins.cssFiles.map(function(file) { return { path: file } }),
title: meta.config.title || '',
description: meta.config.description || '',
'brand:logo': meta.config['brand:logo'] || '',
'brand:logo:display': meta.config['brand:logo']?'':'hide',
browserTitle: meta.config.title || 'NodeBB',
@ -165,7 +166,7 @@ var express = require('express'),
},
function(next) {
// Theme configuration
RDB.hmget('config', 'theme:type', 'theme:id', 'theme:staticDir', function(err, themeData) {
RDB.hmget('config', 'theme:type', 'theme:id', 'theme:staticDir', 'theme:templates', function(err, themeData) {
var themeId = (themeData[1] || 'nodebb-theme-vanilla');
// Detect if a theme has been selected, and handle appropriately
@ -183,6 +184,13 @@ var express = require('express'),
}
}
if (themeData[3]) {
app.use('/templates', express.static(path.join(__dirname, '../node_modules', themeData[1], themeData[3])));
if (process.env.NODE_ENV === 'development') {
winston.info('Custom templates directory routed for theme: ' + themeData[1]);
}
}
app.use(require('less-middleware')({
src: path.join(__dirname, '../node_modules/' + themeId),
dest: path.join(__dirname, '../public/css'),

Loading…
Cancel
Save