mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Merge branch 'origin/master'
Conflicts: src/Fenom/Template.php tests/cases/Fenom/SandboxTest.php
This commit is contained in:
commit
83fbfb1fca
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,7 +1,6 @@
|
||||
.idea
|
||||
vendor
|
||||
build
|
||||
composer.lock
|
||||
composer.phar
|
||||
tests/resources/compile/*
|
||||
!.gitkeep
|
||||
|
@ -2,11 +2,12 @@ Fenom - Template Engine for PHP
|
||||
===============================
|
||||
|
||||
> Composer [package](https://packagist.org/packages/fenom/fenom): `{"fenom/fenom": "2.*"}`. <br />
|
||||
> For old version: `{"fenom/fenom": "1.*"}`. [List](https://github.com/bzick/fenom/wiki/Migrate-from-1.4.9-to-2.0) of incompatibilities between 1.* and 2.* versions.
|
||||
> For old version: `{"fenom/fenom": "1.*"}`. <br />
|
||||
> [List](https://github.com/fenom-template/fenom/wiki/Migrate-from-1.4.9-to-2.0) of incompatibilities between **1** and **2** versions.
|
||||
|
||||
[![Latest Stable Version](https://poser.pugx.org/fenom/fenom/v/stable.png)](https://packagist.org/packages/fenom/fenom)
|
||||
[![Build Status](https://travis-ci.org/bzick/fenom.svg?branch=master)](https://travis-ci.org/bzick/fenom)
|
||||
[![Coverage Status](https://img.shields.io/coveralls/bzick/fenom.svg)](https://coveralls.io/r/bzick/fenom?branch=master)
|
||||
[![Build Status](https://travis-ci.org/fenom-template/fenom.svg?branch=master)](https://travis-ci.org/fenom-template/fenom)
|
||||
[![Coverage Status](https://coveralls.io/repos/fenom-template/fenom/badge.svg?branch=master)](https://coveralls.io/r/fenom-template/fenom?branch=master)
|
||||
[![Total Downloads](https://poser.pugx.org/fenom/fenom/downloads.png)](https://packagist.org/packages/fenom/fenom)
|
||||
|
||||
## [Quick start](./docs/en/start.md) :: [Documentation](./docs/readme.md) [[en](./docs/en/readme.md)|[ru](./docs/ru/readme.md)] :: [Benchmark](./docs/en/benchmark.md)
|
||||
|
1275
composer.lock
generated
Normal file
1275
composer.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -212,7 +212,7 @@ To use octal notation, precede the number with a 0 (zero).
|
||||
To use hexadecimal notation precede the number with 0x.
|
||||
To use binary notation precede the number with 0b.
|
||||
|
||||
``smarty
|
||||
```smarty
|
||||
{var $a = 1234} decimal number
|
||||
{var $a = -123} a negative number
|
||||
{var $a = 0123} octal number (equivalent to 83 decimal)
|
||||
|
@ -63,8 +63,8 @@
|
||||
* [ematch](./mods/ematch.md) — проверяет соответствие регулярному выражению
|
||||
* [replace](./mods/replace.md) — заменяет все вхождения подстроки на строку замену
|
||||
* [ereplace](./mods/ereplace.md) — заменяет все соответсвия регулярному выражению на строку замену.
|
||||
* [split](./mods/split.md) — разивает строку по подстроке
|
||||
* [esplit](./mods/esplit.md) — разивает строку по регулярному выражению
|
||||
* [split](./mods/split.md) — разбивает строку по подстроке
|
||||
* [esplit](./mods/esplit.md) — разбивает строку по регулярному выражению
|
||||
* [join](./mods/join.md) — объединяет массив в строку
|
||||
* так же разрешены функции: `json_encode`, `json_decode`, `count`, `is_string`, `is_array`, `is_numeric`, `is_int`, `is_object`,
|
||||
`strtotime`, `gettype`, `is_double`, `ip2long`, `long2ip`, `strip_tags`, `nl2br`
|
||||
|
@ -352,7 +352,7 @@ Fenom предоставляет возможноть обращаться к ф
|
||||
{"User"|lower}} выведет "user"
|
||||
{$looong_text|truncate:80:"..."} обрежет текст до 80 символов и добавит символы "..."
|
||||
{$looong_text|lower|truncate:$settings.count:$settings.etc}
|
||||
{set $foo="Ivan"|upper} значение переменной $foo будет "USER"
|
||||
{set $foo="User"|upper} значение переменной $foo будет "USER"
|
||||
```
|
||||
|
||||
## Теги
|
||||
|
@ -38,7 +38,7 @@
|
||||
{import 'math.tpl'}
|
||||
```
|
||||
|
||||
При импорте можно указать дргое пространство имен что бы можно было использовать одноименные макросы из разных шаблонов
|
||||
При импорте можно указать другое пространство имен что бы можно было использовать одноименные макросы из разных шаблонов
|
||||
|
||||
```smarty
|
||||
{import 'math.tpl' as math}
|
||||
|
@ -674,6 +674,7 @@ class Template extends Render
|
||||
if($cond) {
|
||||
$term = array_pop($exp) . ' ' . $term;
|
||||
$term = '('. array_pop($exp) . ' ' . $term . ')';
|
||||
$var = false;
|
||||
}
|
||||
$term = $this->parseTernary($tokens, $term, $var);
|
||||
$var = false;
|
||||
@ -820,11 +821,16 @@ class Template extends Render
|
||||
if ($tokens->isSpecialVal()) {
|
||||
$code = $unary . $tokens->getAndNext();
|
||||
} elseif ($tokens->isNext("(") && !$tokens->getWhitespace()) {
|
||||
$func = $this->_fenom->getModifier($tokens->current(), $this);
|
||||
$func = $this->_fenom->getModifier($modifier = $tokens->current(), $this);
|
||||
if (!$func) {
|
||||
throw new \Exception("Function " . $tokens->getAndNext() . " not found");
|
||||
}
|
||||
$code = $unary . $this->parseChain($tokens, $func . $this->parseArgs($tokens->next()));
|
||||
if (!is_string($func)) { // dynamic modifier
|
||||
$call = 'call_user_func_array($tpl->getStorage()->getModifier("' . $modifier . '"), array'.$this->parseArgs($tokens->next()).')'; // @todo optimize
|
||||
} else {
|
||||
$call = $func . $this->parseArgs($tokens->next());
|
||||
}
|
||||
$code = $unary . $this->parseChain($tokens, $call);
|
||||
} elseif ($tokens->isNext(T_NS_SEPARATOR, T_DOUBLE_COLON)) {
|
||||
$method = $this->parseStatic($tokens);
|
||||
$args = $this->parseArgs($tokens);
|
||||
@ -1401,7 +1407,7 @@ class Template extends Render
|
||||
* (1 + 2.3, 'string', $var, [2,4])
|
||||
*
|
||||
* @param Tokenizer $tokens
|
||||
* @throws TokenizeException
|
||||
* @param bool $as_string
|
||||
* @return string
|
||||
*/
|
||||
public function parseArgs(Tokenizer $tokens)
|
||||
|
@ -119,10 +119,32 @@ class FenomTest extends \Fenom\TestCase
|
||||
public function testSetModifier()
|
||||
{
|
||||
$this->fenom->addModifier("mymod", "myMod");
|
||||
$this->tpl('custom.tpl', 'Custom modifier {$a|mymod}');
|
||||
$this->assertSame(
|
||||
$this->assertRender(
|
||||
'Custom modifier {$a|mymod}',
|
||||
"Custom modifier (myMod)Custom(/myMod)",
|
||||
$this->fenom->fetch('custom.tpl', array("a" => "Custom"))
|
||||
array("a" => "Custom")
|
||||
);
|
||||
$this->assertRender(
|
||||
'Custom modifier {mymod($a)}',
|
||||
"Custom modifier (myMod)Custom(/myMod)",
|
||||
array("a" => "Custom")
|
||||
);
|
||||
}
|
||||
|
||||
public function testSetModifierClosure()
|
||||
{
|
||||
$this->fenom->addModifier("mymod", function ($value) {
|
||||
return "(myMod)$value(/myMod)";
|
||||
});
|
||||
$this->assertRender(
|
||||
'Custom modifier {$a|mymod}',
|
||||
"Custom modifier (myMod)Custom(/myMod)",
|
||||
array("a" => "Custom")
|
||||
);
|
||||
$this->assertRender(
|
||||
'Custom modifier {mymod($a)}',
|
||||
"Custom modifier (myMod)Custom(/myMod)",
|
||||
array("a" => "Custom")
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user