mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX Generate valid PHP when $includeDebuggingComments is true.
This commit is contained in:
parent
fece61c90b
commit
04c8e2b762
5
tests/templates/SSViewerTestCommentsFullSource.ss
Normal file
5
tests/templates/SSViewerTestCommentsFullSource.ss
Normal file
@ -0,0 +1,5 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head></head>
|
||||
<body></body>
|
||||
</html>
|
1
tests/templates/SSViewerTestCommentsInclude.ss
Normal file
1
tests/templates/SSViewerTestCommentsInclude.ss
Normal file
@ -0,0 +1 @@
|
||||
Included
|
1
tests/templates/SSViewerTestCommentsPartialSource.ss
Normal file
1
tests/templates/SSViewerTestCommentsPartialSource.ss
Normal file
@ -0,0 +1 @@
|
||||
<div class='typography'></div>
|
1
tests/templates/SSViewerTestCommentsWithInclude.ss
Normal file
1
tests/templates/SSViewerTestCommentsWithInclude.ss
Normal file
@ -0,0 +1 @@
|
||||
<div class='typography'><% include SSViewerTestCommentsInclude %></div>
|
@ -1,6 +1,10 @@
|
||||
<?php
|
||||
|
||||
class SSViewerTest extends SapphireTest {
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
SSViewer::set_source_file_comments(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for {@link SSViewer::current_theme()} for different behaviour
|
||||
@ -583,6 +587,38 @@ after')
|
||||
|
||||
SSViewer::setOption('rewriteHashlinks', $oldRewriteHashLinks);
|
||||
}
|
||||
|
||||
function testRenderWithSourceFileComments() {
|
||||
SSViewer::set_source_file_comments(true);
|
||||
|
||||
$view = new SSViewer(array('SSViewerTestCommentsFullSource'));
|
||||
$data = new ArrayData(array());
|
||||
|
||||
$result = $view->process($data);
|
||||
$expected = '<!doctype html>
|
||||
<html><!-- template ' . BASE_PATH . '/sapphire/tests/templates/SSViewerTestCommentsFullSource.ss -->
|
||||
<head></head>
|
||||
<body></body>
|
||||
<!-- end template ' . BASE_PATH . '/sapphire/tests/templates/SSViewerTestCommentsFullSource.ss --></html>
|
||||
';
|
||||
$this->assertEquals($result, $expected);
|
||||
|
||||
$view = new SSViewer(array('SSViewerTestCommentsPartialSource'));
|
||||
$data = new ArrayData(array());
|
||||
|
||||
$result = $view->process($data);
|
||||
$expected = '<!-- template ' . BASE_PATH . '/sapphire/tests/templates/SSViewerTestCommentsPartialSource.ss --><div class=\'typography\'></div><!-- end template ' . BASE_PATH . '/sapphire/tests/templates/SSViewerTestCommentsPartialSource.ss -->';
|
||||
$this->assertEquals($result, $expected);
|
||||
|
||||
$view = new SSViewer(array('SSViewerTestCommentsWithInclude'));
|
||||
$data = new ArrayData(array());
|
||||
|
||||
$result = $view->process($data);
|
||||
$expected = '<!-- template ' . BASE_PATH . '/sapphire/tests/templates/SSViewerTestCommentsWithInclude.ss --><div class=\'typography\'><!-- include \'SSViewerTestCommentsInclude\' --><!-- template ' . BASE_PATH . '/sapphire/tests/templates/SSViewerTestCommentsInclude.ss -->Included<!-- end template ' . BASE_PATH . '/sapphire/tests/templates/SSViewerTestCommentsInclude.ss --><!-- end include \'SSViewerTestCommentsInclude\' --></div><!-- end template ' . BASE_PATH . '/sapphire/tests/templates/SSViewerTestCommentsWithInclude.ss -->';
|
||||
$this->assertEquals($result, $expected);
|
||||
|
||||
SSViewer::set_source_file_comments(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -2949,7 +2949,7 @@ class SSTemplateParser extends Parser {
|
||||
function ClosedBlock__finalise(&$res) {
|
||||
$blockname = $res['BlockName']['text'];
|
||||
|
||||
$method = 'ClosedBlock_Handle_'.ucfirst(strtolower($blockname));
|
||||
$method = 'ClosedBlock_Handle_'.$blockname;
|
||||
if (method_exists($this, $method)) $res['php'] = $this->$method($res);
|
||||
else {
|
||||
throw new SSTemplateParseException('Unknown closed block "'.$blockname.'" encountered. Perhaps you are not supposed to close this block, or have mis-spelled it?', $this);
|
||||
@ -2981,6 +2981,7 @@ class SSTemplateParser extends Parser {
|
||||
* @deprecated
|
||||
*/
|
||||
function ClosedBlock_Handle_Control(&$res) {
|
||||
Deprecation::notice('3.1', 'Use <% with %> or <% loop %> instead.');
|
||||
return $this->ClosedBlock_Handle_Loop($res);
|
||||
}
|
||||
|
||||
@ -3086,7 +3087,7 @@ class SSTemplateParser extends Parser {
|
||||
function OpenBlock__finalise(&$res) {
|
||||
$blockname = $res['BlockName']['text'];
|
||||
|
||||
$method = 'OpenBlock_Handle_'.ucfirst(strtolower($blockname));
|
||||
$method = 'OpenBlock_Handle_'.$blockname;
|
||||
if (method_exists($this, $method)) $res['php'] = $this->$method($res);
|
||||
else {
|
||||
throw new SSTemplateParseException('Unknown open block "'.$blockname.'" encountered. Perhaps you missed the closing tag or have mis-spelled it?', $this);
|
||||
@ -3104,9 +3105,9 @@ class SSTemplateParser extends Parser {
|
||||
|
||||
if($this->includeDebuggingComments) { // Add include filename comments on dev sites
|
||||
return
|
||||
'$val .= \'<!-- include '.$php.' -->\';'. "\n".
|
||||
'$val .= SSViewer::parse_template('.$php.', $scope->getItem());'. "\n".
|
||||
'$val .= \'<!-- end include '.$php.' -->\';'. "\n";
|
||||
'$val .= \'<!-- include '.addslashes($php).' -->\';'. "\n".
|
||||
'$val .= SSViewer::execute_template('.$php.', $scope->getItem());'. "\n".
|
||||
'$val .= \'<!-- end include '.addslashes($php).' -->\';'. "\n";
|
||||
}
|
||||
else {
|
||||
return
|
||||
@ -3930,7 +3931,8 @@ class SSTemplateParser extends Parser {
|
||||
$code = preg_replace('/(<html[^>]*>)/i', "\\1<!-- template $templateName -->", $code);
|
||||
$code = preg_replace('/(<\/html[^>]*>)/i', "<!-- end template $templateName -->\\1", $code);
|
||||
} else {
|
||||
$code = "<!-- template $templateName -->\n" . $code . "\n<!-- end template $templateName -->";
|
||||
$code = str_replace('<?php' . PHP_EOL, '<?php' . PHP_EOL . '$val .= \'<!-- template ' . $templateName . ' -->\';' . "\n", $code);
|
||||
$code .= "\n" . '$val .= \'<!-- end template ' . $templateName . ' -->\';';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -626,7 +626,7 @@ class SSTemplateParser extends Parser {
|
||||
function ClosedBlock__finalise(&$res) {
|
||||
$blockname = $res['BlockName']['text'];
|
||||
|
||||
$method = 'ClosedBlock_Handle_'.ucfirst(strtolower($blockname));
|
||||
$method = 'ClosedBlock_Handle_'.$blockname;
|
||||
if (method_exists($this, $method)) $res['php'] = $this->$method($res);
|
||||
else {
|
||||
throw new SSTemplateParseException('Unknown closed block "'.$blockname.'" encountered. Perhaps you are not supposed to close this block, or have mis-spelled it?', $this);
|
||||
@ -707,7 +707,7 @@ class SSTemplateParser extends Parser {
|
||||
function OpenBlock__finalise(&$res) {
|
||||
$blockname = $res['BlockName']['text'];
|
||||
|
||||
$method = 'OpenBlock_Handle_'.ucfirst(strtolower($blockname));
|
||||
$method = 'OpenBlock_Handle_'.$blockname;
|
||||
if (method_exists($this, $method)) $res['php'] = $this->$method($res);
|
||||
else {
|
||||
throw new SSTemplateParseException('Unknown open block "'.$blockname.'" encountered. Perhaps you missed the closing tag or have mis-spelled it?', $this);
|
||||
@ -725,9 +725,9 @@ class SSTemplateParser extends Parser {
|
||||
|
||||
if($this->includeDebuggingComments) { // Add include filename comments on dev sites
|
||||
return
|
||||
'$val .= \'<!-- include '.$php.' -->\';'. "\n".
|
||||
'$val .= SSViewer::parse_template('.$php.', $scope->getItem());'. "\n".
|
||||
'$val .= \'<!-- end include '.$php.' -->\';'. "\n";
|
||||
'$val .= \'<!-- include '.addslashes($php).' -->\';'. "\n".
|
||||
'$val .= SSViewer::execute_template('.$php.', $scope->getItem());'. "\n".
|
||||
'$val .= \'<!-- end include '.addslashes($php).' -->\';'. "\n";
|
||||
}
|
||||
else {
|
||||
return
|
||||
@ -919,7 +919,8 @@ class SSTemplateParser extends Parser {
|
||||
$code = preg_replace('/(<html[^>]*>)/i', "\\1<!-- template $templateName -->", $code);
|
||||
$code = preg_replace('/(<\/html[^>]*>)/i', "<!-- end template $templateName -->\\1", $code);
|
||||
} else {
|
||||
$code = "<!-- template $templateName -->\n" . $code . "\n<!-- end template $templateName -->";
|
||||
$code = str_replace('<?php' . PHP_EOL, '<?php' . PHP_EOL . '$val .= \'<!-- template ' . $templateName . ' -->\';' . "\n", $code);
|
||||
$code .= "\n" . '$val .= \'<!-- end template ' . $templateName . ' -->\';';
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user