-
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.
Merge pull request #30 from JoshuaCarter/1.1
Add template logic for nested data
- Loading branch information
Showing
5 changed files
with
190 additions
and
2 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,30 @@ | ||
<?php | ||
|
||
/** | ||
* Used in place of ArrayList when preparing nested arrays for export for SS templates. | ||
* | ||
* var_export calls '__set_state' on classes, so it produces code like: | ||
* | ||
* ArrayList::__set_state(array('items' => [...])) | ||
* | ||
* And because ArrayList doens't implement '__set_state', executing the code throws errors. | ||
* So we work around this by using an ArrayListExportable to produce: | ||
* | ||
* ArrayListExportable::__set_state(array('items' => [...])) | ||
* | ||
* And implement '__set_state' to return a constructed ArrayList. | ||
*/ | ||
class ArrayListExportable | ||
{ | ||
public function __construct($array = array()) | ||
{ | ||
// need to store items for var_export to recurse | ||
$this->items = $array; | ||
} | ||
|
||
public static function __set_state ($array) | ||
{ | ||
// when executed, we naruto-style body-replace with in an ArrayList | ||
return new ArrayList($array['items']); | ||
} | ||
} |
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,23 @@ | ||
<% if $NestedData %> | ||
<% loop $NestedData %> | ||
<h2>$Title</h2> | ||
<% if $Children %> | ||
<ul> | ||
<% loop $Children %> | ||
<li> | ||
<h3>$Title</h3> | ||
<% if $Children %> | ||
<ul> | ||
<% loop $Children %> | ||
<li> | ||
<h4>$Title</h4> | ||
</li> | ||
<% end_loop %> | ||
</ul> | ||
<% end_if %> | ||
</li> | ||
<% end_loop %> | ||
</ul> | ||
<% end_if %> | ||
<% end_loop %> | ||
<% end_if %> |