This commit is contained in:
bzick 2013-08-29 11:29:34 +04:00
parent 270f90792a
commit eef42150b2
5 changed files with 23 additions and 33 deletions

View File

@ -1,6 +1,12 @@
CHANGELOG
=========
## 1.3.1 (2013-08-29)
- Bug: accessor don't work in modifier
- Removed too many EOL in template code
- Tests++
## 1.3.0 (2013-08-23)
- Feature #41: Add system variable `$`.

View File

@ -264,9 +264,6 @@ class Template extends Render
}
gc_collect_cycles();
// if($end < strlen($this->_src) && $this->_src[$end + 1] === "\n") {
// $end++;
// }
$this->_appendText(substr($this->_src, $end ? $end + 1 : 0)); // append tail of the template
if ($this->_stack) {
$_names = array();
@ -340,26 +337,6 @@ class Template extends Render
}
}
/**
* Append PHP_EOL after each '?>'
* @param int $code
* @return string
*/
private function _escapeCode($code)
{
$c = "";
foreach (token_get_all($code) as $token) {
if (is_string($token)) {
$c .= $token;
} elseif ($token[0] == T_CLOSE_TAG) {
$c .= $token[1] . PHP_EOL;
} else {
$c .= $token[1];
}
}
return $c;
}
/**
* Append PHP code to template body
*
@ -372,10 +349,7 @@ class Template extends Render
return;
} else {
$this->_line += substr_count($source, "\n");
if (strpos($code, '?>') !== false) {
$code = $this->_escapeCode($code); // paste PHP_EOL
}
$this->_body .= "<?php\n/* {$this->_name}:{$this->_line}: {$source} */\n $code ?>" . PHP_EOL;
$this->_body .= "<?php\n/* {$this->_name}:{$this->_line}: {$source} */\n $code ?>";
}
}
@ -1266,13 +1240,15 @@ class Template extends Render
$args = array();
while ($tokens->is(":")) {
$token = $tokens->getNext(Tokenizer::MACRO_SCALAR, T_VARIABLE, '"', Tokenizer::MACRO_STRING, "(", "[");
$token = $tokens->getNext(Tokenizer::MACRO_SCALAR, T_VARIABLE, '"', Tokenizer::MACRO_STRING, "(", "[", '$');
if ($tokens->is(Tokenizer::MACRO_SCALAR) || $tokens->isSpecialVal()) {
$args[] = $token;
$tokens->next();
} elseif ($tokens->is(T_VARIABLE)) {
$args[] = $this->parseVariable($tokens, self::DENY_MODS);
} elseif ($tokens->is('$')) {
$args[] = $this->parseAccessor($tokens, $is_var);
} elseif ($tokens->is('"', '`', T_ENCAPSED_AND_WHITESPACE)) {
$args[] = $this->parseQuote($tokens);
} elseif ($tokens->is('(')) {

View File

@ -56,6 +56,7 @@ class TestCase extends \PHPUnit_Framework_TestCase
$this->fenom = Fenom::factory(FENOM_RESOURCES . '/template', FENOM_RESOURCES . '/compile');
$this->fenom->addModifier('dots', __CLASS__ . '::dots');
$this->fenom->addModifier('concat', __CLASS__ . '::concat');
$this->fenom->addModifier('append', __CLASS__ . '::append');
$this->fenom->addFunction('test_function', __CLASS__ . '::inlineFunction');
$this->fenom->addBlockFunction('test_block_function', __CLASS__ . '::blockFunction');
}
@ -70,6 +71,12 @@ class TestCase extends \PHPUnit_Framework_TestCase
return call_user_func_array('var_export', func_get_args());
}
public static function append()
{
return implode("", func_get_args());
}
public static function inlineFunction($params)
{
return isset($params["text"]) ? $params["text"] : "";

View File

@ -9,7 +9,7 @@ class TagsTest extends TestCase
public function _testSandbox()
{
try {
var_dump($this->fenom->compileCode('{var $a=Fenom\TestCase::dots("asd")}')->getBody());
var_dump($this->fenom->compileCode("{var \$a=12313}\nVar: {\$a}")->getBody());
} catch (\Exception $e) {
echo "$e";
}
@ -21,7 +21,7 @@ class TagsTest extends TestCase
*/
public function testVar($tpl_val, $val)
{
$this->assertRender("{var \$a=$tpl_val}\nVar: {\$a}", "\nVar: " . $val);
$this->assertRender("{var \$a=$tpl_val}\nVar: {\$a}", "Var: " . $val);
}
/**
@ -29,7 +29,7 @@ class TagsTest extends TestCase
*/
public function testVarBlock($tpl_val, $val)
{
$this->assertRender("{var \$a}before {{$tpl_val}} after{/var}\nVar: {\$a}", "\nVar: before " . $val . " after");
$this->assertRender("{var \$a}before {{$tpl_val}} after{/var}\nVar: {\$a}", "Var: before " . $val . " after");
}
/**
@ -37,7 +37,7 @@ class TagsTest extends TestCase
*/
public function testVarBlockModified($tpl_val, $val)
{
$this->assertRender("{var \$a|low|dots}before {{$tpl_val}} after{/var}\nVar: {\$a}", "\nVar: " . strtolower("before " . $val . " after") . "...");
$this->assertRender("{var \$a|low|dots}before {{$tpl_val}} after{/var}\nVar: {\$a}", "Var: " . strtolower("before " . $val . " after") . "...");
}
public function testCycle()

View File

@ -708,6 +708,7 @@ class TemplateTest extends TestCase
array('{$.server.one}', 'server1'),
array('{$.const.PHP_EOL}', PHP_EOL),
array('{$.version}', Fenom::VERSION),
array('{"string"|append:"_":$.get.one}', 'string_get1'),
array('{$.get.one?}', '1'),
array('{$.get.one is set}', '1'),
@ -718,7 +719,7 @@ class TemplateTest extends TestCase
public function _testSandbox()
{
try {
var_dump($this->fenom->compileCode('{$.const.access?}')->getBody());
var_dump($this->fenom->compileCode('{"string"|append:$.get.one}')->getBody());
} catch (\Exception $e) {
print_r($e->getMessage() . "\n" . $e->getTraceAsString());
}