From 7d3f312b4c9c39e189c22b8ef22057cf8583052b Mon Sep 17 00:00:00 2001 From: KevBurnsJr Date: Sun, 12 Jun 2011 17:20:03 -0700 Subject: [PATCH 01/23] Adding test for delimiter switching in partials --- test/MustacheTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/MustacheTest.php b/test/MustacheTest.php index 21714a7..3bbb0e3 100644 --- a/test/MustacheTest.php +++ b/test/MustacheTest.php @@ -147,6 +147,15 @@ class MustacheTest extends PHPUnit_Framework_TestCase { $this->assertEquals('Charlie Chaplin', $m->render(null, array('first_name' => 'Charlie', 'last_name' => 'Chaplin'))); $this->assertEquals('Zappa, Frank', $m->render('{{last_name}}, {{first_name}}', array('first_name' => 'Frank', 'last_name' => 'Zappa'))); } + + /** + * @group partials + */ + public function testRenderDelimitersInPartials() { + $m = new Mustache('{{>stache}}', null, array('stache' => '{{=<% %>=}}{{first_name}} {{last_name}}<%={{ }}=%>')); + $this->assertEquals('Charlie Chaplin', $m->render(null, array('first_name' => 'Charlie', 'last_name' => 'Chaplin'))); + $this->assertEquals('{{first_name}} {{last_name}}', $m->render('{{last_name}}, {{first_name}}', array('first_name' => 'Frank', 'last_name' => 'Zappa'))); + } /** * Mustache should allow newlines (and other whitespace) in comments and all other tags. From c2f1201c5c5fdce2d3d405d46e77635813e9e479 Mon Sep 17 00:00:00 2001 From: KevBurnsJr Date: Sun, 12 Jun 2011 17:27:05 -0700 Subject: [PATCH 02/23] Oops, fixing test. --- test/MustacheTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/MustacheTest.php b/test/MustacheTest.php index 3bbb0e3..a1fdded 100644 --- a/test/MustacheTest.php +++ b/test/MustacheTest.php @@ -153,7 +153,7 @@ class MustacheTest extends PHPUnit_Framework_TestCase { */ public function testRenderDelimitersInPartials() { $m = new Mustache('{{>stache}}', null, array('stache' => '{{=<% %>=}}{{first_name}} {{last_name}}<%={{ }}=%>')); - $this->assertEquals('Charlie Chaplin', $m->render(null, array('first_name' => 'Charlie', 'last_name' => 'Chaplin'))); + $this->assertEquals('{{first_name}} {{last_name}}', $m->render(null, array('first_name' => 'Charlie', 'last_name' => 'Chaplin'))); $this->assertEquals('{{first_name}} {{last_name}}', $m->render('{{last_name}}, {{first_name}}', array('first_name' => 'Frank', 'last_name' => 'Zappa'))); } From 1acae92de2c9d18cbc68c51e68cad31143734ff2 Mon Sep 17 00:00:00 2001 From: KevBurnsJr Date: Sun, 12 Jun 2011 20:26:38 -0700 Subject: [PATCH 03/23] Creating new Test to prove error --- test/MustacheTest.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/test/MustacheTest.php b/test/MustacheTest.php index a1fdded..ad81c0c 100644 --- a/test/MustacheTest.php +++ b/test/MustacheTest.php @@ -151,10 +151,13 @@ class MustacheTest extends PHPUnit_Framework_TestCase { /** * @group partials */ - public function testRenderDelimitersInPartials() { - $m = new Mustache('{{>stache}}', null, array('stache' => '{{=<% %>=}}{{first_name}} {{last_name}}<%={{ }}=%>')); - $this->assertEquals('{{first_name}} {{last_name}}', $m->render(null, array('first_name' => 'Charlie', 'last_name' => 'Chaplin'))); - $this->assertEquals('{{first_name}} {{last_name}}', $m->render('{{last_name}}, {{first_name}}', array('first_name' => 'Frank', 'last_name' => 'Zappa'))); + public function testRenderDelimitersInSections() { + $m = new Mustache('{{#a}}{{=<% %>=}}{{b}} c<%={{ }}=%>{{/a}}'); + $this->assertEquals('{{b}} c', $m->render(null, array( + 'a' => array( + array('b' => 'Do Not Render') + ) + ))); } /** From 61a0b7f2f2b83d79f3eb2da851eb9abb6d1b67b0 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Sun, 12 Jun 2011 23:57:29 -0400 Subject: [PATCH 04/23] Provide another interpolation failure test case. --- test/MustacheTest.php | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/test/MustacheTest.php b/test/MustacheTest.php index 41f5b16..70622b4 100644 --- a/test/MustacheTest.php +++ b/test/MustacheTest.php @@ -197,15 +197,27 @@ class MustacheTest extends PHPUnit_Framework_TestCase { } /** - * @group partials + * @group interpolation + * @dataProvider interpolationData */ - public function testRenderDelimitersInSections() { - $m = new Mustache('{{#a}}{{=<% %>=}}{{b}} c<%={{ }}=%>{{/a}}'); - $this->assertEquals('{{b}} c', $m->render(null, array( - 'a' => array( - array('b' => 'Do Not Render') - ) - ))); + public function testDoubleRenderMustacheTags($template, $context, $expected) { + $m = new Mustache($template, $context); + $this->assertEquals($expected, $m->render()); + } + + public function interpolationData() { + return array( + array( + '{{#a}}{{=<% %>=}}{{b}} c<%={{ }}=%>{{/a}}', + array('a' => array(array('b' => 'Do Not Render'))), + '{{b}} c' + ), + array( + '{{#a}}{{b}}{{/a}}', + array('a' => array('b' => '{{c}}'), 'c' => 'FAIL'), + '{{c}}' + ), + ); } /** @@ -438,4 +450,4 @@ class MustacheExposedOptionsStub extends Mustache { public function getDelimiters() { return array($this->_otag, $this->_ctag); } -} \ No newline at end of file +} From 9af6b2033edf8a494fd5556b06fd3741688b4fd8 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Mon, 13 Jun 2011 01:05:48 -0400 Subject: [PATCH 05/23] Work in progress. Fixing double-rendering of sections, mustache injection, etc. --- Mustache.php | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/Mustache.php b/Mustache.php index 4c12603..57ea064 100644 --- a/Mustache.php +++ b/Mustache.php @@ -211,20 +211,10 @@ class Mustache { * @return string Rendered Mustache template. */ protected function _renderTemplate($template) { - $template = $this->_renderSections($template); - return $this->_renderTags($template); - } - - /** - * Render boolean, enumerable and inverted sections. - * - * @access protected - * @param string $template - * @return string - */ - protected function _renderSections($template) { - while ($section_data = $this->_findSection($template)) { - list($section, $offset, $type, $tag_name, $content) = $section_data; + if ($section = $this->_findSection($template)) { + list($section, $offset, $type, $tag_name, $content) = $section; + $before = substr($template, 0, $offset); + $after = substr($template, $offset + strlen($section)); $replace = ''; $val = $this->_getVariable($tag_name); @@ -256,10 +246,10 @@ class Mustache { break; } - $template = substr_replace($template, $replace, $offset, strlen($section)); + return $this->_renderTags($before) . $replace . $this->_renderTemplate($after); } - return $template; + return $this->_renderTags($template); } /** @@ -856,4 +846,4 @@ class MustacheException extends Exception { // which can't be handled by this Mustache instance. const UNKNOWN_PRAGMA = 4; -} \ No newline at end of file +} From f95f8c09a89809bd61a76ec59d01285fed0b801d Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Mon, 13 Jun 2011 01:23:19 -0400 Subject: [PATCH 06/23] More efficient return from _findSection. --- Mustache.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Mustache.php b/Mustache.php index 57ea064..6df106d 100644 --- a/Mustache.php +++ b/Mustache.php @@ -212,9 +212,7 @@ class Mustache { */ protected function _renderTemplate($template) { if ($section = $this->_findSection($template)) { - list($section, $offset, $type, $tag_name, $content) = $section; - $before = substr($template, 0, $offset); - $after = substr($template, $offset + strlen($section)); + list($before, $type, $tag_name, $content, $after) = $section; $replace = ''; $val = $this->_getVariable($tag_name); @@ -276,7 +274,7 @@ class Mustache { * * @access protected * @param string $template - * @return array $section, $offset, $type, $tag_name and $content + * @return array $before, $type, $tag_name, $content and $after */ protected function _findSection($template) { $regEx = $this->_prepareSectionRegEx($this->_otag, $this->_ctag); @@ -316,10 +314,14 @@ class Mustache { } if (empty($section_stack)) { - $section = substr($template, $section_start, $search_offset - $section_start); - $content = substr($template, $content_start, $offset - $content_start); - - return array($section, $section_start, $section_type, $tag_name, $content); + // $before, $type, $tag_name, $content, $after + return array( + substr($template, 0, $section_start), + $section_type, + $tag_name, + substr($template, $content_start, $offset - $content_start), + substr($template, $search_offset), + ); } break; } @@ -847,3 +849,4 @@ class MustacheException extends Exception { const UNKNOWN_PRAGMA = 4; } + From e452b4cb73fac99aa1140757e5e5d47f0cfea3be Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Mon, 13 Jun 2011 02:03:00 -0400 Subject: [PATCH 07/23] Fix the last couple of regressions with section rendering. --- Mustache.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Mustache.php b/Mustache.php index 6df106d..19e9cbb 100644 --- a/Mustache.php +++ b/Mustache.php @@ -214,13 +214,13 @@ class Mustache { if ($section = $this->_findSection($template)) { list($before, $type, $tag_name, $content, $after) = $section; - $replace = ''; + $renderedContent = ''; $val = $this->_getVariable($tag_name); switch($type) { // inverted section case '^': if (empty($val)) { - $replace .= $content; + $renderedContent = $this->_renderTemplate($content); } break; @@ -229,22 +229,22 @@ class Mustache { if ($this->_varIsIterable($val)) { foreach ($val as $local_context) { $this->_pushContext($local_context); - $replace .= $this->_renderTemplate($content); + $renderedContent .= $this->_renderTemplate($content); $this->_popContext(); } } else if ($val) { if (is_array($val) || is_object($val)) { $this->_pushContext($val); - $replace .= $this->_renderTemplate($content); + $renderedContent = $this->_renderTemplate($content); $this->_popContext(); } else { - $replace .= $content; + $renderedContent = $this->_renderTemplate($content); } } break; } - return $this->_renderTags($before) . $replace . $this->_renderTemplate($after); + return $this->_renderTags($before) . $renderedContent . $this->_renderTemplate($after); } return $this->_renderTags($template); @@ -268,9 +268,7 @@ class Mustache { } /** - * Extract a section from $template. - * - * This is a helper function to find sections needed by _renderSections. + * Extract the first section from $template. * * @access protected * @param string $template @@ -566,7 +564,7 @@ class Mustache { case '#': case '^': case '/': - // remove any leftovers from _renderSections + // remove any leftover section tags return $leading . $trailing; break; default: From 0a10c5bcfe1280a19a754328f423d4fb12c2a3d0 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Mon, 13 Jun 2011 02:16:48 -0400 Subject: [PATCH 08/23] update known issues in README --- README.markdown | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.markdown b/README.markdown index 52ee11f..c3f6831 100644 --- a/README.markdown +++ b/README.markdown @@ -81,11 +81,10 @@ And render it: Known Issues ------------ - * As of v1.1.2, there are a couple of whitespace bugs around section tags. * Things get weird when you change delimiters inside a section -- `delimiters` example currently fails with an "unclosed section" exception. - * The current spec test exposes several whitespace bugs (which are mostly instances of the exact same whitespace - bug) ... Despite these failing tests, this version is actually *closer* to correct than previous releases. + * As of v1.1.2, there are a couple of whitespace bugs around section tags... Despite these failing tests, this + version is actually *closer* to correct than previous releases. See Also From 77f9a37b9ecb216753c0fbd7df17ad8352226f47 Mon Sep 17 00:00:00 2001 From: KevBurnsJr Date: Mon, 13 Jun 2011 00:12:04 -0700 Subject: [PATCH 09/23] Moving $orig_tags to render --- Mustache.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Mustache.php b/Mustache.php index 19e9cbb..b6b08e1 100644 --- a/Mustache.php +++ b/Mustache.php @@ -175,6 +175,9 @@ class Mustache { public function render($template = null, $view = null, $partials = null) { if ($template === null) $template = $this->_template; if ($partials !== null) $this->_partials = $partials; + + $otag_orig = $this->_otag; + $ctag_orig = $this->_ctag; if ($view) { $this->_context = array($view); @@ -183,7 +186,12 @@ class Mustache { } $template = $this->_renderPragmas($template); - return $this->_renderTemplate($template, $this->_context); + $template = $this->_renderTemplate($template, $this->_context); + + $this->_otag = $otag_orig; + $this->_ctag = $ctag_orig; + + return $template; } /** @@ -475,9 +483,6 @@ class Mustache { return $template; } - $otag_orig = $this->_otag; - $ctag_orig = $this->_ctag; - $first = true; $this->_tagRegEx = $this->_prepareTagRegEx($this->_otag, $this->_ctag, true); @@ -517,9 +522,6 @@ class Mustache { } } - $this->_otag = $otag_orig; - $this->_ctag = $ctag_orig; - return $html . $template; } From 5e7f0ea4bded0f3c52c6959632de2c1a9f73e680 Mon Sep 17 00:00:00 2001 From: KevBurnsJr Date: Mon, 13 Jun 2011 00:12:47 -0700 Subject: [PATCH 10/23] Relocating _renderTags($before) since _renderTags now has the ability to modify delimiters --- Mustache.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Mustache.php b/Mustache.php index b6b08e1..d0c0da6 100644 --- a/Mustache.php +++ b/Mustache.php @@ -219,8 +219,11 @@ class Mustache { * @return string Rendered Mustache template. */ protected function _renderTemplate($template) { + if ($section = $this->_findSection($template)) { list($before, $type, $tag_name, $content, $after) = $section; + + $rendered_before = $this->_renderTags($before); $renderedContent = ''; $val = $this->_getVariable($tag_name); @@ -252,7 +255,7 @@ class Mustache { break; } - return $this->_renderTags($before) . $renderedContent . $this->_renderTemplate($after); + return $rendered_before . $renderedContent . $this->_renderTemplate($after); } return $this->_renderTags($template); From eff36b5540ae0b13b4f99d601b22240881a42395 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Mon, 13 Jun 2011 03:26:27 -0400 Subject: [PATCH 11/23] Coding style? Conventions? Consistency? Who needs that?. Mebbe I should get some sleep :) --- Mustache.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Mustache.php b/Mustache.php index d0c0da6..779ff34 100644 --- a/Mustache.php +++ b/Mustache.php @@ -225,13 +225,13 @@ class Mustache { $rendered_before = $this->_renderTags($before); - $renderedContent = ''; + $rendered_content = ''; $val = $this->_getVariable($tag_name); switch($type) { // inverted section case '^': if (empty($val)) { - $renderedContent = $this->_renderTemplate($content); + $rendered_content = $this->_renderTemplate($content); } break; @@ -240,22 +240,22 @@ class Mustache { if ($this->_varIsIterable($val)) { foreach ($val as $local_context) { $this->_pushContext($local_context); - $renderedContent .= $this->_renderTemplate($content); + $rendered_content .= $this->_renderTemplate($content); $this->_popContext(); } } else if ($val) { if (is_array($val) || is_object($val)) { $this->_pushContext($val); - $renderedContent = $this->_renderTemplate($content); + $rendered_content = $this->_renderTemplate($content); $this->_popContext(); } else { - $renderedContent = $this->_renderTemplate($content); + $rendered_content = $this->_renderTemplate($content); } } break; } - return $rendered_before . $renderedContent . $this->_renderTemplate($after); + return $rendered_before . $rendered_content . $this->_renderTemplate($after); } return $this->_renderTags($template); From a7cf3e7309dbbdedf58bcdaca9a9bd5ba7cc6cfd Mon Sep 17 00:00:00 2001 From: KevBurnsJr Date: Mon, 13 Jun 2011 00:31:36 -0700 Subject: [PATCH 12/23] Adding test for delimiters --- test/MustacheTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/MustacheTest.php b/test/MustacheTest.php index 70622b4..aded7bc 100644 --- a/test/MustacheTest.php +++ b/test/MustacheTest.php @@ -402,6 +402,15 @@ class MustacheTest extends PHPUnit_Framework_TestCase { $this->assertEquals('success', $m->render('{{=<% %>=}}<% result %>')); } + /** + * @group delimiters + */ + public function testStickyDelimiters() { + $m = new Mustache(null, array('result' => 'FAIL')); + $this->assertEquals('{{ result }}', $m->render('{{=[[ ]]=}}{{ result }}[[={{ }}=]]')); + $this->assertEquals('{{ result }}', $m->render('{{=[[ ]]=}}{{#result}}FAIL{{/result}}{{result}}[[={{ }}=]]')); + } + /** * @group sections * @dataProvider poorlyNestedSections From a2f3662b6b897651429c2d9a50ab7b65a5f5446d Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Mon, 13 Jun 2011 03:54:15 -0400 Subject: [PATCH 13/23] update failing test case, test for sticky delims between renders. --- test/MustacheTest.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/MustacheTest.php b/test/MustacheTest.php index aded7bc..d62d648 100644 --- a/test/MustacheTest.php +++ b/test/MustacheTest.php @@ -36,7 +36,7 @@ class MustacheTest extends PHPUnit_Framework_TestCase { const TEST_CLASS = 'Mustache'; protected $knownIssues = array( - 'Delimiters' => "Known issue: sections don't respect delimiter changes", + // Just the whitespace ones... ); /** @@ -408,7 +408,8 @@ class MustacheTest extends PHPUnit_Framework_TestCase { public function testStickyDelimiters() { $m = new Mustache(null, array('result' => 'FAIL')); $this->assertEquals('{{ result }}', $m->render('{{=[[ ]]=}}{{ result }}[[={{ }}=]]')); - $this->assertEquals('{{ result }}', $m->render('{{=[[ ]]=}}{{#result}}FAIL{{/result}}{{result}}[[={{ }}=]]')); + $this->assertEquals('{{ result }}', $m->render('{{=[[ ]]=}}[[#result]]{{ result }}[[/result]]')); + $this->assertEquals('{{ result }}', $m->render('{{=[[ ]]=}}[[#result]]{{ result }}[[/result]][[={{ }}=]]')); } /** From 25070141a945c009180d49912eb020adeda9c941 Mon Sep 17 00:00:00 2001 From: KevBurnsJr Date: Mon, 13 Jun 2011 00:55:31 -0700 Subject: [PATCH 14/23] Fixing broken test --- test/MustacheTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/MustacheTest.php b/test/MustacheTest.php index aded7bc..8245e5d 100644 --- a/test/MustacheTest.php +++ b/test/MustacheTest.php @@ -408,7 +408,7 @@ class MustacheTest extends PHPUnit_Framework_TestCase { public function testStickyDelimiters() { $m = new Mustache(null, array('result' => 'FAIL')); $this->assertEquals('{{ result }}', $m->render('{{=[[ ]]=}}{{ result }}[[={{ }}=]]')); - $this->assertEquals('{{ result }}', $m->render('{{=[[ ]]=}}{{#result}}FAIL{{/result}}{{result}}[[={{ }}=]]')); + $this->assertEquals('{{#result}}{{/result}}', $m->render('{{=[[ ]]=}}{{#result}}{{/result}}[[={{ }}=]]')); } /** From a16d9ed51c1c234b78cdfc7144171feee47c7a3b Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Mon, 13 Jun 2011 04:00:13 -0400 Subject: [PATCH 15/23] add a test that changes delimiters all over the place... inside and outside sections. --- README.markdown | 2 -- test/MustacheTest.php | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/README.markdown b/README.markdown index c3f6831..2c13ab3 100644 --- a/README.markdown +++ b/README.markdown @@ -81,8 +81,6 @@ And render it: Known Issues ------------ - * Things get weird when you change delimiters inside a section -- `delimiters` example currently fails with an - "unclosed section" exception. * As of v1.1.2, there are a couple of whitespace bugs around section tags... Despite these failing tests, this version is actually *closer* to correct than previous releases. diff --git a/test/MustacheTest.php b/test/MustacheTest.php index d62d648..7edf232 100644 --- a/test/MustacheTest.php +++ b/test/MustacheTest.php @@ -410,6 +410,7 @@ class MustacheTest extends PHPUnit_Framework_TestCase { $this->assertEquals('{{ result }}', $m->render('{{=[[ ]]=}}{{ result }}[[={{ }}=]]')); $this->assertEquals('{{ result }}', $m->render('{{=[[ ]]=}}[[#result]]{{ result }}[[/result]]')); $this->assertEquals('{{ result }}', $m->render('{{=[[ ]]=}}[[#result]]{{ result }}[[/result]][[={{ }}=]]')); + $this->assertEquals('{{ result }}', $m->render('{{#result}}{{=[[ ]]=}}{{ result }}[[/result]][[^result]][[={{ }}=]][[ result ]]{{/result}}')); } /** From 1abf854af3ca3bb6b7943a32ed7d5dc69ddaefa3 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Mon, 13 Jun 2011 04:00:49 -0400 Subject: [PATCH 16/23] Make section rendering delimiter-chage-aware. Fixes longstanding section/delimiter bug. --- Mustache.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Mustache.php b/Mustache.php index 779ff34..ef3af03 100644 --- a/Mustache.php +++ b/Mustache.php @@ -271,7 +271,7 @@ class Mustache { */ protected function _prepareSectionRegEx($otag, $ctag) { return sprintf( - '/(?:(?<=\\n)[ \\t]*)?%s(?P[%s])(?P.+?)%s\\n?/s', + '/(?:(?<=\\n)[ \\t]*)?%s(?:(?P[%s])(?P.+?)|=(?P.*?)=)%s\\n?/s', preg_quote($otag, '/'), self::SECTION_TYPES, preg_quote($ctag, '/') @@ -297,6 +297,12 @@ class Mustache { $section_stack = array(); $matches = array(); while (preg_match($regEx, $template, $matches, PREG_OFFSET_CAPTURE, $search_offset)) { + if (isset($matches['delims'][0])) { + list($otag, $ctag) = explode(' ', $matches['delims'][0]); + $regEx = $this->_prepareSectionRegEx($otag, $ctag); + $search_offset = $matches[0][1] + strlen($matches[0][0]); + continue; + } $match = $matches[0][0]; $offset = $matches[0][1]; From 527bca37f35cc95c7a7c58cb56dce987b45e4209 Mon Sep 17 00:00:00 2001 From: KevBurnsJr Date: Mon, 13 Jun 2011 01:01:33 -0700 Subject: [PATCH 17/23] Fixing testStickyDelimiters --- Mustache.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Mustache.php b/Mustache.php index d0c0da6..3a64e6d 100644 --- a/Mustache.php +++ b/Mustache.php @@ -219,7 +219,6 @@ class Mustache { * @return string Rendered Mustache template. */ protected function _renderTemplate($template) { - if ($section = $this->_findSection($template)) { list($before, $type, $tag_name, $content, $after) = $section; @@ -271,7 +270,7 @@ class Mustache { */ protected function _prepareSectionRegEx($otag, $ctag) { return sprintf( - '/(?:(?<=\\n)[ \\t]*)?%s(?P[%s])(?P.+?)%s\\n?/s', + '/(?:(?<=\\n)[ \\t]*)?%s(?:(?P[%s])(?P.+?)|=(?P.*?)=)%s\\n?/s', preg_quote($otag, '/'), self::SECTION_TYPES, preg_quote($ctag, '/') @@ -297,11 +296,18 @@ class Mustache { $section_stack = array(); $matches = array(); while (preg_match($regEx, $template, $matches, PREG_OFFSET_CAPTURE, $search_offset)) { - + $match = $matches[0][0]; $offset = $matches[0][1]; $type = $matches['type'][0]; $tag_name = trim($matches['tag_name'][0]); + + if (isset($matches['delims'][0])) { + list($otag, $ctag) = explode(' ', $matches['delims'][0]); + $regEx = $this->_prepareSectionRegEx($otag, $ctag); + $search_offset = $offset + strlen($match); + continue; + } $search_offset = $offset + strlen($match); From 3a8b4b0ec79c7af91d3c43f56831a2468a03a346 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Mon, 13 Jun 2011 04:26:35 -0400 Subject: [PATCH 18/23] Update manpage links in README Closes #41 Thanks ddrake --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 2c13ab3..f2dbe39 100644 --- a/README.markdown +++ b/README.markdown @@ -89,4 +89,4 @@ See Also -------- * [Readme for the Ruby Mustache implementation](http://github.com/defunkt/mustache/blob/master/README.md). - * [mustache(1)](http://defunkt.github.com/mustache/mustache.1.html) and [mustache(5)](http://defunkt.github.com/mustache/mustache.5.html) man pages. + * [mustache(1)](http://mustache.github.com/mustache.1.html) and [mustache(5)](http://mustache.github.com/mustache.5.html) man pages. From a086a21b5fc668b9a01b6f52c7578cfc713ed48d Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Mon, 13 Jun 2011 04:33:03 -0400 Subject: [PATCH 19/23] clarifying which version tag --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index f2dbe39..830df90 100644 --- a/README.markdown +++ b/README.markdown @@ -81,7 +81,7 @@ And render it: Known Issues ------------ - * As of v1.1.2, there are a couple of whitespace bugs around section tags... Despite these failing tests, this + * As of Mustache spec v1.1.2, there are a couple of whitespace bugs around section tags... Despite these failing tests, this version is actually *closer* to correct than previous releases. From 28b5a457cef50299fd52c7ce038e7629ce321e54 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Mon, 13 Jun 2011 04:38:24 -0400 Subject: [PATCH 20/23] fix merge conflict. --- Mustache.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Mustache.php b/Mustache.php index 3f7a572..5b7b57b 100644 --- a/Mustache.php +++ b/Mustache.php @@ -307,13 +307,6 @@ class Mustache { $offset = $matches[0][1]; $type = $matches['type'][0]; $tag_name = trim($matches['tag_name'][0]); - - if (isset($matches['delims'][0])) { - list($otag, $ctag) = explode(' ', $matches['delims'][0]); - $regEx = $this->_prepareSectionRegEx($otag, $ctag); - $search_offset = $offset + strlen($match); - continue; - } $search_offset = $offset + strlen($match); From b7a12665ea003b3f9ffd3c43a02d3136b48e9b71 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Mon, 13 Jun 2011 15:12:43 -0400 Subject: [PATCH 21/23] Add a VERSION constant. closes #45 --- Mustache.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Mustache.php b/Mustache.php index 5b7b57b..ed27c59 100644 --- a/Mustache.php +++ b/Mustache.php @@ -14,6 +14,8 @@ */ class Mustache { + const VERSION = '0.7.1-dev'; + /** * Should this Mustache throw exceptions when it finds unexpected tags? * @@ -175,7 +177,7 @@ class Mustache { public function render($template = null, $view = null, $partials = null) { if ($template === null) $template = $this->_template; if ($partials !== null) $this->_partials = $partials; - + $otag_orig = $this->_otag; $ctag_orig = $this->_ctag; @@ -190,7 +192,7 @@ class Mustache { $this->_otag = $otag_orig; $this->_ctag = $ctag_orig; - + return $template; } @@ -221,7 +223,7 @@ class Mustache { protected function _renderTemplate($template) { if ($section = $this->_findSection($template)) { list($before, $type, $tag_name, $content, $after) = $section; - + $rendered_before = $this->_renderTags($before); $rendered_content = ''; From fbcea210e3fcdb54416d9749cfb3a44d249b0804 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Mon, 13 Jun 2011 15:14:29 -0400 Subject: [PATCH 22/23] Version bump --- Mustache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mustache.php b/Mustache.php index ed27c59..33c9288 100644 --- a/Mustache.php +++ b/Mustache.php @@ -14,7 +14,7 @@ */ class Mustache { - const VERSION = '0.7.1-dev'; + const VERSION = '0.7.1'; /** * Should this Mustache throw exceptions when it finds unexpected tags? From ccf4b336665ef7bd32f775fa9aecd370b81b3743 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Mon, 13 Jun 2011 15:23:38 -0400 Subject: [PATCH 23/23] Add a SPEC_VERSION constant, since that's super handy too. --- Mustache.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Mustache.php b/Mustache.php index 33c9288..a6c87c8 100644 --- a/Mustache.php +++ b/Mustache.php @@ -14,7 +14,8 @@ */ class Mustache { - const VERSION = '0.7.1'; + const VERSION = '0.7.1'; + const SPEC_VERSION = '1.1.2'; /** * Should this Mustache throw exceptions when it finds unexpected tags?