-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglue.js
30 lines (27 loc) · 843 Bytes
/
glue.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
var glue = {
templates: {},
views: {},
fetchTemplate: function(template, success){
$.get('/mustaches/'+template+'.html.mustache', null, function(mustache){
glue.templates[template]=mustache;
if(success !== null) {success(template);}
});
},
fetchView: function(view_path, success) {
$.getJSON(view_path, function(view){
glue.views[view_path] = view;
if(success !== null) { success(view);}
});
},
renderMustache: function(template, view_path, success){
var html = $.mustache(glue.templates[template], glue.views[view_path]);
success(html);
},
render: function(template, view_path, success){
glue.fetchTemplate(template, function(){
glue.fetchView(view_path, function(){
glue.renderMustache(template, view_path, success);
});
});
}
};