-
-
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.
Simplify the mechanisms behind bind* functions. (#111)
* Fix return type for getElementById, closes #65 * Update PHPDoc to include inherited changes * Rename function for removing template attributes * Set value for certain input fields differently * Bind list to document fragment for efficiency for #77 * Remove unbindable check * Allow returning any iterable, not just array - fixes #88 * Test that multiple kvps can be bound within the same parameter * Isolate bug for #105 - use README example * Rename BindDataGetter -> BindObject * Tidy up bindData function * Test incompatible bindData types * Remove bindNestedList function * Testing bindValue * Test bindObjectValue * Test bindValue within lists * Bindable type checking * Simplify bind functions, closes #110 * Skip empty lists
- Loading branch information
Showing
15 changed files
with
681 additions
and
220 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<!doctype html> | ||
<h1>Shopping list</h1> | ||
|
||
<shopping-list id="groceries"></shopping-list> | ||
|
||
<p>The use of a custom element is more useful on more complex pages, but is shown above as an example.</p> |
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,20 @@ | ||
<?php | ||
require __DIR__ . "/../vendor/autoload.php"; | ||
|
||
use Gt\DomTemplate\HTMLDocument; | ||
|
||
$html = file_get_contents("01-example-groceries.html"); | ||
$document = new HTMLDocument($html, "./_component"); | ||
$document->extractTemplates(); | ||
|
||
$data = [ | ||
["id" => 1, "title" => "Tomatoes"], | ||
["id" => 2, "title" => "Noodles"], | ||
["id" => 3, "title" => "Cheese"], | ||
["id" => 4, "title" => "Broccoli"], | ||
]; | ||
|
||
$outputTo = $document->getElementById("groceries"); | ||
$outputTo->bindList($data); | ||
|
||
echo $document; |
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,3 @@ | ||
<ul> | ||
<li data-template data-bind:text="title" data-bind:data-id="id">Item name</li> | ||
</ul> |
This file was deleted.
Oops, something went wrong.
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,15 @@ | ||
<?php | ||
namespace Gt\DomTemplate; | ||
|
||
/** | ||
* This interface does not define any functions, but is used to indicate that | ||
* the implementing class should expose "bind*" functions for the key-value data | ||
* it represents. | ||
* | ||
* For example: class Person implements BindObject { | ||
* // This function will be called for the "name" key when bound. | ||
* public function bindName():string { | ||
* return $this->forename . " " . $this->surname; | ||
* } | ||
*/ | ||
interface BindObject {} |
Oops, something went wrong.