From c287d5cb2e9cd566c074e00c078c3db8f2db2246 Mon Sep 17 00:00:00 2001 From: Seth Kinast Date: Wed, 1 Apr 2015 14:02:09 -0700 Subject: [PATCH] dust.load() accepts a name to load from cache, or a compiled body --- lib/dust.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/dust.js b/lib/dust.js index 87ce9397..70c8f8f1 100644 --- a/lib/dust.js +++ b/lib/dust.js @@ -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); } @@ -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)); } };