-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
184 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
%A% | ||
foreach ($iterator = $ʟ_it = new LR\CachingIterator([1,2,3], $ʟ_it ?? null) as $foo) /* line %d% */ { | ||
echo ' <b'; | ||
echo ($ʟ_tmp = array_filter([$iterator->even ? 'even' : null])) ? ' class="' . LR\Filters::escapeHtmlAttr(implode(" ", array_unique($ʟ_tmp))) . '"' : "" /* line %d% */; | ||
echo '>item</b> | ||
'; | ||
$iterations++; | ||
} | ||
$iterator = $ʟ_it = $ʟ_it->getParent(); | ||
echo "\n"; | ||
$iterations = 0; | ||
foreach ($iterator = $ʟ_it = new LR\CachingIterator([1, 2, 3], $ʟ_it ?? null) as $foo) /* line %d% */ { | ||
echo '<p'; | ||
echo ($ʟ_tmp = array_filter([$iterator->even ? 'even' : null])) ? ' class="' . LR\Filters::escapeHtmlAttr(implode(" ", array_unique($ʟ_tmp))) . '"' : "" /* line %d% */; | ||
echo '>'; | ||
echo LR\Filters::escapeHtmlText($foo) /* line %d% */; | ||
echo '</p> | ||
'; | ||
$iterations++; | ||
} | ||
$iterator = $ʟ_it = $ʟ_it->getParent(); | ||
echo ' | ||
<p'; | ||
echo ($ʟ_tmp = array_filter(['foo', (false ? 'first' : null), 'odd', (true ? 'foo' : 'bar')])) ? ' class="' . LR\Filters::escapeHtmlAttr(implode(" ", array_unique($ʟ_tmp))) . '"' : "" /* line %d% */; | ||
echo '>n:class</p> | ||
|
||
<p'; | ||
echo ($ʟ_tmp = array_filter([false ? 'first' : null])) ? ' class="' . LR\Filters::escapeHtmlAttr(implode(" ", array_unique($ʟ_tmp))) . '"' : "" /* line %d% */; | ||
echo '>n:class empty</p> | ||
|
||
<p'; | ||
echo ($ʟ_tmp = array_filter([true ? 'bem--modifier' : null])) ? ' class="' . LR\Filters::escapeHtmlAttr(implode(" ", array_unique($ʟ_tmp))) . '"' : "" /* line %d% */; | ||
echo '>n:class with BEM</p> | ||
'; | ||
%A% |
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,65 @@ | ||
<?php | ||
|
||
/** | ||
* n:attr | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
use Tester\Assert; | ||
|
||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
$latte = new Latte\Engine; | ||
$latte->setLoader(new Latte\Loaders\StringLoader); | ||
|
||
$template = <<<'EOD' | ||
<p n:attr="title => hello, lang => isset($lang) ? $lang"> </p> | ||
<p n:attr="[title => hello]"> </p> | ||
|
||
EOD; | ||
|
||
Assert::match( | ||
<<<'XX' | ||
%A% | ||
echo ' | ||
<p'; | ||
$ʟ_tmp = ['title' => 'hello', 'lang' => isset($lang) ? $lang : null]; | ||
echo LR\Filters::htmlAttributes(isset($ʟ_tmp[0]) && is_array($ʟ_tmp[0]) ? $ʟ_tmp[0] : $ʟ_tmp) /* line 2 */; | ||
echo '> </p> | ||
<p'; | ||
$ʟ_tmp = [['title' => 'hello']]; | ||
echo LR\Filters::htmlAttributes(isset($ʟ_tmp[0]) && is_array($ʟ_tmp[0]) ? $ʟ_tmp[0] : $ʟ_tmp) /* line 4 */; | ||
echo '> </p> | ||
'; | ||
%A% | ||
XX | ||
, | ||
$latte->compile($template) | ||
); | ||
|
||
Assert::match( | ||
<<<'XX' | ||
<p title="hello"> </p> | ||
<p title="hello"> </p> | ||
XX | ||
, | ||
$latte->renderToString($template) | ||
); | ||
|
||
|
||
Assert::exception(function () use ($latte) { | ||
$latte->compile('<div n:attr/>'); | ||
}, Latte\CompileException::class, 'Missing arguments in n:attr'); | ||
|
||
|
||
Assert::exception(function () use ($latte) { | ||
$latte->compile('<div n:inner-attr/>'); | ||
}, Latte\CompileException::class, 'Unknown attribute n:inner-attr'); |
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,68 @@ | ||
<?php | ||
|
||
/** | ||
* n:class | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
use Tester\Assert; | ||
|
||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
$latte = new Latte\Engine; | ||
$latte->setLoader(new Latte\Loaders\StringLoader); | ||
|
||
$template = <<<'EOD' | ||
{foreach [1,2,3] as $foo} | ||
<b n:class="$iterator->even ? even">item</b> | ||
{/foreach} | ||
<p n:foreach="[1, 2, 3] as $foo" n:class="$iterator->even ? even">{$foo}</p> | ||
<p n:class="foo, (false ? first), odd, (true ? foo : bar)">n:class</p> | ||
<p n:class="false ? first">n:class empty</p> | ||
<p n:class="true ? bem--modifier">n:class with BEM</p> | ||
|
||
EOD; | ||
|
||
Assert::matchFile( | ||
__DIR__ . '/expected/n-class.phtml', | ||
$latte->compile($template) | ||
); | ||
|
||
Assert::match( | ||
<<<'XX' | ||
<b>item</b> | ||
<b class="even">item</b> | ||
<b>item</b> | ||
<p>1</p> | ||
<p class="even">2</p> | ||
<p>3</p> | ||
<p class="foo odd">n:class</p> | ||
<p>n:class empty</p> | ||
<p class="bem--modifier">n:class with BEM</p> | ||
XX | ||
, | ||
$latte->renderToString($template) | ||
); | ||
|
||
|
||
Assert::exception(function () use ($latte) { | ||
$latte->compile('<div n:class/>'); | ||
}, Latte\CompileException::class, 'Missing arguments in n:class'); | ||
|
||
|
||
Assert::exception(function () use ($latte) { | ||
$latte->compile('<div n:inner-class/>'); | ||
}, Latte\CompileException::class, 'Unknown attribute n:inner-class'); |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?php | ||
|
||
/** | ||
* Test: Latte\Engine and n:tag. | ||
* n:tag | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|