Skip to content

Commit 092f059

Browse files
author
Tortue Torche
committed
Update @content_tag_for Blade directives to be able to use all data available from the current view.
<?php $myLocaleVariable = 'cool'; ?> @div_for($project) @if (isset($myLocaleVariable)) My text @endif @end_div_for() And fix the support of Collections/arrays who implement the IteratorAggregate interface: <?php $users = App\User::all(); ?> @div_for($users) as ($user) {{ $userIndex }} {{ $user->name }} @end_div_for
1 parent deccfde commit 092f059

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/Efficiently/JqueryLaravel/BladeExtensions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ public function registerContentTags()
104104
$replacement = <<<EOT
105105
<?php
106106
\${$recordName}Record = $record;
107-
if (! is_a(\${$recordName}Record, "\Illuminate\Support\Collection")) {
107+
if (! is_a(\${$recordName}Record, "\IteratorAggregate")) {
108108
\${$recordName}Record = new \Illuminate\Support\Collection([\${$recordName}Record]);
109109
}
110110
\${$recordIndex} = -1;// -1 because we increment index at the beginnning of the loop
111-
\${$recordName}Record->each(function(\${$recordName}) use(\$__env, &\${$recordIndex}){
111+
foreach (\${$recordName}Record as \${$recordName}) {
112112
\${$recordIndex}++;
113113
\$options = (array) $options;
114114
\$options['class'] = implode(" ",
@@ -132,7 +132,7 @@ public function registerContentTags()
132132
$replacement = <<<EOT
133133
<?php
134134
echo '</'.$tagName.'>';$3
135-
});
135+
}
136136
?>
137137
EOT;
138138
$view = preg_replace($pattern, $replacement, $view, 1);

tests/JqlBladeExtensionsTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ public function testContentTagFor()
8282
$expect = <<<EOT
8383
<?php
8484
\$projectRecord = \$project;
85-
if (! is_a(\$projectRecord, "\Illuminate\Support\Collection")) {
85+
if (! is_a(\$projectRecord, "\IteratorAggregate")) {
8686
\$projectRecord = new \Illuminate\Support\Collection([\$projectRecord]);
8787
}
8888
\$projectIndex = -1;// -1 because we increment index at the beginnning of the loop
89-
\$projectRecord->each(function(\$project) use(\$__env, &\$projectIndex){
89+
foreach (\$projectRecord as \$project) {
9090
\$projectIndex++;
9191
\$options = (array) [];
9292
\$options['class'] = implode(" ",
@@ -98,7 +98,7 @@ public function testContentTagFor()
9898
<?php
9999
echo '</'.'div'.'>';
100100
101-
});
101+
}
102102
?>
103103
EOT;
104104
$view = Blade::compileString($contentTagFor);
@@ -121,11 +121,11 @@ public function testContentTagForWithOptions()
121121
$expect = <<<EOT
122122
<?php
123123
\$projectRecord = \$project;
124-
if (! is_a(\$projectRecord, "\Illuminate\Support\Collection")) {
124+
if (! is_a(\$projectRecord, "\IteratorAggregate")) {
125125
\$projectRecord = new \Illuminate\Support\Collection([\$projectRecord]);
126126
}
127127
\$projectIndex = -1;// -1 because we increment index at the beginnning of the loop
128-
\$projectRecord->each(function(\$project) use(\$__env, &\$projectIndex){
128+
foreach (\$projectRecord as \$project) {
129129
\$projectIndex++;
130130
\$options = (array) ['remote' => 'true'];
131131
\$options['class'] = implode(" ",
@@ -137,7 +137,7 @@ public function testContentTagForWithOptions()
137137
<?php
138138
echo '</'.'div'.'>';
139139
140-
});
140+
}
141141
?>
142142
EOT;
143143
$view = Blade::compileString($contentTagFor);

0 commit comments

Comments
 (0)