From 07ee1a479d74f8bd20972fb1ff9b977be2651a72 Mon Sep 17 00:00:00 2001 From: Dmitri Perunov Date: Mon, 12 Aug 2013 12:38:31 -0700 Subject: [PATCH 1/6] Fix packagist.org's project url --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e9bebe1..6e30b61 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Fenom - Template Engine for PHP =============================== -> Composer package: `{"fenom/fenom": "dev-master"}`. See on [Packagist.org](https://packagist.org/packages/bzick/fenom) +> Composer package: `{"fenom/fenom": "dev-master"}`. See on [Packagist.org](https://packagist.org/packages/fenom/fenom) [![Build Status](https://travis-ci.org/bzick/fenom.png?branch=master)](https://travis-ci.org/bzick/fenom) ## [Usage](./docs/usage.md) :: [Documentation](./docs/readme.md) :: [Benchmark](./docs/benchmark.md) :: [Articles](./docs/articles.md) From 712e8319a6b0ad1c20344a753c34b558efec73db Mon Sep 17 00:00:00 2001 From: bzick Date: Fri, 23 Aug 2013 01:00:06 +0400 Subject: [PATCH 2/6] Upd CHANGELOG.md --- CHANGELOG.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0f3856..ad3efdb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,13 @@ CHANGELOG ========= -## 1.3.0 +## 1.3.0 (2013-08-23) - Feature #41: Add system variable `$`. -- Fix bug when recursive macros doesn't work in Template +- Fix bug when recursive macros doesn't work in `Fenom\Template` - Recognize variable parser +- Recognize macros parser +- Fix `auto_reload` option - Tests++ - Docs-- From 418fbed53702ed222fc5af16a0e64faaf86d3dbc Mon Sep 17 00:00:00 2001 From: bzick Date: Fri, 23 Aug 2013 01:02:49 +0400 Subject: [PATCH 3/6] Fix texts for 5.3 --- tests/cases/Fenom/MacrosTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/cases/Fenom/MacrosTest.php b/tests/cases/Fenom/MacrosTest.php index 06551ef..e777dd0 100644 --- a/tests/cases/Fenom/MacrosTest.php +++ b/tests/cases/Fenom/MacrosTest.php @@ -65,8 +65,8 @@ class MacrosTest extends TestCase // $this->fenom->compile("macro_recursive.tpl")->display([]); // $this->fenom->flush(); // var_dump($this->fenom->fetch("macro_recursive.tpl", [])); - var_dump( $this->fenom->compile("macro_recursive_import.tpl")->display([])); - var_dump( $this->fenom->display("macro_recursive_import.tpl", [])); + var_dump( $this->fenom->compile("macro_recursive_import.tpl")->display(array())); + var_dump( $this->fenom->display("macro_recursive_import.tpl", array())); } catch (\Exception $e) { var_dump($e->getMessage() . ": " . $e->getTraceAsString()); } From 270f90792a4f0397c53ff22d15e182a204515c3f Mon Sep 17 00:00:00 2001 From: bzick Date: Fri, 23 Aug 2013 01:06:47 +0400 Subject: [PATCH 4/6] Disable buggy trim --- src/Fenom/Template.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Fenom/Template.php b/src/Fenom/Template.php index 033e32f..8b14288 100644 --- a/src/Fenom/Template.php +++ b/src/Fenom/Template.php @@ -224,9 +224,9 @@ class Template extends Render break; default: // var_dump($this->_src[$pos]); - if($this->_src[$pos] === "\n") { - $pos++; - } +// if($this->_src[$pos] === "\n") { +// $pos++; +// } $this->_appendText(substr($this->_src, $pos, $start - $pos)); $end = $start + 1; do { @@ -264,9 +264,9 @@ class Template extends Render } gc_collect_cycles(); - if($end < strlen($this->_src) && $this->_src[$end + 1] === "\n") { - $end++; - } +// 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(); From d5b45756980a7b0f8d07a0da4fc77089c9395f43 Mon Sep 17 00:00:00 2001 From: Ivan Shalganov Date: Fri, 23 Aug 2013 14:09:54 +0400 Subject: [PATCH 5/6] Update readme.md --- docs/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/readme.md b/docs/readme.md index d697f00..3bc093a 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -6,7 +6,7 @@ Documentation * [Install](./install.md) * [Usage](./usage.md) * [Fenom adapters](./adapters.md) -* [Develop](./develop.md) +* [Develop](./dev/readme.md) * [Settings](./settings.md) * [Callbacks and filters](./callbacks.md) * [Syntax](./syntax.md) From eef42150b2c3301aec732e049574ec69affa527c Mon Sep 17 00:00:00 2001 From: bzick Date: Thu, 29 Aug 2013 11:29:34 +0400 Subject: [PATCH 6/6] 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()); }