techy
Version:
Flat CMS based on Gulp and AbsurdJS
35 lines • 1.18 kB
JavaScript
var fs = require('fs');
var absurd = require('absurd')();
module.exports = function(file, data) {
file = file.indexOf('.html') > 0 || file.indexOf('.md') > 0 || file.indexOf('.markdown') > 0 ? file : file + '.html';
var process = function(template) {
var ext = template.split('.').pop().toLowerCase();
if(ext == 'md' || ext == 'markdown') {
data = data || {};
data.paths = this.get('paths');
if(this.parseMarkdownFile) {
return this.parseMarkdownFile({
path: template
}, null, true, data);
}
return '';
} else {
template = fs.readFileSync(template).toString();
var result = '';
absurd.flush().morph('html').add(template).compile(function(err, html) {
result = html;
}, data);
return result;
}
}.bind(this);
var src = this.get('src');
if(fs.existsSync(this.root + '/_tpl/' + file)) {
return process(this.root + '/_tpl/' + file);
} else if(fs.existsSync(this.root + '/' + file)) {
return process(this.root + '/' + file);
} else if(src && fs.existsSync(src + '/' + file)) {
return process(src + '/' + file);
} else {
throw new Error('There is no \'' + file + '\' in \'' + this.root + '/_tpl/\' directory.');
}
}