Commit 77501e61 by Seldaek

git-svn-id: svn://dwoo.org/dwoo/trunk@103 0598d79b-80c4-4d41-97ba-ac86fbbd088b

parent 8d7eeff5
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
*/ */
class Dwoo_Plugin_strip extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block class Dwoo_Plugin_strip extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block
{ {
public function init($type = 'text') public function init()
{ {
} }
...@@ -33,18 +33,8 @@ class Dwoo_Plugin_strip extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Bl ...@@ -33,18 +33,8 @@ class Dwoo_Plugin_strip extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Bl
public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content) public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
{ {
$params = $compiler->getCompiledParams($params); $params = $compiler->getCompiledParams($params);
switch (trim($params['type'], '"\'')) { $content = preg_replace(array("/\n/","/\r/",'/(<\?(?:php)?|<%)\s*/'), array('','','$1 '), preg_replace('#^\s*(.+?)\s*$#m', '$1', $content));
case 'code':
$content = preg_replace('/\{[\r\n]+/', '{ ', preg_replace('#^\s*(.+?)\s*$#m', '$1', $content));
$content = str_replace(array("\n","\r"), null, $content);
break;
case 'text':
default:
$content = str_replace(array("\n","\r"), null, preg_replace('#^\s*(.+?)\s*$#m', '$1', $content));
}
return $content; return $content;
} }
......
...@@ -18,7 +18,7 @@ class BlockTests extends PHPUnit_Framework_TestCase ...@@ -18,7 +18,7 @@ class BlockTests extends PHPUnit_Framework_TestCase
{ {
$cmp = new Dwoo_Compiler(); $cmp = new Dwoo_Compiler();
$cmp->setAutoEscape(true); $cmp->setAutoEscape(true);
$tpl = new Dwoo_Template_String('{$foo}{auto_escape off}{$foo}{/}'); $tpl = new Dwoo_Template_String('{$foo}{auto_escape off}{$foo}{/}');
$tpl->forceCompilation(); $tpl->forceCompilation();
...@@ -28,7 +28,7 @@ class BlockTests extends PHPUnit_Framework_TestCase ...@@ -28,7 +28,7 @@ class BlockTests extends PHPUnit_Framework_TestCase
$tpl->forceCompilation(); $tpl->forceCompilation();
$this->assertEquals("a<b>ca&lt;b&gt;c", $this->dwoo->get($tpl, array('foo'=>'a<b>c'))); $this->assertEquals("a<b>ca&lt;b&gt;c", $this->dwoo->get($tpl, array('foo'=>'a<b>c')));
// fixes the init call not being called (which is normal) // fixes the init call not being called (which is normal)
$fixCall = new Dwoo_Plugin_auto_escape($this->dwoo); $fixCall = new Dwoo_Plugin_auto_escape($this->dwoo);
$fixCall->init(''); $fixCall->init('');
...@@ -61,7 +61,7 @@ class BlockTests extends PHPUnit_Framework_TestCase ...@@ -61,7 +61,7 @@ class BlockTests extends PHPUnit_Framework_TestCase
$fixCall = new Dwoo_Plugin_capture($this->dwoo); $fixCall = new Dwoo_Plugin_capture($this->dwoo);
$fixCall->init(''); $fixCall->init('');
} }
public function testDynamic() public function testDynamic()
{ {
$preTime = time(); $preTime = time();
...@@ -69,7 +69,7 @@ class BlockTests extends PHPUnit_Framework_TestCase ...@@ -69,7 +69,7 @@ class BlockTests extends PHPUnit_Framework_TestCase
$tpl->forceCompilation(); $tpl->forceCompilation();
$this->assertEquals($preTime . $preTime, $this->dwoo->get($tpl, array('pre'=>$preTime), $this->compiler)); $this->assertEquals($preTime . $preTime, $this->dwoo->get($tpl, array('pre'=>$preTime), $this->compiler));
sleep(1); sleep(1);
$postTime = time(); $postTime = time();
$this->assertEquals($preTime . $postTime, $this->dwoo->get($tpl, array('pre'=>$postTime), $this->compiler)); $this->assertEquals($preTime . $postTime, $this->dwoo->get($tpl, array('pre'=>$postTime), $this->compiler));
...@@ -348,14 +348,11 @@ baz")); ...@@ -348,14 +348,11 @@ baz"));
$this->assertEquals("abca\nb\nc", $this->dwoo->get($tpl, array(), $this->compiler)); $this->assertEquals("abca\nb\nc", $this->dwoo->get($tpl, array(), $this->compiler));
} }
public function testStripCode() public function testStripWithPhp()
{ {
$tpl = new Dwoo_Template_String("{strip code} $tpl = new Dwoo_Template_String("{strip}a\nb{\$foo=\"\\n\"}{if \$foo}>{\$foo}<{/if}\nc{/strip}a\nb\nc");
function foo() {
x;
}");
$tpl->forceCompilation(); $tpl->forceCompilation();
$this->assertEquals("function foo() { x;}", $this->dwoo->get($tpl, array(), $this->compiler)); $this->assertEquals("ab>\n<ca\nb\nc", $this->dwoo->get($tpl, array(), $this->compiler));
} }
public function testTextFormat() public function testTextFormat()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment