Skip to content

Commit

Permalink
dust.load() accepts a name to load from cache, or a compiled body
Browse files Browse the repository at this point in the history
  • Loading branch information
Seth Kinast committed Apr 14, 2015
1 parent 82dee90 commit c287d5c
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/dust.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@
dust.cache[name] = tmpl;
};

dust.render = function(name, context, callback) {
dust.render = function(nameOrTemplate, context, callback) {
var chunk = new Stub(callback).head;
try {
dust.load(name, chunk, Context.wrap(context, name)).end();
dust.load(nameOrTemplate, chunk, Context.wrap(context, nameOrTemplate)).end();
} catch (err) {
chunk.setError(err);
}
Expand Down Expand Up @@ -136,25 +136,25 @@
};
};

dust.load = function(name, chunk, context) {
var tmpl = dust.cache[name];
dust.load = function(nameOrTemplate, chunk, context) {
var tmpl = nameOrTemplate.__dustBody ? nameOrTemplate : dust.cache[nameOrTemplate];
if (tmpl) {
return tmpl(chunk, context);
} else {
if (dust.onLoad) {
return chunk.map(function(chunk) {
dust.onLoad(name, function(err, src) {
dust.onLoad(nameOrTemplate, function(err, src) {
if (err) {
return chunk.setError(err);
}
if (!dust.cache[name]) {
dust.loadSource(dust.compile(src, name));
if (!dust.cache[nameOrTemplate]) {
dust.loadSource(dust.compile(src, nameOrTemplate));
}
dust.cache[name](chunk, context).end();
dust.cache[nameOrTemplate](chunk, context).end();
});
});
}
return chunk.setError(new Error('Template Not Found: ' + name));
return chunk.setError(new Error('Template Not Found: ' + nameOrTemplate));
}
};

Expand Down

0 comments on commit c287d5c

Please sign in to comment.