Skip to content

Commit d563893

Browse files
Eduardo OttavianiEduardo Ottaviani
authored andcommitted
Adding template.load() on jails for external templates
1 parent 93569e4 commit d563893

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

source/jails.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
define(function(){
22

33
var
4-
Jails, config, $, global = {}, publisher, slice, order;
4+
Jails, config, $, global = {}, publisher, slice;
55

66
slice = Array.prototype.slice;
7-
order = { partial :0, component:1, controller :2, app :3 };
87

98
Jails = {
109

@@ -361,6 +360,28 @@ define(function(){
361360
this.templates = {};
362361
this.filters = {};
363362

363+
this.template = {
364+
365+
promises:{},
366+
367+
load :function(url, name){
368+
369+
var p, template, t, l;
370+
name = name || filename(url);
371+
template = Jails.templates;
372+
t = template[name];
373+
pm = this.promises[name];
374+
375+
if(t) return t;
376+
if(pm) return pm;
377+
378+
l = $.get(url).done(function(tpl){ template[name] = tpl; });
379+
this.promises[name] = l;
380+
381+
return l;
382+
}
383+
};
384+
364385
this.controller = function(name, method){
365386
return create.call(this, 'controller', name, method);
366387
};
@@ -453,6 +474,10 @@ define(function(){
453474
}));
454475
}
455476

477+
function filename(url){
478+
return url.split(/\//).pop().split(/\./).shift();
479+
}
480+
456481
Interface._class.apply( Jails );
457482
return Jails;
458483

source/jails.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)