mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Merge remote-tracking branch 'refs/remotes/origin/master' into develop
This commit is contained in:
commit
ae34025ca7
34
CHANGELOG.md
34
CHANGELOG.md
@ -1,7 +1,15 @@
|
|||||||
CHANGELOG
|
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 #28: macros may be called recursively
|
||||||
- Feature #29: add {unset} tag
|
- Feature #29: add {unset} tag
|
||||||
@ -14,7 +22,11 @@ CHANGELOG
|
|||||||
- Tests++
|
- Tests++
|
||||||
- Docs++
|
- 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 #19: Bug with "if" expressions starting with "("
|
||||||
- Bug #16: Allow modifiers for function calls
|
- Bug #16: Allow modifiers for function calls
|
||||||
@ -36,49 +48,49 @@ CHANGELOG
|
|||||||
- Docs++
|
- Docs++
|
||||||
- Test++
|
- Test++
|
||||||
|
|
||||||
## 1.0.8
|
### 1.0.8 (2013-07-07)
|
||||||
|
|
||||||
- Perform auto_escape options
|
- Perform auto_escape options
|
||||||
- Fix bugs
|
- Fix bugs
|
||||||
- Update documentation
|
- Update documentation
|
||||||
|
|
||||||
## 1.0.7
|
### 1.0.7 (2013-07-07)
|
||||||
|
|
||||||
- Perform auto_escape options
|
- Perform auto_escape options
|
||||||
- Fix bugs
|
- Fix bugs
|
||||||
|
|
||||||
## 1.0.6 (2013-07-04)
|
### 1.0.6 (2013-07-04)
|
||||||
|
|
||||||
- Fix modifiers insertions
|
- Fix modifiers insertions
|
||||||
|
|
||||||
## 1.0.5 (2013-07-04)
|
### 1.0.5 (2013-07-04)
|
||||||
|
|
||||||
- Add `Fenom::AUTO_ESCAPE` support (feature #2)
|
- Add `Fenom::AUTO_ESCAPE` support (feature #2)
|
||||||
- Update documentation
|
- Update documentation
|
||||||
|
|
||||||
## 1.0.4 (2013-06-27)
|
### 1.0.4 (2013-06-27)
|
||||||
|
|
||||||
- Add nested level for {extends} and {use}
|
- Add nested level for {extends} and {use}
|
||||||
- Small bug fix
|
- Small bug fix
|
||||||
- Update documentation
|
- Update documentation
|
||||||
|
|
||||||
## 1.0.3 (2013-06-20)
|
### 1.0.3 (2013-06-20)
|
||||||
|
|
||||||
- Allow any callable for modifier (instead string)
|
- Allow any callable for modifier (instead string)
|
||||||
- Bug fix
|
- Bug fix
|
||||||
- Update documentation
|
- Update documentation
|
||||||
|
|
||||||
## 1.0.2 (2013-06-18)
|
### 1.0.2 (2013-06-18)
|
||||||
|
|
||||||
- Optimize extends
|
- Optimize extends
|
||||||
- Bug fix
|
- Bug fix
|
||||||
- Update documentation
|
- Update documentation
|
||||||
|
|
||||||
## 1.0.1 (2013-05-30)
|
### 1.0.1 (2013-05-30)
|
||||||
|
|
||||||
- Bug fix
|
- Bug fix
|
||||||
- comments don't work
|
- comments don't work
|
||||||
|
|
||||||
## 1.0 (2013-05-30)
|
## 1.0.0 (2013-05-30)
|
||||||
|
|
||||||
- First release
|
- First release
|
||||||
|
@ -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)
|
> Composer package: `{"fenom/fenom": "dev-master"}`. See on [Packagist.org](https://packagist.org/packages/bzick/fenom)
|
||||||
|
|
||||||
[](https://travis-ci.org/fenom/fenom)
|
[](https://travis-ci.org/bzick/fenom)
|
||||||
## [Usage](./docs/usage.md) :: [Documentation](./docs/readme.md) :: [Benchmark](./docs/benchmark.md) :: [Articles](./docs/articles.md)
|
## [Usage](./docs/usage.md) :: [Documentation](./docs/readme.md) :: [Benchmark](./docs/benchmark.md) :: [Articles](./docs/articles.md)
|
||||||
|
|
||||||
* Simple [syntax](./docs/syntax.md)
|
* Simple [syntax](./docs/syntax.md)
|
||||||
|
@ -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
|
```smarty
|
||||||
{var $var=EXPR}
|
{var $var=EXPR}
|
||||||
@ -19,8 +19,8 @@ Tag {var} [RU]
|
|||||||
{/var}
|
{/var}
|
||||||
```
|
```
|
||||||
|
|
||||||
К названию новой переменной предъявляются те же требования, что и к [именам переменных](http://www.php.net/manual/en/language.variables.basics.php) в PHP.
|
Variable names follow the same rules as other labels in PHP.
|
||||||
Выражение EXPR подразумевает любое поддерживаемое выражение.
|
A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores.
|
||||||
|
|
||||||
```smarty
|
```smarty
|
||||||
{var $v = 5}
|
{var $v = 5}
|
||||||
@ -34,18 +34,26 @@ Tag {var} [RU]
|
|||||||
{var $v = $y-$x}
|
{var $v = $y-$x}
|
||||||
{var $v = $y*$x-2}
|
{var $v = $y*$x-2}
|
||||||
{var $v = ($y^$x)+7}
|
{var $v = ($y^$x)+7}
|
||||||
|
```
|
||||||
|
|
||||||
Присваивание массивов
|
Creating array
|
||||||
|
|
||||||
|
```smarty
|
||||||
{var $v = [1,2,3]}
|
{var $v = [1,2,3]}
|
||||||
{var $v = []}
|
{var $v = []}
|
||||||
{var $v = ["one"|upper => 1, 4 => $x, "three" => 3]}
|
{var $v = ["one"|upper => 1, 4 => $x, "three" => 3]}
|
||||||
{var $v = ["key1" => $y*$x-2, "key2" => ["z" => $z]]}
|
{var $v = ["key1" => $y*$x-2, "key2" => ["z" => $z]]}
|
||||||
|
```
|
||||||
|
|
||||||
Присваивание результата выполнения функции
|
Getting function result into variable
|
||||||
|
|
||||||
|
```smarty
|
||||||
{var $v = count([1,2,3])+7}
|
{var $v = count([1,2,3])+7}
|
||||||
|
```
|
||||||
|
|
||||||
|
Collect the output of the template into a variable
|
||||||
|
|
||||||
|
```smarty
|
||||||
{var $v}
|
{var $v}
|
||||||
Some long {$text|trim}
|
Some long {$text|trim}
|
||||||
{/var}
|
{/var}
|
||||||
|
@ -216,11 +216,6 @@ class Fenom
|
|||||||
'type' => self::INLINE_COMPILER,
|
'type' => self::INLINE_COMPILER,
|
||||||
'parser' => 'Fenom\Compiler::tagUse'
|
'parser' => 'Fenom\Compiler::tagUse'
|
||||||
),
|
),
|
||||||
'capture' => array( // {capture ...} {/capture}
|
|
||||||
'type' => self::BLOCK_COMPILER,
|
|
||||||
'open' => 'Fenom\Compiler::captureOpen',
|
|
||||||
'close' => 'Fenom\Compiler::captureClose'
|
|
||||||
),
|
|
||||||
'filter' => array( // {filter} ... {/filter}
|
'filter' => array( // {filter} ... {/filter}
|
||||||
'type' => self::BLOCK_COMPILER,
|
'type' => self::BLOCK_COMPILER,
|
||||||
'open' => 'Fenom\Compiler::filterOpen',
|
'open' => 'Fenom\Compiler::filterOpen',
|
||||||
@ -853,7 +848,7 @@ class Fenom
|
|||||||
{
|
{
|
||||||
foreach ($values as $key => $value) {
|
foreach ($values as $key => $value) {
|
||||||
if (isset($options[$key])) {
|
if (isset($options[$key])) {
|
||||||
if ($options[$key]) {
|
if ($value) {
|
||||||
$mask |= $options[$key];
|
$mask |= $options[$key];
|
||||||
} else {
|
} else {
|
||||||
$mask &= ~$options[$key];
|
$mask &= ~$options[$key];
|
||||||
|
@ -648,6 +648,8 @@ class Template extends Render
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$cond = true;
|
$cond = true;
|
||||||
|
} elseif ($tokens->is(Tokenizer::MACRO_BOOLEAN)) {
|
||||||
|
$cond = false;
|
||||||
}
|
}
|
||||||
$op = $tokens->getAndNext();
|
$op = $tokens->getAndNext();
|
||||||
} elseif ($tokens->is(Tokenizer::MACRO_EQUALS)) { // assignment operator: $a = 4, $a += 3, ...
|
} elseif ($tokens->is(Tokenizer::MACRO_EQUALS)) { // assignment operator: $a = 4, $a += 3, ...
|
||||||
@ -1270,36 +1272,6 @@ class Template extends Render
|
|||||||
throw new UnexpectedTokenException($tokens);
|
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 Tokenizer $tokens
|
||||||
* @param $name
|
* @param $name
|
||||||
|
@ -274,6 +274,7 @@ class TemplateTest extends TestCase
|
|||||||
array('if: {if true} block1 {else} block2 {/if} end', $a, 'if: block1 end'),
|
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 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 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',
|
array('if: {if ($val1 || $val0) && $x} block1 {else} block2 {/if} end',
|
||||||
$a, 'if: block1 end'),
|
$a, 'if: block1 end'),
|
||||||
array('if: {if $unexist} block1 {else} block2 {/if} end', $a, 'if: block2 end', Fenom::FORCE_VERIFY),
|
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()
|
public function _testSandbox()
|
||||||
{
|
{
|
||||||
try {
|
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) {
|
} catch (\Exception $e) {
|
||||||
print_r($e->getMessage() . "\n" . $e->getTraceAsString());
|
print_r($e->getMessage() . "\n" . $e->getTraceAsString());
|
||||||
}
|
}
|
||||||
|
@ -109,27 +109,25 @@ class FenomTest extends \Fenom\TestCase
|
|||||||
|
|
||||||
$this->fenom->setOptions($options);
|
$this->fenom->setOptions($options);
|
||||||
$this->assertSame($this->fenom->getOptions(), $flags);
|
$this->assertSame($this->fenom->getOptions(), $flags);
|
||||||
// printf("from %010b, flags %010b\n", $this->fenom->getOptions(), $flags);
|
$this->fenom->setOptions(array($code => false));
|
||||||
// $this->fenom->setOptions(array($code => false));
|
$this->assertSame($this->fenom->getOptions(), $flags & ~$option);
|
||||||
// printf("remove %010b from option %010b, flags %010b\n", $option, $this->fenom->getOptions(), $flags & ~$option);
|
|
||||||
// $this->assertSame($this->fenom->getOptions(), $flags & ~$option);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFilter()
|
public function testFilter()
|
||||||
{
|
{
|
||||||
$punit = $this;
|
$punit = $this;
|
||||||
$this->fenom->addPreFilter(function ($src, $tpl) use ($punit) {
|
$this->fenom->addPreFilter(function ($src, $tpl) use ($punit) {
|
||||||
$this->assertInstanceOf('Fenom\Template', $tpl);
|
$punit->assertInstanceOf('Fenom\Template', $tpl);
|
||||||
return "== $src ==";
|
return "== $src ==";
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->fenom->addPostFilter(function ($code, $tpl) use ($punit) {
|
$this->fenom->addPostFilter(function ($code, $tpl) use ($punit) {
|
||||||
$this->assertInstanceOf('Fenom\Template', $tpl);
|
$punit->assertInstanceOf('Fenom\Template', $tpl);
|
||||||
return "+++ $code +++";
|
return "+++ $code +++";
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->fenom->addFilter(function ($text, $tpl) use ($punit) {
|
$this->fenom->addFilter(function ($text, $tpl) use ($punit) {
|
||||||
$this->assertInstanceOf('Fenom\Template', $tpl);
|
$punit->assertInstanceOf('Fenom\Template', $tpl);
|
||||||
return "|--- $text ---|";
|
return "|--- $text ---|";
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user