diff --git a/dist/dust-core-1.1.1.js b/dist/dust-core-1.1.1.js index c062151e..dc531566 100644 --- a/dist/dust-core-1.1.1.js +++ b/dist/dust-core-1.1.1.js @@ -510,6 +510,7 @@ Chunk.prototype.partial = function(elem, context, params) { //put the params context second to match what section does. {.} matches the current context without parameters // start with an empty context partialContext = dust.makeBase(context.global); + partialContext.blocks = context.blocks; if (context.stack && context.stack.tail){ // grab the stack(tail) off of the previous context if we have it partialContext.stack = context.stack.tail; diff --git a/dist/dust-full-1.1.1.js b/dist/dust-full-1.1.1.js index 5ff1756a..58027436 100644 --- a/dist/dust-full-1.1.1.js +++ b/dist/dust-full-1.1.1.js @@ -510,6 +510,7 @@ Chunk.prototype.partial = function(elem, context, params) { //put the params context second to match what section does. {.} matches the current context without parameters // start with an empty context partialContext = dust.makeBase(context.global); + partialContext.blocks = context.blocks; if (context.stack && context.stack.tail){ // grab the stack(tail) off of the previous context if we have it partialContext.stack = context.stack.tail; diff --git a/test/jasmine-test/spec/coreTests.js b/test/jasmine-test/spec/coreTests.js index a999935d..39aae0b5 100644 --- a/test/jasmine-test/spec/coreTests.js +++ b/test/jasmine-test/spec/coreTests.js @@ -784,6 +784,62 @@ var coreTests = [ expected: "", message: "should ignore carriage return or tab in inline param values" }, + { + name: "array: reference $idx in iteration on objects", + source: "{#names}({$idx}).{title} {name}{~n}{/names}", + context: { title: "Sir", names: [ { name: "Moe" }, { name: "Larry" }, { name: "Curly" } ] }, + expected: "(0).Sir Moe\n(1).Sir Larry\n(2).Sir Curly\n", + message: "array: reference $idx in iteration on objects" + }, + { + name: "array: reference $len in iteration on objects", + source: "{#names}Size=({$len}).{title} {name}{~n}{/names}", + context: { title: "Sir", names: [ { name: "Moe" }, { name: "Larry" }, { name: "Curly" } ] }, + expected: "Size=(3).Sir Moe\nSize=(3).Sir Larry\nSize=(3).Sir Curly\n", + message: "test array: reference $len in iteration on objects" + }, + { + name: "array reference $idx in iteration on simple type", + source: "{#names}({$idx}).{title} {.}{~n}{/names}", + context: { title: "Sir", names: [ "Moe", "Larry", "Curly" ] }, + expected: "(0).Sir Moe\n(1).Sir Larry\n(2).Sir Curly\n", + message: "test array reference $idx in iteration on simple types" + }, + { + name: "array reference $len in iteration on simple type", + source: "{#names}Size=({$len}).{title} {.}{~n}{/names}", + context: { title: "Sir", names: [ "Moe", "Larry", "Curly" ] }, + expected: "Size=(3).Sir Moe\nSize=(3).Sir Larry\nSize=(3).Sir Curly\n", + message: "test array reference $len in iteration on simple types" + }, + { + name: "array reference $idx/$len on empty array case", + source: "{#names}Idx={$idx} Size=({$len}).{title} {.}{~n}{/names}", + context: { title: "Sir", names: [ ] }, + expected: "", + message: "test array reference $idx/$len on empty array case" + }, + { + name: "array reference $idx/$len on single element case (scalar case)", + source: "{#name}Idx={$idx} Size={$len} {.}{/name}", + context: { name: "Just one name" }, + expected: "Idx= Size= Just one name", + message: "test array reference $idx/$len on single element case" + }, + { + name: "array reference $idx/$len {#.} section case", + source: "{#names}{#.}{$idx}{.} {/.}{/names}", + context: { names: ["Moe", "Larry", "Curly"] }, + expected: "0Moe 1Larry 2Curly ", + message: "test array reference $idx/$len {#.} section case" + }, + { + name: "array reference $idx/$len nested loops", + source: "{#A}A loop:{$idx}-{$len},{#B}B loop:{$idx}-{$len}C[0]={.C[0]} {/B}A loop trailing: {$idx}-{$len}{/A}", + context: {"A": [ {"B": [ {"C": ["Ca1", "C2"]}, {"C": ["Ca2", "Ca22"]} ] }, {"B": [ {"C": ["Cb1", "C2"]}, {"C": ["Cb2", "Ca2"]} ] } ] }, + expected: "A loop:0-2,B loop:0-2C[0]=Ca1 B loop:1-2C[0]=Ca2 A loop trailing: 0-2A loop:1-2,B loop:0-2C[0]=Cb1 B loop:1-2C[0]=Cb2 A loop trailing: 1-2", + message: "test array reference $idx/$len nested loops" + }, { name: "blocks with dynamic keys", source: ['{ -