From cd4f68808859141ca773bb8d68b71094c9c08b45 Mon Sep 17 00:00:00 2001 From: bzick Date: Sat, 27 Aug 2016 22:30:34 +0300 Subject: [PATCH] Fix #249 --- sandbox/fenom.php | 66 +++++++++++++++++++++++++++++- sandbox/templates/bug249/bread.tpl | 38 +++++++++++++++++ src/Fenom/RangeIterator.php | 2 +- tests/cases/Fenom/TemplateTest.php | 5 +++ 4 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 sandbox/templates/bug249/bread.tpl diff --git a/sandbox/fenom.php b/sandbox/fenom.php index 22d5513..6b8ccf6 100644 --- a/sandbox/fenom.php +++ b/sandbox/fenom.php @@ -5,11 +5,73 @@ require_once __DIR__.'/../tests/tools.php'; \Fenom::registerAutoload(); +$vars = [ + [ + "id" => 1, + "name" => "Блаблабла", + "hidden_url" => "/" + ], + [ + "id" => 2, + "name" => "Каталог", + "hidden_url" => "/catalog" + ], + [ + "id" => 3, + "name" => "Сыромолочная группа", + "hidden_url" => "/catalog/cat_1.html" + ], + [ + "id" => 4, + "name" => "Сыры", + "hidden_url" => "/catalog/cat_2.html" + ], +]; + $fenom = Fenom::factory(__DIR__.'/templates', __DIR__.'/compiled'); $fenom->setOptions(Fenom::AUTO_RELOAD | Fenom::FORCE_VERIFY); //var_dump($fenom->compile("nested.tpl", [])->getTemplateCode()); //exit; -var_dump($fenom->fetch('bug247/home.tpl', [])); +var_dump($fenom->fetch('bug249/bread.tpl', ["arr" => $vars])); +//var_dump($fenom->compile('bug249/bread.tpl', false)->getBody()); //var_dump($fenom->compile("bug158/main.tpl", [])->getTemplateCode()); //var_dump($fenom->display("bug158/main.tpl", [])); -// $fenom->getTemplate("problem.tpl"); \ No newline at end of file +// $fenom->getTemplate("problem.tpl"); + +/* + * + * Array +( + [0] => Array + ( + [id] => 1 + [name] => Блаблабла + [hidden_url] => / + ) + [1] => Array + ( + [id] => 2 + [name] => Каталог + [hidden_url] => /catalog/ + ) + [2] => Array + ( + [orig_id] => 1 + [hidden_url] => /catalog/cat_1.html + [name] => Сыромолочная группа + ) + [3] => Array + ( + [orig_id] => 2 + [hidden_url] => /catalog/cat_2.html + [name] => Сыры + ) + [4] => Array + ( + [orig_id] => 6 + [hidden_url] => /catalog/cat_6.html + [name] => Сыр плавленый + ) +) + + */ \ No newline at end of file diff --git a/sandbox/templates/bug249/bread.tpl b/sandbox/templates/bug249/bread.tpl new file mode 100644 index 0000000..df6d4d6 --- /dev/null +++ b/sandbox/templates/bug249/bread.tpl @@ -0,0 +1,38 @@ +{*
*} + {**} +{*
*} + +=== {(1..3)|length} === + +{foreach 1..3 as $c index=$i first=$first last=$last} + {$i}: {$last} +{/foreach} + +
+ +
\ No newline at end of file diff --git a/src/Fenom/RangeIterator.php b/src/Fenom/RangeIterator.php index 2d5cfb1..8bb0a79 100644 --- a/src/Fenom/RangeIterator.php +++ b/src/Fenom/RangeIterator.php @@ -90,7 +90,7 @@ class RangeIterator implements \Iterator, \Countable */ public function count() { - return intval(($this->max - $this->min) / $this->step); + return intval(($this->max - $this->min + 1) / $this->step); } /** diff --git a/tests/cases/Fenom/TemplateTest.php b/tests/cases/Fenom/TemplateTest.php index 882fa7d..061b9b8 100644 --- a/tests/cases/Fenom/TemplateTest.php +++ b/tests/cases/Fenom/TemplateTest.php @@ -1406,6 +1406,11 @@ class TemplateTest extends TestCase $a, 'Foreach: 0 => 1, 1 => 2, 2 => 3, end' ), + array( + 'Foreach: {foreach 1..3 as $k => $e last=$l} {$k} => {$e}, {if $l}last{/if} {/foreach} end', + $a, + 'Foreach: 0 => 1, 1 => 2, 2 => 3, last end' + ), array( 'Foreach: {foreach $.get.items as $e} {$e}, {/foreach} end', $a,