move strip processing from parser to compiler

This commit is contained in:
Uwe Tews
2015-04-02 01:42:53 +02:00
parent e9fd2354ef
commit a92302d059
3 changed files with 1244 additions and 1198 deletions
@@ -218,6 +218,13 @@ abstract class Smarty_Internal_TemplateCompilerBase
*/
public $parent_compiler = null;
/**
* Strip preg pattern
*
* @var string
*/
public $stripRegEx = '![\t ]*[\r\n]+[\t ]*!';
/**
* method to compile a Smarty template
*
@@ -595,6 +602,27 @@ abstract class Smarty_Internal_TemplateCompilerBase
return '$_smarty_tpl->tpl_vars[' . $variable . ']->value';
}
/**
* This method is called from parser to process a text content section
* - remove text from inheritance child templates as they may generate output
* - strip text if strip is enabled
*
* @param string $text
*
* @return null|\Smarty_Internal_ParseTree_Text
*/
public function processText($text) {
if ($this->inheritance_child && !$this->blockTagNestingLevel) {
return null;
}
if ($this->parser->strip) {
return new Smarty_Internal_ParseTree_Text($this->parser, preg_replace($this->stripRegEx, '', $text));
} else {
return new Smarty_Internal_ParseTree_Text($this->parser, $text);
}
}
/**
* lazy loads internal compile plugin for tag and calls the compile method
* compile objects cached for reuse.