Merge remote-tracking branch 'refs/remotes/origin/master' into develop

This commit is contained in:
bzick 2013-08-08 18:45:19 +04:00
commit ae34025ca7
7 changed files with 49 additions and 63 deletions

View File

@ -1,7 +1,15 @@
CHANGELOG
=========
## 1.2.0
### 1.2.2 (2013-08-07)
- Fix bug in setOptions method
### 1.2.1 (2013-08-06)
- Fix #39: compile error with boolean operators
## 1.2.0 (2013-08-05)
- Feature #28: macros may be called recursively
- Feature #29: add {unset} tag
@ -14,7 +22,11 @@ CHANGELOG
- Tests++
- Docs++
## 1.1.0
### 1.1.1 (2013-07-24)
- Bug fixes
## 1.1.0 (2013-07-22)
- Bug #19: Bug with "if" expressions starting with "("
- Bug #16: Allow modifiers for function calls
@ -36,49 +48,49 @@ CHANGELOG
- Docs++
- Test++
## 1.0.8
### 1.0.8 (2013-07-07)
- Perform auto_escape options
- Fix bugs
- Update documentation
## 1.0.7
### 1.0.7 (2013-07-07)
- Perform auto_escape options
- Fix bugs
## 1.0.6 (2013-07-04)
### 1.0.6 (2013-07-04)
- Fix modifiers insertions
## 1.0.5 (2013-07-04)
### 1.0.5 (2013-07-04)
- Add `Fenom::AUTO_ESCAPE` support (feature #2)
- Update documentation
## 1.0.4 (2013-06-27)
### 1.0.4 (2013-06-27)
- Add nested level for {extends} and {use}
- Small bug fix
- Update documentation
## 1.0.3 (2013-06-20)
### 1.0.3 (2013-06-20)
- Allow any callable for modifier (instead string)
- Bug fix
- Update documentation
## 1.0.2 (2013-06-18)
### 1.0.2 (2013-06-18)
- Optimize extends
- Bug fix
- Update documentation
## 1.0.1 (2013-05-30)
### 1.0.1 (2013-05-30)
- Bug fix
- comments don't work
## 1.0 (2013-05-30)
## 1.0.0 (2013-05-30)
- First release

View File

@ -3,7 +3,7 @@ Fenom - Template Engine for PHP
> Composer package: `{"fenom/fenom": "dev-master"}`. See on [Packagist.org](https://packagist.org/packages/bzick/fenom)
[![Build Status](https://travis-ci.org/bzick/fenom.png?branch=master)](https://travis-ci.org/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)
* Simple [syntax](./docs/syntax.md)

View File

@ -1,7 +1,7 @@
Tag {var} [RU]
==============
Tag {var}
=========
Тег {var} предназначен для создания переменных в шаблонах.
The tag {var} is used for assigning template variables during the execution of a template.
```smarty
{var $var=EXPR}
@ -19,8 +19,8 @@ Tag {var} [RU]
{/var}
```
К названию новой переменной предъявляются те же требования, что и к [именам переменных](http://www.php.net/manual/en/language.variables.basics.php) в PHP.
Выражение EXPR подразумевает любое поддерживаемое выражение.
Variable names follow the same rules as other labels in PHP.
A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores.
```smarty
{var $v = 5}
@ -34,18 +34,26 @@ Tag {var} [RU]
{var $v = $y-$x}
{var $v = $y*$x-2}
{var $v = ($y^$x)+7}
```
Присваивание массивов
Creating array
```smarty
{var $v = [1,2,3]}
{var $v = []}
{var $v = ["one"|upper => 1, 4 => $x, "three" => 3]}
{var $v = ["key1" => $y*$x-2, "key2" => ["z" => $z]]}
```
Присваивание результата выполнения функции
Getting function result into variable
```smarty
{var $v = count([1,2,3])+7}
```
Collect the output of the template into a variable
```smarty
{var $v}
Some long {$text|trim}
{/var}

View File

@ -216,11 +216,6 @@ class Fenom
'type' => self::INLINE_COMPILER,
'parser' => 'Fenom\Compiler::tagUse'
),
'capture' => array( // {capture ...} {/capture}
'type' => self::BLOCK_COMPILER,
'open' => 'Fenom\Compiler::captureOpen',
'close' => 'Fenom\Compiler::captureClose'
),
'filter' => array( // {filter} ... {/filter}
'type' => self::BLOCK_COMPILER,
'open' => 'Fenom\Compiler::filterOpen',
@ -853,7 +848,7 @@ class Fenom
{
foreach ($values as $key => $value) {
if (isset($options[$key])) {
if ($options[$key]) {
if ($value) {
$mask |= $options[$key];
} else {
$mask &= ~$options[$key];

View File

@ -648,6 +648,8 @@ class Template extends Render
break;
}
$cond = true;
} elseif ($tokens->is(Tokenizer::MACRO_BOOLEAN)) {
$cond = false;
}
$op = $tokens->getAndNext();
} elseif ($tokens->is(Tokenizer::MACRO_EQUALS)) { // assignment operator: $a = 4, $a += 3, ...
@ -1270,36 +1272,6 @@ class Template extends Render
throw new UnexpectedTokenException($tokens);
}
/**
* Parse constant
* #Ns\MyClass::CONST1, #CONST1, #MyClass::CONST1
*
* @param Tokenizer $tokens
* @return string
* @throws InvalidUsageException
*/
public function parseConst(Tokenizer $tokens)
{
$tokens->get('#');
$name = $tokens->getNext(T_STRING);
$tokens->next();
if ($tokens->is(T_NAMESPACE)) {
$name .= '\\';
$name .= $tokens->getNext(T_STRING);
$tokens->next();
}
if ($tokens->is(T_DOUBLE_COLON)) {
$name .= '::';
$name .= $tokens->getNext(T_STRING);
$tokens->next();
}
if (defined($name)) {
return $name;
} else {
throw new InvalidUsageException("Use undefined constant $name");
}
}
/**
* @param Tokenizer $tokens
* @param $name

View File

@ -274,6 +274,7 @@ class TemplateTest extends TestCase
array('if: {if true} block1 {else} block2 {/if} end', $a, 'if: block1 end'),
array('if: {if false} block1 {else} block2 {/if} end', $a, 'if: block2 end'),
array('if: {if null} block1 {else} block2 {/if} end', $a, 'if: block2 end'),
array('if: {if max(2, 4) > 1 && max(2, 3) < 1} block1 {else} block2 {/if} end', $a, 'if: block2 end'),
array('if: {if ($val1 || $val0) && $x} block1 {else} block2 {/if} end',
$a, 'if: block1 end'),
array('if: {if $unexist} block1 {else} block2 {/if} end', $a, 'if: block2 end', Fenom::FORCE_VERIFY),
@ -689,7 +690,7 @@ class TemplateTest extends TestCase
public function _testSandbox()
{
try {
var_dump($this->fenom->compileCode('{$a++~"hi"~time("Y:m:d")}')->getBody());
var_dump($this->fenom->compileCode('{if max(2, 4) > 1 && max(2, 3) < 1} block1 {else} block2 {/if}')->getBody());
} catch (\Exception $e) {
print_r($e->getMessage() . "\n" . $e->getTraceAsString());
}

View File

@ -109,27 +109,25 @@ class FenomTest extends \Fenom\TestCase
$this->fenom->setOptions($options);
$this->assertSame($this->fenom->getOptions(), $flags);
// printf("from %010b, flags %010b\n", $this->fenom->getOptions(), $flags);
// $this->fenom->setOptions(array($code => false));
// printf("remove %010b from option %010b, flags %010b\n", $option, $this->fenom->getOptions(), $flags & ~$option);
// $this->assertSame($this->fenom->getOptions(), $flags & ~$option);
$this->fenom->setOptions(array($code => false));
$this->assertSame($this->fenom->getOptions(), $flags & ~$option);
}
public function testFilter()
{
$punit = $this;
$this->fenom->addPreFilter(function ($src, $tpl) use ($punit) {
$this->assertInstanceOf('Fenom\Template', $tpl);
$punit->assertInstanceOf('Fenom\Template', $tpl);
return "== $src ==";
});
$this->fenom->addPostFilter(function ($code, $tpl) use ($punit) {
$this->assertInstanceOf('Fenom\Template', $tpl);
$punit->assertInstanceOf('Fenom\Template', $tpl);
return "+++ $code +++";
});
$this->fenom->addFilter(function ($text, $tpl) use ($punit) {
$this->assertInstanceOf('Fenom\Template', $tpl);
$punit->assertInstanceOf('Fenom\Template', $tpl);
return "|--- $text ---|";
});