Merge branch 'master' into develop

This commit is contained in:
bzick 2013-08-30 10:26:27 +04:00
commit 3f77cdd099
8 changed files with 34 additions and 42 deletions

View File

@ -1,11 +1,19 @@
CHANGELOG
=========
## 1.3.0
## 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 `$`.
- 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--

View File

@ -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)

View File

@ -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)

View File

@ -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,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

@ -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());
}

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());
}