Skip to content

Commit

Permalink
fix issue linkedin#68
Browse files Browse the repository at this point in the history
  • Loading branch information
jairodemorais committed Jun 28, 2012
1 parent c13e29b commit 637066f
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 9 deletions.
19 changes: 15 additions & 4 deletions dist/dust-core-0.6.0.js
Expand Up @@ -541,6 +541,16 @@ if (typeof exports !== "undefined") {
}
(function(dust){

/* make a safe version of console if it is not available
* currently supporting:
* _console.log
* */
var _console = (typeof console !== 'undefined')? console: {
log: function(){
/* a noop*/
}
};

function isSelect(context) {
var value = context.current();
return typeof value === "object" && value.isSelect === true;
Expand Down Expand Up @@ -600,7 +610,10 @@ var helpers = {
idx: function(chunk, context, bodies) {
return bodies.block(chunk, context.push(context.stack.index));
},

contextDump: function(chunk, context, bodies) {
_console.log(JSON.stringify(context.stack));
return chunk;
},
"if": function( chunk, context, bodies, params ){
if( params && params.cond ){
var cond = params.cond;
Expand All @@ -626,9 +639,7 @@ var helpers = {
}
// no condition
else {
if( typeof window !== 'undefined' && window.console ){
window.console.log( "No expression given!" );
}
_console.log( "No expression given!" );
}
return chunk;
},
Expand Down
25 changes: 21 additions & 4 deletions dist/dust-full-0.6.0.js
Expand Up @@ -541,6 +541,16 @@ if (typeof exports !== "undefined") {
}
(function(dust){

/* make a safe version of console if it is not available
* currently supporting:
* _console.log
* */
var _console = (typeof console !== 'undefined')? console: {
log: function(){
/* a noop*/
}
};

function isSelect(context) {
var value = context.current();
return typeof value === "object" && value.isSelect === true;
Expand Down Expand Up @@ -600,7 +610,10 @@ var helpers = {
idx: function(chunk, context, bodies) {
return bodies.block(chunk, context.push(context.stack.index));
},

contextDump: function(chunk, context, bodies) {
_console.log(JSON.stringify(context.stack));
return chunk;
},
"if": function( chunk, context, bodies, params ){
if( params && params.cond ){
var cond = params.cond;
Expand All @@ -626,9 +639,7 @@ var helpers = {
}
// no condition
else {
if( typeof window !== 'undefined' && window.console ){
window.console.log( "No expression given!" );
}
_console.log( "No expression given!" );
}
return chunk;
},
Expand Down Expand Up @@ -2187,11 +2198,17 @@ var parser = (function(){
result0 = result0 !== null ? result0 : "";
if (result0 !== null) {
result2 = parse_nestedKey();
if (result2 === null) {
result2 = parse_array();
}
if (result2 !== null) {
result1 = [];
while (result2 !== null) {
result1.push(result2);
result2 = parse_nestedKey();
if (result2 === null) {
result2 = parse_array();
}
}
} else {
result1 = null;
Expand Down
6 changes: 6 additions & 0 deletions lib/parser.js

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

2 changes: 1 addition & 1 deletion src/dust.pegjs
Expand Up @@ -121,7 +121,7 @@ integer "integer"
Match anything that match with key plus one or more characters that match with key again but preceded by a dot "."
---------------------------------------------------------------------------------------------------------------------------------------*/
path "path"
= k:key? d:(nestedKey)+ {
= k:key? d:(nestedKey / array)+ {
d = d[0];
if (k && d) {
d.unshift(k);
Expand Down
7 changes: 7 additions & 0 deletions test/jasmine-test/spec/examples.js
Expand Up @@ -505,6 +505,13 @@ var dustExamples = [
expected: "hello!",
message: "should return a specific array element by index. Most Complex case, the array contains nested objects."
},
{
name: "Accessing array by index",
source: '{do[0]}',
context: { "do": ["lala", "lele"] },
expected: "lala",
message: "should return a specific array element by index. Root context object as array."
},
{
name: "params: integer",
source: "{#helper foo=10 /}",
Expand Down

0 comments on commit 637066f

Please sign in to comment.