This commit is contained in:
bzick 2016-05-08 18:26:01 +03:00
parent d23e2b4c4f
commit dec06c888e
7 changed files with 53 additions and 6 deletions

9
docs/en/tags/do.md Normal file
View 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
View File

@ -0,0 +1,9 @@
Тег {do}
========
Выполнить произвольноые выражение без вывода результата на экран
```smarty
{do $count++}
{do $object->method()}
```

View File

@ -7,10 +7,7 @@ require_once __DIR__.'/../tests/tools.php';
$fenom = Fenom::factory(__DIR__.'/templates', __DIR__.'/../tests/resources/compile');
$fenom->setOptions(Fenom::AUTO_RELOAD);
$fenom->addModifier('firstimg', function ($img) {
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->compileCode('{do $object->method()}')->getTemplateCode());
//var_dump($fenom->compile("bug158/main.tpl", [])->getTemplateCode());
//var_dump($fenom->display("bug158/main.tpl", []));
// $fenom->getTemplate("problem.tpl");

View File

@ -272,6 +272,10 @@ class Fenom
'open' => 'Fenom\Compiler::setOpen',
'close' => 'Fenom\Compiler::setClose'
),
'do' => array( // {do ...}
'type' => self::INLINE_COMPILER,
'parser' => 'Fenom\Compiler::tagDo'
),
'block' => array( // {block ...} {parent} {/block}
'type' => self::BLOCK_COMPILER,
'open' => 'Fenom\Compiler::tagBlockOpen',

View File

@ -813,6 +813,11 @@ class Compiler
return $scope["name"] . '=' . $scope["value"] . ';';
}
public static function tagDo($tokens, Tag $scope)
{
return $scope->tpl->parseExpr($tokens).';';
}
/**
* @param Tokenizer $tokens

View File

@ -23,7 +23,8 @@ class RangeIterator implements \Iterator, \Countable
* @param int $step
* @return $this
*/
public function setStep($step) {
public function setStep($step)
{
if($step > 0) {
$this->current = min($this->min, $this->max);
} elseif($step < 0) {

View File

@ -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()
{
@ -1154,6 +1166,15 @@ class TemplateTest extends TestCase
$this->exec($code, $vars, $result);
}
/**
* @dataProvider providerDo
*/
public function testDo($code, $vars, $result)
{
$this->exec($code, $vars, $result);
}
/**
* @dataProvider providerVarsInvalid
*/
@ -1587,6 +1608,8 @@ class TemplateTest extends TestCase
{
return array(
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=1.."f"}', "1,0,"),
// array('{set $a="a"..2}', "0,1,2,"),
@ -1618,7 +1641,6 @@ class TemplateTest extends TestCase
/**
* @dataProvider providerRange
* @group testRange
* @group dev
* @param string $code
* @param string $result
*/