summaryrefslogtreecommitdiff
path: root/stupid_template_engine.php
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2012-01-15 13:04:03 +0100
committerKevin Chabowski <kevin@kch42.de>2012-01-15 13:04:03 +0100
commit8e35fad33de1fbecea7c29776f7afab6a4b88a48 (patch)
tree45140f6f610cc0481e5c6b0bc0eb932578bad972 /stupid_template_engine.php
parent7807fca367008ceaa8ff1b5a1b7f040520ee1cad (diff)
downloadste-8e35fad33de1fbecea7c29776f7afab6a4b88a48.tar.gz
ste-8e35fad33de1fbecea7c29776f7afab6a4b88a48.tar.bz2
ste-8e35fad33de1fbecea7c29776f7afab6a4b88a48.zip
Added builtin ste:get and fixed a code generation bug.
* ste:get allows us to get a variable's content dynamically. * (') was escaped for TextNodes, which resulted to: \' should have been: '
Diffstat (limited to 'stupid_template_engine.php')
-rw-r--r--stupid_template_engine.php11
1 files changed, 9 insertions, 2 deletions
diff --git a/stupid_template_engine.php b/stupid_template_engine.php
index 2e11ed4..48164c1 100644
--- a/stupid_template_engine.php
+++ b/stupid_template_engine.php
@@ -44,7 +44,7 @@ class VariableNode extends ASTNode
public $arrayfields;
public function transcompile()
{
- $varaccess = '@$ste->vars[' . (is_numeric($this->name) ? $this->name : '\'' . escape_text($this->name) . '\''). ']';
+ $varaccess = '@$ste->vars[' . (is_numeric($this->name) ? $this->name : '"' . escape_text($this->name) . '"'). ']';
foreach($this->arrayfields as $af)
{
if((count($af) == 1) and ($af[0] instanceof TextNode) and is_numeric($af->text))
@@ -778,6 +778,13 @@ $ste_builtins = array(
return $code;
},
+ "get" => function($ast)
+ {
+ if(empty($ast->params["var"]))
+ throw new ParseCompileError("Transcompile Error: var missing in <ste:get>.", $ast->tpl, $ast->offset);
+
+ return "\$outputstack[\$outputstack_i] .= \$ste->get_var_by_name(" . _transcompile($ast->params["var"], True) . ");";
+ },
"calc" => function($ast)
{
$code = "\$outputstack[] = '';\n\$outputstack_i++;\n";
@@ -790,7 +797,7 @@ $ste_builtins = array(
function escape_text($text)
{
- return addcslashes($text, "\r\n\t\$\0..\x1f\\'\"\x7f..\xff");
+ return addcslashes($text, "\r\n\t\$\0..\x1f\\\"\x7f..\xff");
}
function _transcompile($ast, $no_outputstack = False) /* The real transcompile function, does not add boilerplate code. */