-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvements to working with lists of data (data-bind:list and nested…
… object improvements) (#415) * build: upgrade dom requirement and loosen version range * docs: update examples * feature: trim whitespace when there are only template children closes #363 * maintenance: phpstorm analysis improvements * test: refactor test helper class * wip: add test data for big integration * test: add failing test to cover nested objects for #356 * test: add extra cases for nested object test * feature: allow nesting of object properties closes #356 * maintenance: static analysis improvement * test: nested objects with bindgetter functions * test: isolate issue #367 * test: use `data-template-parent` attribute internally instead of id closes #367 * test: isolate functionality for #368 * wip: implementation for #368 not yet completed * feature: data-bind:list closes #368 * tidy: static analysis improvements * tidy: types of reflection method improved * tidy: remove unused import * tidy: nullable reflection type * tidy: remove unused elements * docs: add nested music example
- Loading branch information
Showing
30 changed files
with
1,052 additions
and
309 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
<?php | ||
use Gt\Dom\HTMLDocument; | ||
use Gt\DomTemplate\DocumentBinder; | ||
|
||
require __DIR__ . "/../../vendor/autoload.php"; | ||
|
||
$html = <<<HTML | ||
<!doctype html> | ||
<h1>Music library</h1> | ||
<ul> | ||
<li> | ||
<h2 data-bind:text>Artist name</h2> | ||
<ul> | ||
<li> | ||
<h3 data-bind:text>Album name</h3> | ||
<ol> | ||
<li data-bind:text>Track name</li> | ||
</ol> | ||
</li> | ||
</ul> | ||
</li> | ||
</ul> | ||
HTML; | ||
|
||
$musicData = [ | ||
"A Band From Your Childhood" => [ | ||
"This Album is Good" => [ | ||
"The Best Song You‘ve Ever Heard", | ||
"Another Cracking Tune", | ||
"Top Notch Music Here", | ||
"The Best Is Left ‘Til Last", | ||
], | ||
"Adequate Collection" => [ | ||
"Meh", | ||
"‘sok", | ||
"Sounds Like Every Other Song", | ||
], | ||
], | ||
"Bongo and The Bronks" => [ | ||
"Salad" => [ | ||
"Tomatoes", | ||
"Song About Cucumber", | ||
"Onions Make Me Cry (but I love them)", | ||
], | ||
"Meat" => [ | ||
"Steak", | ||
"Is Chicken Really a Meat?", | ||
"Don‘t Look in the Sausage Factory", | ||
"Stop Horsing Around", | ||
], | ||
"SnaxX" => [ | ||
"Crispy Potatoes With Salt", | ||
"Pretzel Song", | ||
"Pork Scratchings Are Skin", | ||
"The Peanut Is Not Actually A Nut", | ||
], | ||
], | ||
"Crayons" => [ | ||
"Pastel Colours" => [ | ||
"Egg Shell", | ||
"Cotton", | ||
"Frost", | ||
"Periwinkle", | ||
], | ||
"Different Shades of Blue" => [ | ||
"Cobalt", | ||
"Slate", | ||
"Indigo", | ||
"Teal", | ||
], | ||
] | ||
]; | ||
|
||
function example(DocumentBinder $binder, array $musicData):void { | ||
$binder->bindList($musicData); | ||
} | ||
|
||
$document = new HTMLDocument($html); | ||
$binder = new DocumentBinder($document); | ||
|
||
example($binder, $musicData); | ||
|
||
echo $document; | ||
|
||
/* | ||
Output: | ||
<!doctype html> | ||
<h1>Music library</h1> | ||
<ul> | ||
<li> | ||
<h2>A Band From Your Childhood</h2> | ||
<ul> | ||
<li> | ||
<h3>This Album is Good</h3> | ||
<ol> | ||
<li>The Best Song You‘ve Ever Heard</li> | ||
<li>Another Cracking Tune</li> | ||
<li>Top Notch Music Here</li> | ||
<li>The Best Is Left ‘Til Last</li> | ||
</ol> | ||
</li> | ||
<li> | ||
<h3>Adequate Collection</h3> | ||
<ol> | ||
<li>Meh</li> | ||
<li>‘sok</li> | ||
<li>Sounds Like Every Other Song</li> | ||
</ol> | ||
</li> | ||
</ul> | ||
</li> | ||
<li> | ||
<h2>Bongo and The Bronks</h2> | ||
<ul> | ||
<li> | ||
<h3>Salad</h3> | ||
<ol> | ||
<li>Tomatoes</li> | ||
<li>Song About Cucumber</li> | ||
<li>Onions Make Me Cry (but I love them)</li> | ||
</ol> | ||
</li> | ||
<li> | ||
<h3>Meat</h3> | ||
<ol> | ||
<li>Steak</li> | ||
<li>Is Chicken Really a Meat?</li> | ||
<li>Don‘t Look in the Sausage Factory</li> | ||
<li>Stop Horsing Around</li> | ||
</ol> | ||
</li> | ||
<li> | ||
<h3>SnaxX</h3> | ||
<ol> | ||
<li>Crispy Potatoes With Salt</li> | ||
<li>Pretzel Song</li> | ||
<li>Pork Scratchings Are Skin</li> | ||
<li>The Peanut Is Not Actually A Nut</li> | ||
</ol> | ||
</li> | ||
</ul> | ||
</li> | ||
<li> | ||
<h2>Crayons</h2> | ||
<ul> | ||
<li> | ||
<h3>Pastel Colours</h3> | ||
<ol> | ||
<li>Egg Shell</li> | ||
<li>Cotton</li> | ||
<li>Frost</li> | ||
<li>Periwinkle</li> | ||
</ol> | ||
</li> | ||
<li> | ||
<h3>Different Shades of Blue</h3> | ||
<ol> | ||
<li>Cobalt</li> | ||
<li>Slate</li> | ||
<li>Indigo</li> | ||
<li>Teal</li> | ||
</ol> | ||
</li> | ||
</ul> | ||
</li> | ||
</ul> | ||
*/ |
Oops, something went wrong.