Skip to content

Commit

Permalink
fix block placeholder in swig layout #737
Browse files Browse the repository at this point in the history
  • Loading branch information
bung87 committed Jun 19, 2017
1 parent a502ee9 commit b589186
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/template/adapters/swig.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
'use strict';

var file = require('utilities').file
, path = require('path')
, fs = require('fs')
, swig = {};

swig = function () {
Expand All @@ -34,21 +36,21 @@
'root' : '/',
'tags' : {},
'extensions' : {},
'tzOffset' : 0
'tzOffset' : 0,
'loader': this.engine.loaders.fs(path.resolve('app/views'))
});

};

swig.prototype.compile = function (template, options) {
// If there is no baseNamePath swig will use the template string as a key. Use a hash as a key instead
if(!options.baseNamePath){
options.baseNamePath = require('crypto').createHash('sha1').update(template).digest('hex');
}
return this.engine.compile(template, {filename: options.baseNamePath});

};

swig.prototype.render = function (data, fn) {
return fn(data);
var template = fs.readFileSync(path.resolve(data.template + ".html.swig"),'utf-8');
var baseNamePath = require('crypto').createHash('sha1').update(template).digest('hex');
var t = this.engine.compile(template, {filename: baseNamePath});
return t(data);
};

module.exports = swig;
Expand Down

0 comments on commit b589186

Please sign in to comment.