Skip to content

Commit

Permalink
Release v2.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Seth Kinast committed Apr 30, 2015
1 parent 325f4a9 commit 162006a
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 97 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
## Change Log

### v2.7.1 (2015/04/30 20:32 +00:00)
- [#655](https://github.com/linkedin/dustjs/pull/655) Update CommonJS example to make use of new onLoad behavior (@sethkinast)
- [#653](https://github.com/linkedin/dustjs/pull/653) Fix array iteration when context is undefined (@sethkinast)
- [#641](https://github.com/linkedin/dustjs/pull/641) Add a `cb(null, compiledTemplate)` signature to `dust.onLoad` Calling the `onLoad` callback with a compiled template function will use this template to satisfy the load request. The template is not automatically registered under any name when passed to the callback, so the `onLoad` function should handle registration as it needs. `dust.cache` behavior has been changed slightly. Before, setting it to false would blow away the entire cache on every render. Now, setting it to false just prevents new templates from being added and cached templates from being used, but if it's set to true again previously-cached templates will be ready to use. (@sethkinast)
- [#650](https://github.com/linkedin/dustjs/pull/650) Pin jasmine@2.2.x for grunt-jasmine-nodejs (@sethkinast)
- [#646](https://github.com/linkedin/dustjs/pull/646) Update AMD and CommonJS examples (@sethkinast)
- [#637](https://github.com/linkedin/dustjs/pull/637) CommonJS example (@sethkinast)
- [#638](https://github.com/linkedin/dustjs/pull/638) Preserve compiler backwards compatibility with pre-2.7 versions (@sethkinast)
- [#639](https://github.com/linkedin/dustjs/pull/639) Fix failing test on Windows (@sethkinast)

### v2.7.0 (2015/04/17 23:23 +00:00)
- [#636](https://github.com/linkedin/dustjs/pull/636) Fix failing tests in IE8 (@sethkinast)
- [#633](https://github.com/linkedin/dustjs/pull/633) Drop Node 0.8 (@sethkinast)
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dustjs-linkedin",
"version": "2.7.0",
"version": "2.7.1",
"homepage": "https://github.com/linkedin/dustjs",
"authors": [
"Veena Basavaraj <vybs@users.noreply.github.com>",
Expand Down
123 changes: 79 additions & 44 deletions dist/dust-core.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! dustjs-linkedin - v2.7.0
/*! dustjs-linkedin - v2.7.1
* http://dustjs.com/
* Copyright (c) 2015 Aleksander Williams; Released under the MIT License */
(function (root, factory) {
Expand All @@ -12,7 +12,7 @@
}
}(this, function() {
var dust = {
"version": "2.7.0"
"version": "2.7.1"
},
NONE = 'NONE', ERROR = 'ERROR', WARN = 'WARN', INFO = 'INFO', DEBUG = 'DEBUG',
EMPTY_FUNC = function() {};
Expand Down Expand Up @@ -90,7 +90,9 @@
return;
}
tmpl.templateName = name;
dust.cache[name] = tmpl;
if (dust.config.cache !== false) {
dust.cache[name] = tmpl;
}
};

dust.render = function(nameOrTemplate, context, callback) {
Expand All @@ -115,41 +117,74 @@
return stream;
};

function load(nameOrTemplate, chunk, context) {
/**
* Extracts a template function (body_0) from whatever is passed.
* @param nameOrTemplate {*} Could be:
* - the name of a template to load from cache
* - a CommonJS-compiled template (a function with a `template` property)
* - a template function
* @param loadFromCache {Boolean} if false, don't look in the cache
* @return {Function} a template function, if found
*/
function getTemplate(nameOrTemplate, loadFromCache/*=true*/) {
if(!nameOrTemplate) {
return chunk.setError(new Error('No template or template name provided to render'));
}

if(!dust.config.cache) {
dust.cache = {};
return;
}

var tmpl;
if(typeof nameOrTemplate === 'function' && nameOrTemplate.template) {
// Sugar away CommonJS module templates
tmpl = nameOrTemplate.template;
} else if(dust.isTemplateFn(nameOrTemplate)) {
return nameOrTemplate.template;
}
if(dust.isTemplateFn(nameOrTemplate)) {
// Template functions passed directly
tmpl = nameOrTemplate;
} else {
// Load a template with this name from cache
tmpl = dust.cache[nameOrTemplate];
return nameOrTemplate;
}
if(loadFromCache !== false) {
// Try loading a template with this name from cache
return dust.cache[nameOrTemplate];
}
}

if (tmpl) {
return tmpl(chunk, Context.wrap(context, tmpl.templateName));
function load(nameOrTemplate, chunk, context) {
if(!nameOrTemplate) {
return chunk.setError(new Error('No template or template name provided to render'));
}

var template = getTemplate(nameOrTemplate, dust.config.cache);

if (template) {
return template(chunk, Context.wrap(context, template.templateName));
} else {
if (dust.onLoad) {
return chunk.map(function(chunk) {
dust.onLoad(nameOrTemplate, function(err, src) {
// Alias just so it's easier to read that this would always be a name
var name = nameOrTemplate;
// Three possible scenarios for a successful callback:
// - `require(nameOrTemplate)(dust); cb()`
// - `src = readFile('src.dust'); cb(null, src)`
// - `compiledTemplate = require(nameOrTemplate)(dust); cb(null, compiledTemplate)`
function done(err, srcOrTemplate) {
var template;
if (err) {
return chunk.setError(err);
}
if (!dust.cache[nameOrTemplate]) {
dust.loadSource(dust.compile(src, nameOrTemplate));
// Prefer a template that is passed via callback over the cached version.
template = getTemplate(srcOrTemplate, false) || getTemplate(name, dust.config.cache);
if (!template) {
// It's a template string, compile it and register under `name`
if(dust.compile) {
template = dust.loadSource(dust.compile(srcOrTemplate, name));
} else {
return chunk.setError(new Error('Dust compiler not available'));
}
}
dust.cache[nameOrTemplate](chunk, Context.wrap(context, nameOrTemplate)).end();
});
template(chunk, Context.wrap(context, template.templateName)).end();
}

if(dust.onLoad.length === 3) {
dust.onLoad(name, context.options, done);
} else {
dust.onLoad(name, done);
}
});
}
return chunk.setError(new Error('Template Not Found: ' + nameOrTemplate));
Expand Down Expand Up @@ -273,18 +308,19 @@
}
};

function Context(stack, global, blocks, templateName) {
function Context(stack, global, options, blocks, templateName) {
if(stack !== undefined && !(stack instanceof Stack)) {
stack = new Stack(stack);
}
this.stack = stack;
this.global = global;
this.options = options;
this.blocks = blocks;
this.templateName = templateName;
}

dust.makeBase = function(global) {
return new Context(undefined, global);
dust.makeBase = dust.context = function(global, options) {
return new Context(undefined, global, options);
};

/**
Expand All @@ -303,7 +339,7 @@
if (context instanceof Context) {
return context;
}
return new Context(context, {}, null, name);
return new Context(context, {}, {}, null, name);
};

/**
Expand Down Expand Up @@ -429,7 +465,7 @@
};

Context.prototype.rebase = function(head) {
return new Context(head, this.global, this.blocks, this.getTemplateName());
return new Context(head, this.global, this.options, this.blocks, this.getTemplateName());
};

Context.prototype.clone = function() {
Expand Down Expand Up @@ -478,7 +514,7 @@
} else {
newBlocks = blocks.concat([locals]);
}
return new Context(this.stack, this.global, newBlocks, this.getTemplateName());
return new Context(this.stack, this.global, this.options, newBlocks, this.getTemplateName());
}
return this;
};
Expand Down Expand Up @@ -731,7 +767,7 @@
var body = bodies.block,
skip = bodies['else'],
chunk = this,
i, len;
i, len, head;

if (typeof elem === 'function' && !dust.isTemplateFn(elem)) {
try {
Expand Down Expand Up @@ -760,23 +796,16 @@
if (body) {
len = elem.length;
if (len > 0) {
// any custom helper can blow up the stack and store a flattened context, guard defensively
if(context.stack.head) {
context.stack.head.$len = len;
}
head = context.stack && context.stack.head || {};
head.$len = len;
for (i = 0; i < len; i++) {
if(context.stack.head) {
context.stack.head.$idx = i;
}
head.$idx = i;
chunk = body(chunk, context.push(elem[i], i, len));
}
if(context.stack.head) {
context.stack.head.$idx = undefined;
context.stack.head.$len = undefined;
}
head.$idx = undefined;
head.$len = undefined;
return chunk;
}
else if (skip) {
} else if (skip) {
return skip(this, context);
}
}
Expand Down Expand Up @@ -847,6 +876,12 @@
Chunk.prototype.partial = function(elem, context, partialContext, params) {
var head;

if(params === undefined) {
// Compatibility for < 2.7.0 where `partialContext` did not exist
params = partialContext;
partialContext = context;
}

if (!dust.isEmptyObject(params)) {
partialContext = partialContext.clone();
head = partialContext.pop();
Expand Down
Loading

0 comments on commit 162006a

Please sign in to comment.