From 114477811c0e7ed4a25bc789f0cbd39bc87b61d9 Mon Sep 17 00:00:00 2001 From: Mike Sherov Date: Thu, 7 Aug 2014 12:58:42 -0400 Subject: [PATCH 1/3] Add failing test For extra whitespace in nested partials. --- test/fixtures/examples/nested_partials/nested_partials.txt | 3 +++ .../examples/nested_partials/partials/fourth_inline.mustache | 1 + test/fixtures/examples/nested_partials/partials/third.mustache | 3 +++ 3 files changed, 7 insertions(+) create mode 100644 test/fixtures/examples/nested_partials/partials/fourth_inline.mustache diff --git a/test/fixtures/examples/nested_partials/nested_partials.txt b/test/fixtures/examples/nested_partials/nested_partials.txt index 62776f9..badd575 100644 --- a/test/fixtures/examples/nested_partials/nested_partials.txt +++ b/test/fixtures/examples/nested_partials/nested_partials.txt @@ -3,5 +3,8 @@ FOURTH! + + FOURTH!FOURTH! + \ No newline at end of file diff --git a/test/fixtures/examples/nested_partials/partials/fourth_inline.mustache b/test/fixtures/examples/nested_partials/partials/fourth_inline.mustache new file mode 100644 index 0000000..d796ae0 --- /dev/null +++ b/test/fixtures/examples/nested_partials/partials/fourth_inline.mustache @@ -0,0 +1 @@ +{{ val }} \ No newline at end of file diff --git a/test/fixtures/examples/nested_partials/partials/third.mustache b/test/fixtures/examples/nested_partials/partials/third.mustache index f33301a..30f8fa8 100644 --- a/test/fixtures/examples/nested_partials/partials/third.mustache +++ b/test/fixtures/examples/nested_partials/partials/third.mustache @@ -1,3 +1,6 @@ {{> fourth }} + + {{> fourth_inline }}{{> fourth_inline }} + From 5d77f4de9a9be441515412bb103e55cd3cb6112d Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Thu, 7 Aug 2014 10:38:44 -0700 Subject: [PATCH 2/3] Move failing nested partial example into a test case. See #214 --- .../Functional/NestedPartialIndentTest.php | 45 +++++++++++++++++++ .../nested_partials/nested_partials.txt | 3 -- .../partials/fourth_inline.mustache | 1 - .../nested_partials/partials/third.mustache | 3 -- 4 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 test/Mustache/Test/Functional/NestedPartialIndentTest.php delete mode 100644 test/fixtures/examples/nested_partials/partials/fourth_inline.mustache diff --git a/test/Mustache/Test/Functional/NestedPartialIndentTest.php b/test/Mustache/Test/Functional/NestedPartialIndentTest.php new file mode 100644 index 0000000..a484cf5 --- /dev/null +++ b/test/Mustache/Test/Functional/NestedPartialIndentTest.php @@ -0,0 +1,45 @@ + $partials + )); + $tpl = $m->loadTemplate($src); + $this->assertEquals($expected, $tpl->render()); + } + + public function partialsAndStuff() + { + $partials = array( + 'a' => ' {{> b }}', + 'b' => ' {{> d }}', + 'c' => ' {{> d }}{{> d }}', + 'd' => 'D!', + ); + + return array( + array(' {{> a }}', $partials, ' D!'), + array(' {{> b }}', $partials, ' D!'), + array(' {{> c }}', $partials, ' D!D!'), + ); + } +} diff --git a/test/fixtures/examples/nested_partials/nested_partials.txt b/test/fixtures/examples/nested_partials/nested_partials.txt index badd575..62776f9 100644 --- a/test/fixtures/examples/nested_partials/nested_partials.txt +++ b/test/fixtures/examples/nested_partials/nested_partials.txt @@ -3,8 +3,5 @@ FOURTH! - - FOURTH!FOURTH! - \ No newline at end of file diff --git a/test/fixtures/examples/nested_partials/partials/fourth_inline.mustache b/test/fixtures/examples/nested_partials/partials/fourth_inline.mustache deleted file mode 100644 index d796ae0..0000000 --- a/test/fixtures/examples/nested_partials/partials/fourth_inline.mustache +++ /dev/null @@ -1 +0,0 @@ -{{ val }} \ No newline at end of file diff --git a/test/fixtures/examples/nested_partials/partials/third.mustache b/test/fixtures/examples/nested_partials/partials/third.mustache index 30f8fa8..f33301a 100644 --- a/test/fixtures/examples/nested_partials/partials/third.mustache +++ b/test/fixtures/examples/nested_partials/partials/third.mustache @@ -1,6 +1,3 @@ {{> fourth }} - - {{> fourth_inline }}{{> fourth_inline }} - From 35456764a1ef25e453eb9387654a1c5bafe232dc Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Thu, 7 Aug 2014 10:45:33 -0700 Subject: [PATCH 3/3] Only pass indent through to standalone nested partials. Fixes #214 --- src/Mustache/Compiler.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Mustache/Compiler.php b/src/Mustache/Compiler.php index c6fa24d..e157e2e 100644 --- a/src/Mustache/Compiler.php +++ b/src/Mustache/Compiler.php @@ -277,9 +277,10 @@ class Mustache_Compiler return sprintf($this->prepare(self::INVERTED_SECTION, $level), $id, $method, $id, $filters, $this->walk($nodes, $level)); } + const PARTIAL_INDENT = ', $indent . %s'; const PARTIAL = ' if ($partial = $this->mustache->loadPartial(%s)) { - $buffer .= $partial->renderInternal($context, $indent . %s); + $buffer .= $partial->renderInternal($context%s); } '; @@ -294,10 +295,16 @@ class Mustache_Compiler */ private function partial($id, $indent, $level) { + if ($indent !== '') { + $indentParam = sprintf(self::PARTIAL_INDENT, var_export($indent, true)); + } else { + $indentParam = ''; + } + return sprintf( $this->prepare(self::PARTIAL, $level), var_export($id, true), - var_export($indent, true) + $indentParam ); }