mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Done #228
This commit is contained in:
parent
d23e2b4c4f
commit
dec06c888e
9
docs/en/tags/do.md
Normal file
9
docs/en/tags/do.md
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
Tag {do}
|
||||||
|
========
|
||||||
|
|
||||||
|
Evaluates any expression and doesn't print anything
|
||||||
|
|
||||||
|
```smarty
|
||||||
|
{do $count++}
|
||||||
|
{do $object->method()}
|
||||||
|
```
|
9
docs/ru/tags/do.md
Normal file
9
docs/ru/tags/do.md
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
Тег {do}
|
||||||
|
========
|
||||||
|
|
||||||
|
Выполнить произвольноые выражение без вывода результата на экран
|
||||||
|
|
||||||
|
```smarty
|
||||||
|
{do $count++}
|
||||||
|
{do $object->method()}
|
||||||
|
```
|
@ -7,10 +7,7 @@ require_once __DIR__.'/../tests/tools.php';
|
|||||||
|
|
||||||
$fenom = Fenom::factory(__DIR__.'/templates', __DIR__.'/../tests/resources/compile');
|
$fenom = Fenom::factory(__DIR__.'/templates', __DIR__.'/../tests/resources/compile');
|
||||||
$fenom->setOptions(Fenom::AUTO_RELOAD);
|
$fenom->setOptions(Fenom::AUTO_RELOAD);
|
||||||
$fenom->addModifier('firstimg', function ($img) {
|
var_dump($fenom->compileCode('{do $object->method()}')->getTemplateCode());
|
||||||
return $img;
|
|
||||||
});
|
|
||||||
var_dump($fenom->compileCode('{foreach $list as $k => $e last=$l first=$f index=$i} {if $f}first{/if} {$i}: {$k} => {$e}, {if $l}last{/if} {/foreach}')->getTemplateCode());
|
|
||||||
//var_dump($fenom->compile("bug158/main.tpl", [])->getTemplateCode());
|
//var_dump($fenom->compile("bug158/main.tpl", [])->getTemplateCode());
|
||||||
//var_dump($fenom->display("bug158/main.tpl", []));
|
//var_dump($fenom->display("bug158/main.tpl", []));
|
||||||
// $fenom->getTemplate("problem.tpl");
|
// $fenom->getTemplate("problem.tpl");
|
@ -272,6 +272,10 @@ class Fenom
|
|||||||
'open' => 'Fenom\Compiler::setOpen',
|
'open' => 'Fenom\Compiler::setOpen',
|
||||||
'close' => 'Fenom\Compiler::setClose'
|
'close' => 'Fenom\Compiler::setClose'
|
||||||
),
|
),
|
||||||
|
'do' => array( // {do ...}
|
||||||
|
'type' => self::INLINE_COMPILER,
|
||||||
|
'parser' => 'Fenom\Compiler::tagDo'
|
||||||
|
),
|
||||||
'block' => array( // {block ...} {parent} {/block}
|
'block' => array( // {block ...} {parent} {/block}
|
||||||
'type' => self::BLOCK_COMPILER,
|
'type' => self::BLOCK_COMPILER,
|
||||||
'open' => 'Fenom\Compiler::tagBlockOpen',
|
'open' => 'Fenom\Compiler::tagBlockOpen',
|
||||||
|
@ -813,6 +813,11 @@ class Compiler
|
|||||||
return $scope["name"] . '=' . $scope["value"] . ';';
|
return $scope["name"] . '=' . $scope["value"] . ';';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function tagDo($tokens, Tag $scope)
|
||||||
|
{
|
||||||
|
return $scope->tpl->parseExpr($tokens).';';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Tokenizer $tokens
|
* @param Tokenizer $tokens
|
||||||
|
@ -23,7 +23,8 @@ class RangeIterator implements \Iterator, \Countable
|
|||||||
* @param int $step
|
* @param int $step
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setStep($step) {
|
public function setStep($step)
|
||||||
|
{
|
||||||
if($step > 0) {
|
if($step > 0) {
|
||||||
$this->current = min($this->min, $this->max);
|
$this->current = min($this->min, $this->max);
|
||||||
} elseif($step < 0) {
|
} elseif($step < 0) {
|
||||||
|
@ -111,6 +111,18 @@ class TemplateTest extends TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function providerDo() {
|
||||||
|
$vars = array(
|
||||||
|
"c" => 4,
|
||||||
|
"world" => new Helper('world')
|
||||||
|
);
|
||||||
|
return array(
|
||||||
|
array('{do "nope"}', $vars, ""),
|
||||||
|
array('{do $c++} -> {$c}', $vars, "-> 5"),
|
||||||
|
array('{do $world->chunk(1)}', $vars, ""),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function providerVarsInvalid()
|
public static function providerVarsInvalid()
|
||||||
{
|
{
|
||||||
@ -1154,6 +1166,15 @@ class TemplateTest extends TestCase
|
|||||||
$this->exec($code, $vars, $result);
|
$this->exec($code, $vars, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerDo
|
||||||
|
*/
|
||||||
|
public function testDo($code, $vars, $result)
|
||||||
|
{
|
||||||
|
$this->exec($code, $vars, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerVarsInvalid
|
* @dataProvider providerVarsInvalid
|
||||||
*/
|
*/
|
||||||
@ -1587,6 +1608,8 @@ class TemplateTest extends TestCase
|
|||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
array('{set $a=1..3}', "1,2,3,"),
|
array('{set $a=1..3}', "1,2,3,"),
|
||||||
|
// array('{set $a=0..0}', ""),
|
||||||
|
// array('{set $a=1..1}', ""),
|
||||||
// array('{set $a="a".."f"}', "a,b,c,d,e,f,"),
|
// array('{set $a="a".."f"}', "a,b,c,d,e,f,"),
|
||||||
// array('{set $a=1.."f"}', "1,0,"),
|
// array('{set $a=1.."f"}', "1,0,"),
|
||||||
// array('{set $a="a"..2}', "0,1,2,"),
|
// array('{set $a="a"..2}', "0,1,2,"),
|
||||||
@ -1618,7 +1641,6 @@ class TemplateTest extends TestCase
|
|||||||
/**
|
/**
|
||||||
* @dataProvider providerRange
|
* @dataProvider providerRange
|
||||||
* @group testRange
|
* @group testRange
|
||||||
* @group dev
|
|
||||||
* @param string $code
|
* @param string $code
|
||||||
* @param string $result
|
* @param string $result
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user