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

View File

@@ -369,12 +369,16 @@ template_element(res)::= XMLTAG. {
}
// template text
template_element(res)::= TEXT(o). {
if ($this->strip) {
res = new Smarty_Internal_ParseTree_Text($this, preg_replace('![\t ]*[\r\n]+[\t ]*!', '', o));
} else {
res = new Smarty_Internal_ParseTree_Text($this, o);
}
template_element(res)::= text_content(t). {
res = $this->compiler->processText(t);
}
text_content(res) ::= TEXT(o). {
res = o;
}
text_content(res) ::= text_content(t) TEXT(o). {
res = t . o;
}
// strip on

View File

@@ -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.

File diff suppressed because it is too large Load Diff