-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* For #96 added $loop->even and $loop->odd and $loop->iteration * Also, **$loop->index now starts with 0 instead of 1**
- Loading branch information
Showing
9 changed files
with
130 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
/** | ||
* Copyright (c) 2016 Jorge Patricio Castro Castillo MIT License. | ||
*/ | ||
include "../lib/BladeOne.php"; | ||
use eftec\bladeone\BladeOne; | ||
|
||
$views = __DIR__ . '/views'; | ||
$compiledFolder = __DIR__ . '/compiled'; | ||
$blade=new BladeOne($views,$compiledFolder,BladeOne::MODE_DEBUG); | ||
|
||
|
||
$users=[]; | ||
|
||
$john=new stdClass(); | ||
$john->name="John"; | ||
$john->post=[]; | ||
|
||
$annah=new stdClass(); | ||
$annah->name="Annah"; | ||
$annah->post=[]; | ||
|
||
$post1=new stdClass(); | ||
$post1->subject="Hi there 1"; | ||
|
||
$post2=new stdClass(); | ||
$post2->subject="Hi there 2"; | ||
|
||
$john->posts[]=$post1; | ||
$john->posts[]=$post2; | ||
|
||
$annah->posts[]=$post1; | ||
$annah->posts[]=$post2; | ||
|
||
$users[]=$john; | ||
$users[]=$annah; | ||
|
||
|
||
try { | ||
echo $blade->run("Test.loop2" | ||
, ["users" => $users]); | ||
} catch (Exception $e) { | ||
echo "error found ".$e->getMessage()."<br>".$e->getTraceAsString(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<html> | ||
<head> | ||
<title>Example of Loop 2</title> | ||
<!-- Google Fonts --> | ||
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic"> | ||
<!-- CSS Reset --> | ||
<link rel="stylesheet" href="//cdn.rawgit.com/necolas/normalize.css/master/normalize.css"> | ||
<!-- Milligram CSS minified --> | ||
<link rel="stylesheet" href="//cdn.rawgit.com/milligram/milligram/master/dist/milligram.min.css"> | ||
</head> | ||
<body> | ||
<h1>Example of Loops</h1> | ||
@foreach ($users as $user) | ||
<hr> | ||
Name user:{{$user->name}}<br> | ||
<ul> | ||
@foreach ($user->posts as $post) | ||
<li>{{$loop->parent->index}} {{$loop->index}} {{$loop->even}}: Subject:{{$post->subject}}</li> | ||
|
||
@endforeach | ||
</ul> | ||
@endforeach | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,13 @@ | |
* @author G.J.W. Oolbekkink <[email protected]> | ||
* @since 17/09/2018 | ||
*/ | ||
class LoopTest extends AbstractBladeTestCase { | ||
class LoopTest extends AbstractBladeTestCase | ||
{ | ||
/** | ||
* @throws \Exception | ||
*/ | ||
public function testFor() { | ||
public function testFor() | ||
{ | ||
$bladeSource = /** @lang Blade */ | ||
<<<'BLADE' | ||
@for($i = 1; $i <= 6; $i++) | ||
|
@@ -23,7 +25,8 @@ public function testFor() { | |
/** | ||
* @throws \Exception | ||
*/ | ||
public function testForEach() { | ||
public function testForEach() | ||
{ | ||
$bladeSource = /** @lang Blade */ | ||
<<<'BLADE' | ||
@foreach($items as $item) | ||
|
@@ -32,11 +35,33 @@ public function testForEach() { | |
BLADE; | ||
$this->assertEqualsIgnoringWhitespace("Item a Item b", $this->blade->runString($bladeSource, ['items' => ['a', 'b']])); | ||
} | ||
|
||
/** | ||
* @throws \Exception | ||
*/ | ||
public function testForElse() { | ||
public function testForEachLoopVar() | ||
{ | ||
$bladeSource = /** @lang Blade */ | ||
<<<'BLADE' | ||
@foreach($items as $item) | ||
Item_index:{{$loop->index}},iteration:{{$loop->iteration}},first:{{$loop->first}} | ||
,last:{{$loop->last}},remaining:{{$loop->remaining}} | ||
,count:{{$loop->count}},depth:{{$loop->depth}},parent:{{$loop->parent}} | ||
,even:{{$loop->even}},odd:{{$loop->odd}},value{{ $item }} | ||
@endforeach | ||
BLADE; | ||
$this->assertEqualsIgnoringWhitespace("Item_index:0,iteration:1,first:1"." | ||
,last:,remaining:2"." | ||
,count:2,depth:1,parent:"." | ||
,even:1,odd:,valuea"." | ||
Item_index:1,iteration:2,first:"." | ||
,last:,remaining:1,count:2,depth:1,parent:"." | ||
,even:,odd:1,valueb", $this->blade->runString($bladeSource, ['items' => ['a', 'b']])); | ||
} | ||
/** | ||
* @throws \Exception | ||
*/ | ||
public function testForElse() | ||
{ | ||
$bladeSource = /** @lang Blade */ | ||
<<<'BLADE' | ||
@forelse($items as $item) | ||
|
@@ -52,7 +77,8 @@ public function testForElse() { | |
/** | ||
* @throws \Exception | ||
*/ | ||
public function testWhile() { | ||
public function testWhile() | ||
{ | ||
$bladeSource = <<<'BLADE' | ||
@php($i = 1) | ||
@while($i < 5) | ||
|
@@ -61,6 +87,5 @@ public function testWhile() { | |
@endwhile | ||
BLADE; | ||
$this->assertEqualsIgnoringWhitespace("Item 2 Item 3 Item 4 Item 5", $this->blade->runString($bladeSource, [])); | ||
|
||
} | ||
} | ||
} |