Skip to content

Commit

Permalink
Release v1.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Prayrit Jain committed Mar 11, 2015
1 parent d674865 commit 996e2f5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 32 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dustjs-helpers",
"version": "1.6.0",
"version": "1.6.1",
"homepage": "https://github.com/linkedin/dustjs-helpers",
"authors": [
"Veena Basavaraj <vybs@users.noreply.github.com>",
Expand Down
60 changes: 32 additions & 28 deletions dist/dust-helpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! dustjs-helpers - v1.6.0
/*! dustjs-helpers - v1.6.1
* https://github.com/linkedin/dustjs-helpers
* Copyright (c) 2015 Aleksander Williams; Released under the MIT License */
(function(root, factory) {
Expand Down Expand Up @@ -35,9 +35,14 @@ function getSelectState(context) {
}

function addSelectState(context, key) {
var head = context.stack.head;
return context
.rebase(context.stack.tail)
var head = context.stack.head,
newContext = context.rebase();

if(context.stack && context.stack.tail) {
newContext.stack = context.stack.tail;
}

return newContext
.push({ "__select__": {
isResolved: false,
isDefaulted: false,
Expand All @@ -46,7 +51,7 @@ function addSelectState(context, key) {
key: key
}
})
.push(head);
.push(head, context.stack.index, context.stack.of);
}

// Utility method : toString() equivalent for functions
Expand Down Expand Up @@ -267,51 +272,50 @@ var helpers = {
// operand can be null for "abs", ceil and floor
operand = params.operand,
round = params.round,
mathOut = null,
operError = function(){
_log("operand is required for this math method");
return null;
};

key = dust.helpers.tap(key, chunk, context);
operand = dust.helpers.tap(operand, chunk, context);
mathOut = null;

key = parseFloat(dust.helpers.tap(key, chunk, context));
operand = parseFloat(dust.helpers.tap(operand, chunk, context));
// TODO: handle and tests for negatives and floats in all math operations
switch(method) {
case "mod":
if(operand === 0 || operand === -0) {
_log("operand for divide operation is 0/-0: expect Nan!");
_log("Division by 0 in {@math} helper", "WARN");
}
mathOut = parseFloat(key) % parseFloat(operand);
mathOut = key % operand;
break;
case "add":
mathOut = parseFloat(key) + parseFloat(operand);
mathOut = key + operand;
break;
case "subtract":
mathOut = parseFloat(key) - parseFloat(operand);
mathOut = key - operand;
break;
case "multiply":
mathOut = parseFloat(key) * parseFloat(operand);
mathOut = key * operand;
break;
case "divide":
if(operand === 0 || operand === -0) {
_log("operand for divide operation is 0/-0: expect Nan/Infinity!");
}
mathOut = parseFloat(key) / parseFloat(operand);
if(operand === 0 || operand === -0) {
_log("Division by 0 in {@math} helper", "WARN");
}
mathOut = key / operand;
break;
case "ceil":
mathOut = Math.ceil(parseFloat(key));
mathOut = Math.ceil(key);
break;
case "floor":
mathOut = Math.floor(parseFloat(key));
mathOut = Math.floor(key);
break;
case "round":
mathOut = Math.round(parseFloat(key));
mathOut = Math.round(key);
break;
case "abs":
mathOut = Math.abs(parseFloat(key));
mathOut = Math.abs(key);
break;
case "toint":
mathOut = parseInt(key, 10);
break;
default:
_log("method passed is not supported");
_log("{@math}: method " + method + " not supported");
}

if (mathOut !== null){
Expand Down Expand Up @@ -367,7 +371,7 @@ var helpers = {
_log("Missing body block in {@select}");
}
} else {
_log("No key provided for {@select}");
_log("No key provided for {@select}", "WARN");
}
return chunk;
},
Expand Down
4 changes: 2 additions & 2 deletions dist/dust-helpers.min.js

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dustjs-helpers",
"version": "1.6.0",
"version": "1.6.1",
"author": {
"name": "Aleksander Williams",
"url": "http://akdubya.github.com/dustjs"
Expand Down

0 comments on commit 996e2f5

Please sign in to comment.