From eef42150b2c3301aec732e049574ec69affa527c Mon Sep 17 00:00:00 2001 From: bzick Date: Thu, 29 Aug 2013 11:29:34 +0400 Subject: [PATCH] 1.3.1 --- CHANGELOG.md | 6 ++++++ src/Fenom/Template.php | 32 ++++-------------------------- tests/TestCase.php | 7 +++++++ tests/cases/Fenom/TagsTest.php | 8 ++++---- tests/cases/Fenom/TemplateTest.php | 3 ++- 5 files changed, 23 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad3efdb..f8c4801 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 `$`. diff --git a/src/Fenom/Template.php b/src/Fenom/Template.php index 8b14288..128e530 100644 --- a/src/Fenom/Template.php +++ b/src/Fenom/Template.php @@ -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 .= "_name}:{$this->_line}: {$source} */\n $code ?>" . PHP_EOL; + $this->_body .= "_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('(')) { diff --git a/tests/TestCase.php b/tests/TestCase.php index 8d4b56f..f10c152 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -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"] : ""; diff --git a/tests/cases/Fenom/TagsTest.php b/tests/cases/Fenom/TagsTest.php index ade43e8..3cfea60 100644 --- a/tests/cases/Fenom/TagsTest.php +++ b/tests/cases/Fenom/TagsTest.php @@ -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() diff --git a/tests/cases/Fenom/TemplateTest.php b/tests/cases/Fenom/TemplateTest.php index d501f68..ec2a970 100644 --- a/tests/cases/Fenom/TemplateTest.php +++ b/tests/cases/Fenom/TemplateTest.php @@ -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()); }