summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2013-10-20 22:14:18 +0200
committerKevin Chabowski <kevin@kch42.de>2013-10-20 22:14:18 +0200
commitb2c464d6e3b4fa91eca3a80985150ee100713b9f (patch)
treec66111c3bcdf47e3e9606590d0f7a4325700a385
parent5401ff08a26e11649d282c5c8fe11d9d8c199c53 (diff)
downloadste-b2c464d6e3b4fa91eca3a80985150ee100713b9f.tar.gz
ste-b2c464d6e3b4fa91eca3a80985150ee100713b9f.tar.bz2
ste-b2c464d6e3b4fa91eca3a80985150ee100713b9f.zip
tidyup_ast improved
-rw-r--r--stupid_template_engine.php53
1 files changed, 28 insertions, 25 deletions
diff --git a/stupid_template_engine.php b/stupid_template_engine.php
index 1cd21fc..386f760 100644
--- a/stupid_template_engine.php
+++ b/stupid_template_engine.php
@@ -218,37 +218,40 @@ class Parser {
$out = array();
$prevtext = NULL;
- $first = true;
+ $wastag = true;
foreach($ast as $node) {
- if($node instanceof TagNode) {
- $node->sub = self::tidyup_ast($node->sub);
- }
-
- if(!($node instanceof TextNode)) {
- if($prevtext !== NULL) {
- if($prevtext->text != "") {
- $out[] = $prevtext;
- }
- $prevtext = NULL;
+ if($node instanceof TextNode) {
+ if($wastag) {
+ $node->text = ltrim($node->text);
}
- $out[] = $node;
-
- $first = false;
- continue;
- }
-
- if($first) {
- $node->text = ltrim($node->text);
- }
-
- if($prevtext !== NULL) {
- $prevtext->text .= $node->text;
+ if($prevtext === NULL) {
+ $prevtext = $node;
+ } else {
+ $prevtext->text .= $node->text;
+ }
} else {
- $prevtext = $node;
+ if(($prevtext !== NULL) && ($prevtext->text != "")) {
+ $out[] = $prevtext;
+ }
+ $prevtext = NULL;
+
+ if($node instanceof TagNode) {
+ $node->sub = self::tidyup_ast($node->sub);
+ foreach($node->params as $k => &$v) {
+ $v = self::tidyup_ast($v);
+ }
+ unset($v);
+ } else { /* VariableNode */
+ foreach($node->arrayfields as &$v) {
+ $v = self::tidyup_ast($v);
+ }
+ unset($v);
+ }
+ $out[] = $node;
}
- $first = false;
+ $wastag = $node instanceof TagNode;
}
if(($prevtext !== NULL) && ($prevtext->text != "")) {