-
Notifications
You must be signed in to change notification settings - Fork 122
/
get-compiled-template.js
45 lines (35 loc) · 1.18 KB
/
get-compiled-template.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'use strict';
var format = require('stringformat');
var request = require('minimal-request');
var settings = require('./settings');
var TryGetCached = require('./try-get-cached');
var requireTemplate = require('./utils/require-template');
module.exports = function(cache){
var tryGetCached = new TryGetCached(cache);
return function(template, useCache, timeout, callback){
var getTemplateFromS3 = function(cb){
request({
url: template.src,
timeout: timeout
}, function(err, templateText){
if(!!err){
return cb({
status: err,
response: {
error: format(settings.connectionError, template.src, templateText)
}
});
}
var type = template.type;
if (type === 'jade') { type = 'oc-template-jade'; }
if (type === 'handlebars') { type = 'oc-template-handlebars'; }
var ocTemplate = requireTemplate(type);
cb(null, ocTemplate.getCompiledTemplate(templateText, template.key));
});
};
if(!!useCache){
return tryGetCached('template', template.key, getTemplateFromS3, callback);
}
return getTemplateFromS3(callback);
};
};