From 658af7d01f41d8e828bd7184aab5503246af6b6c Mon Sep 17 00:00:00 2001 From: Matt Powell Date: Wed, 30 Oct 2013 15:21:34 -0700 Subject: [PATCH 1/3] Add support for parameters on inline partials/blocks --- lib/dust.js | 6 ++++- test/jasmine-test/spec/coreTests.js | 39 +++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/lib/dust.js b/lib/dust.js index e08c756e..ed559c2f 100755 --- a/lib/dust.js +++ b/lib/dust.js @@ -619,9 +619,13 @@ Chunk.prototype.notexists = function(elem, context, bodies) { return this; }; -Chunk.prototype.block = function(elem, context, bodies) { +Chunk.prototype.block = function(elem, context, bodies, params) { var body = bodies.block; + if (params) { + context = context.push(params); + } + if (elem) { body = elem; } diff --git a/test/jasmine-test/spec/coreTests.js b/test/jasmine-test/spec/coreTests.js index 45578d02..3c6fde4d 100755 --- a/test/jasmine-test/spec/coreTests.js +++ b/test/jasmine-test/spec/coreTests.js @@ -1188,6 +1188,45 @@ var coreTests = [ context: { "val1" : "title", "val2" : "A", "obj" : { "name" : ["A", "B"] } }, expected: "AAA", message: "should test blocks with dynamic key values as arrays" + }, + { + name: "blocks with inline parameters", + source: [ '{', + ' {+formBody/}', + ' ', + '{/form}', + '', + '{+form url=dynamically_generated_url/}'].join("\n"), + context: { dynamically_generated_url: 'http://google.com/search'}, + expected: '
', + message: "should test blocks with inline parameters" + }, + { + name: "blocks with inline parameters that reference objects", + source: [ '{', + ' {+formBody/}', + ' ', + '{/formAction}', + '', + '{+formAction url=dynamically_generated_url/}'].join("\n"), + context: { "dynamically_generated_url": { "value": "http://google.com/search" } }, + expected: '
', + message: "should test blocks with inline parameters" + }, + { + name: "blocks with missing inline parameters", + source: [ '{', + ' {+formBody/}', + ' ', + '{/formAction}', + '', + '{+formAction url=refDoesntExist/}'].join("\n"), + context: {}, + expected: '
', + message: "should test blocks with inline parameters" } ] }, From 3a111b2baf253e1ebd311a85728ef54d1309b257 Mon Sep 17 00:00:00 2001 From: Matt Powell Date: Tue, 5 Nov 2013 13:59:36 -0800 Subject: [PATCH 2/3] adds two more unit tests. one which tests passing static strings as an inline parameter to an inline partial and another that tests defining static params on a block. --- test/jasmine-test/spec/coreTests.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/jasmine-test/spec/coreTests.js b/test/jasmine-test/spec/coreTests.js index 3c6fde4d..8ab82e67 100755 --- a/test/jasmine-test/spec/coreTests.js +++ b/test/jasmine-test/spec/coreTests.js @@ -922,6 +922,13 @@ var coreTests = [ expected: "Hello Mick! You have 30 new messages.", message: "should test a blocks with no defaults" }, + { + name: "partial_with_blocks_and_overridable_params", + source: "{+header name=\"Test\" count=\"100\"}Hello {name}! You have {count} new messages.{/header}", + context: { }, + expected: "Hello Test! You have 100 new messages.", + message: "should test defining a block in a partial." + }, { name: "partial_print_name", source: "{#helper}{/helper}", @@ -1227,6 +1234,28 @@ var coreTests = [ context: {}, expected: '
', message: "should test blocks with inline parameters" + }, + { + name: "blocks with a static string as an inline parameter", + source: [ '{', + ' {+formBody/}', + ' ', + '{/formAction}', + '', + '{+formAction url="http://google.com/search"/}'].join("\n"), + context: {}, + expected: '
', + message: "should test blocks with inline parameters that are static strings" + }, + { + name: "blocks defined in another partial with inline parameters", + source: [ '{>"partial_with_blocks_and_overridable_params"/}', + '', + '{ Date: Tue, 19 Nov 2013 18:02:44 -0800 Subject: [PATCH 3/3] revert/remove partial_with_blocks_and_overridable_params partial and unit test --- test/jasmine-test/spec/coreTests.js | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/test/jasmine-test/spec/coreTests.js b/test/jasmine-test/spec/coreTests.js index 8ab82e67..7d803092 100755 --- a/test/jasmine-test/spec/coreTests.js +++ b/test/jasmine-test/spec/coreTests.js @@ -922,13 +922,6 @@ var coreTests = [ expected: "Hello Mick! You have 30 new messages.", message: "should test a blocks with no defaults" }, - { - name: "partial_with_blocks_and_overridable_params", - source: "{+header name=\"Test\" count=\"100\"}Hello {name}! You have {count} new messages.{/header}", - context: { }, - expected: "Hello Test! You have 100 new messages.", - message: "should test defining a block in a partial." - }, { name: "partial_print_name", source: "{#helper}{/helper}", @@ -1247,15 +1240,6 @@ var coreTests = [ context: {}, expected: '
', message: "should test blocks with inline parameters that are static strings" - }, - { - name: "blocks defined in another partial with inline parameters", - source: [ '{>"partial_with_blocks_and_overridable_params"/}', - '', - '{