Created
March 12, 2010 02:58
-
-
Save sminnee/329986 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Index: sapphire/core/SSViewer.php | |
| =================================================================== | |
| --- sapphire/core/SSViewer.php (revision 100762) | |
| +++ sapphire/core/SSViewer.php (working copy) | |
| @@ -387,6 +387,11 @@ | |
| return $output; | |
| } | |
| + | |
| + static function execute_template($template, $data) { | |
| + $v = new SSViewer($template); | |
| + return $v->process($data); | |
| + } | |
| static function parseTemplateContent($content, $template="") { | |
| // Remove UTF-8 byte order mark: | |
| @@ -406,21 +411,6 @@ | |
| } | |
| } | |
| - while(true) { | |
| - $oldContent = $content; | |
| - | |
| - // Add include filename comments on dev sites | |
| - if(Director::isDev() && self::$source_file_comments) $replacementCode = 'return "<!-- include " . SSViewer::getTemplateFile($matches[1]) . " -->\n" | |
| - . SSViewer::getTemplateContent($matches[1]) | |
| - . "\n<!-- end include " . SSViewer::getTemplateFile($matches[1]) . " -->";'; | |
| - else $replacementCode = 'return SSViewer::getTemplateContent($matches[1]);'; | |
| - | |
| - $content = preg_replace_callback('/<' . '% include +([A-Za-z0-9_]+) +%' . '>/', create_function( | |
| - '$matches', $replacementCode | |
| - ), $content); | |
| - if($oldContent == $content) break; | |
| - } | |
| - | |
| // $val, $val.property, $val(param), etc. | |
| $replacements = array( | |
| '/<%--.*--%>/U' => '', | |
| @@ -531,6 +521,17 @@ | |
| // add all requirements to the $requirements array | |
| preg_match_all('/<% require ([a-zA-Z]+)\(([^\)]+)\) %>/', $content, $requirements); | |
| $content = preg_replace('/<% require .* %>/', null, $content); | |
| + | |
| + | |
| + // Add include filename comments on dev sites | |
| + if(Director::isDev() && self::$source_file_comments) $replacementCode = 'return "<!-- include " . SSViewer::getTemplateFile($matches[1]) . " -->\n" | |
| + . "<?= SSViewer::parse_template(\\"" . $matches[1] . "\", \$item); ?>" | |
| + . "\n<!-- end include " . SSViewer::getTemplateFile($matches[1]) . " -->";'; | |
| + else $replacementCode = 'return "<?= SSViewer::execute_template(\\"" . $matches[1] . "\", \$item); ?>";'; | |
| + | |
| + $content = preg_replace_callback('/<' . '% include +([A-Za-z0-9_]+) +%' . '>/', create_function( | |
| + '$matches', $replacementCode | |
| + ), $content); | |
| // legacy | |
| $content = ereg_replace('<!-- +if +([A-Za-z0-9_]+) +-->', '<? if($item->cachedCall("\\1")) { ?>', $content); | |
| Index: sapphire/tests/SSViewerTest.php | |
| =================================================================== | |
| --- sapphire/tests/SSViewerTest.php (revision 100762) | |
| +++ sapphire/tests/SSViewerTest.php (working copy) | |
| @@ -280,6 +280,32 @@ | |
| $negotiator->xhtml($response); | |
| $this->assertRegExp('/<head><base href=".*"><\/base><\/head>/', $response->getBody()); | |
| } | |
| + | |
| + | |
| + function testRecursiveInclude() { | |
| + $view = new SSViewer(array('SSViewerTestRecursiveInclude')); | |
| + | |
| + $data = new ArrayData(array( | |
| + 'Title' => 'A', | |
| + 'Children' => new DataObjectSet(array( | |
| + new ArrayData(array( | |
| + 'Title' => 'A1', | |
| + 'Children' => new DataObjectSet(array( | |
| + new ArrayData(array( 'Title' => 'A1 i', )), | |
| + new ArrayData(array( 'Title' => 'A1 ii', )), | |
| + )), | |
| + )), | |
| + new ArrayData(array( 'Title' => 'A2', )), | |
| + new ArrayData(array( 'Title' => 'A3', )), | |
| + )), | |
| + )); | |
| + | |
| + $result = $view->process($data); | |
| + // We don't care about whitespace | |
| + $rationalisedResult = trim(preg_replace('/\s+/', ' ', $result)); | |
| + | |
| + $this->assertEquals('A A1 A1 i A1 ii A2 A3', $rationalisedResult); | |
| + } | |
| } | |
| /** | |
| Index: sapphire/tests/templates/SSViewerTestRecursiveInclude.ss | |
| =================================================================== | |
| --- sapphire/tests/templates/SSViewerTestRecursiveInclude.ss (revision 0) | |
| +++ sapphire/tests/templates/SSViewerTestRecursiveInclude.ss (revision 0) | |
| @@ -0,0 +1,6 @@ | |
| +$Title | |
| +<% if Children %> | |
| +<% control Children %> | |
| +<% include SSViewerTestRecursiveInclude %> | |
| +<% end_control %> | |
| +<% end_if %> | |
| \ No newline at end of file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment