Skip to content

Commit

Permalink
Adding template.load() on jails for external templates
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduardo Ottaviani authored and Eduardo Ottaviani committed Apr 4, 2015
1 parent 93569e4 commit d563893
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
29 changes: 27 additions & 2 deletions source/jails.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
define(function(){

var
Jails, config, $, global = {}, publisher, slice, order;
Jails, config, $, global = {}, publisher, slice;

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

Jails = {

Expand Down Expand Up @@ -361,6 +360,28 @@ define(function(){
this.templates = {};
this.filters = {};

this.template = {

promises:{},

load :function(url, name){

var p, template, t, l;
name = name || filename(url);
template = Jails.templates;
t = template[name];
pm = this.promises[name];

if(t) return t;
if(pm) return pm;

l = $.get(url).done(function(tpl){ template[name] = tpl; });
this.promises[name] = l;

return l;
}
};

this.controller = function(name, method){
return create.call(this, 'controller', name, method);
};
Expand Down Expand Up @@ -453,6 +474,10 @@ define(function(){
}));
}

function filename(url){
return url.split(/\//).pop().split(/\./).shift();
}

Interface._class.apply( Jails );
return Jails;

Expand Down
2 changes: 1 addition & 1 deletion source/jails.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d563893

Please sign in to comment.