-
Notifications
You must be signed in to change notification settings - Fork 0
/
tlc-template.js
54 lines (47 loc) · 1.2 KB
/
tlc-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
44
45
46
47
48
49
50
51
52
53
54
var cheerio = require('cheerio');
function appendTemplate($tag, $template){
}
function TemplateModule(){
var templates = {};
this.loadTemplates = function(htmlString){
var $ = cheerio.load(htmlString);
$('[id]').each(function(i,e){
templates[$(this).attr('id')] = $.html($(this).removeAttr('id'));
});
}
this.tlcModule = {
translate : function(context){
var data = context.args('data');
//console.dir(data);
if(data){
var templateid = context.args('templateid');
// console.dir(templates);
// console.log(templateid);
// console.log(typeof templates[templateid]);
var r = false;
if(templateid){
var $tag = cheerio.load(templates[templateid]);
//console.log(templates[templateid]);
//$tag.append(templates[templateid]);
// console.log('post append');
r = context.tlc.run($tag,data);
//console.log(r);
var html = cheerio.html($tag);
context.focus(html);
}
// console.dir(tlc);
// var opts = context.opts();
// console.log(opts);
return r;
}
else{
return false;
}
}
}
//console.log(moduleName);
this.templates = function(){
return templates;
}
}
module.exports = TemplateModule