summaryrefslogtreecommitdiff
path: root/stupid_template_engine.php
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2011-09-23 22:24:16 +0200
committerKevin Chabowski <kevin@kch42.de>2011-09-23 22:24:16 +0200
commit1619126d7d87538082dd58645a37f528adb1deeb (patch)
tree33a96610937ca591fa5bcac5aef556b8b2300c02 /stupid_template_engine.php
parentbc0ea34989618d8747076c322c14d0cd6af591b2 (diff)
downloadste-1619126d7d87538082dd58645a37f528adb1deeb.tar.gz
ste-1619126d7d87538082dd58645a37f528adb1deeb.tar.bz2
ste-1619126d7d87538082dd58645a37f528adb1deeb.zip
Added short syntag for comparison.
~{a|op|b} Also updated the documentation and made unescape_text() a alias of PHP's stripcslashes().
Diffstat (limited to 'stupid_template_engine.php')
-rw-r--r--stupid_template_engine.php11
1 files changed, 8 insertions, 3 deletions
diff --git a/stupid_template_engine.php b/stupid_template_engine.php
index d36352d..d88adb4 100644
--- a/stupid_template_engine.php
+++ b/stupid_template_engine.php
@@ -83,8 +83,7 @@ function find_closing_bracket($text, $opening, $closing)
function unescape_text($text)
{
- $text = preg_replace("/(?:(?<!\\\\)\\\\\\\$)/s", "$", $text);
- return str_replace("\\\\", "\\", $text);
+ return stripcslashes($text);
}
function tokenize_text($text)
@@ -233,13 +232,19 @@ function parse($code)
{
/* Precompiling... */
$code = preg_replace("/\\<\\s*ste:comment\\s*\\>.*?\\<\\s*\\/\\s*ste:comment\\s*\\>/s", "", $code); /* Remove comments */
+ $code = preg_replace( /* Transform short form of comparison (~{a|op|b}) to long form */
+ "/(?:(?<!\\\\)~)(?:(?<!\\\\)\\{)(.*?)(?:(?<!\\\\)\\|)(.*?)(?:(?<!\\\\)\\|)(.*?)(?:(?<!\\\\)\\})/s",
+ "<ste:cmp text_a=\"\$1\" op=\"\$2\" text_b=\"\$3\" />",
+ $code
+ );
$code = preg_replace( /* Transform short form of if-clause (?{cond|then|else}) to long form */
"/(?:(?<!\\\\)\\?)(?:(?<!\\\\)\\{)(.*?)(?:(?<!\\\\)\\|)(.*?)(?:(?<!\\\\)\\|)(.*?)(?:(?<!\\\\)\\})/s",
"<ste:if>\$1<ste:then>\$2</ste:then><ste:else>\$3</ste:else></ste:if>",
$code
);
- /* Unescape \? \{ \} \| */
+ /* Unescape \? \~ \{ \} \| */
$code = preg_replace("/(?:(?<!\\\\)\\\\\\?)/s", "?", $code);
+ $code = preg_replace("/(?:(?<!\\\\)\\\\~)/s", "~", $code);
$code = preg_replace("/(?:(?<!\\\\)\\\\\\{)/s", "{", $code);
$code = preg_replace("/(?:(?<!\\\\)\\\\\\})/s", "}", $code);
$code = preg_replace("/(?:(?<!\\\\)\\\\\\|)/s", "|", $code);