Skip to content

Commit

Permalink
Merge branch 'release/v0.16.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
betterthanclay committed Feb 19, 2025
2 parents b3673ab + b61e9b7 commit 0f8a43e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 29 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v0.16.2 (2025-02-19)
* Accept Generators in list factories

## v0.16.1 (2025-02-18)
* Re-added ArrayAccess to ContentCollection

Expand Down
61 changes: 41 additions & 20 deletions src/Tagged/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace DecodeLabs\Tagged;

use Closure;
use DecodeLabs\Coercion;
use DecodeLabs\Glitch\Proxy as Glitch;
use DecodeLabs\Tagged;
Expand Down Expand Up @@ -132,18 +133,22 @@ public function content(
/**
* Generate nested list
*
* @param iterable<mixed>|null $list
* @param iterable<mixed>|Closure():(iterable<mixed>)|null $list
* @param array<string, mixed>|null $attributes
*/
public function list(
?iterable $list,
iterable|Closure|null $list,
string $container,
?string $name,
?callable $callback = null,
?array $attributes = null
): Element {
$output = Element::create($container, function () use ($list, $name, $callback) {
if (!$list) {
if($list instanceof Closure) {
$list = $list();
}

if (!is_iterable($list)) {
return;
}

Expand Down Expand Up @@ -180,17 +185,21 @@ public function list(
/**
* Generate naked list
*
* @param iterable<mixed>|null $list
* @param iterable<mixed>|Closure():(iterable<mixed>)|null $list
* @param array<string, mixed>|null $attributes
*/
public function elements(
?iterable $list,
iterable|Closure|null $list,
?string $name,
?callable $callback = null,
?array $attributes = null
): Buffer {
return ContentCollection::normalize(function () use ($list, $name, $callback, $attributes) {
if (!$list) {
if($list instanceof Closure) {
$list = $list();
}

if (!is_iterable($list)) {
return;
}

Expand Down Expand Up @@ -224,14 +233,18 @@ public function elements(
/**
* Generate unwrapped naked list
*
* @param iterable<mixed>|null $list
* @param iterable<mixed>|Closure():(iterable<mixed>)|null $list
*/
public function loop(
?iterable $list,
iterable|Closure|null $list,
?callable $callback = null
): Buffer {
return ContentCollection::normalize(function () use ($list, $callback) {
if (!$list) {
if($list instanceof Closure) {
$list = $list();
}

if (!is_iterable($list)) {
return;
}

Expand All @@ -253,11 +266,11 @@ public function loop(
/**
* Create a standard ul > li structure
*
* @param iterable<mixed>|null $list
* @param iterable<mixed>|Closure():(iterable<mixed>)|null $list
* @param array<string, mixed>|null $attributes
*/
public function uList(
?iterable $list,
iterable|Closure|null $list,
?callable $renderer = null,
?array $attributes = null
): Element {
Expand All @@ -269,11 +282,11 @@ public function uList(
/**
* Create a standard ol > li structure
*
* @param iterable<mixed>|null $list
* @param iterable<mixed>|Closure():(iterable<mixed>)|null $list
* @param array<string, mixed>|null $attributes
*/
public function oList(
?iterable $list,
iterable|Closure|null $list,
?callable $renderer = null,
?array $attributes = null
): Element {
Expand All @@ -285,11 +298,11 @@ public function oList(
/**
* Create a standard dl > dt + dd structure
*
* @param iterable<mixed>|null $list
* @param array<string, mixed>|null $attributes
* @param iterable<mixed>|Closure():(iterable<mixed>)|null $list
* @param array<string,mixed>|null $attributes
*/
public function dList(
?iterable $list,
iterable|Closure|null $list,
?callable $renderer = null,
?array $attributes = null
): Element {
Expand All @@ -298,7 +311,11 @@ public function dList(
};

$output = Element::create('dl', function () use ($list, $renderer) {
if (!$list) {
if($list instanceof Closure) {
$list = $list();
}

if (!is_iterable($list)) {
return;
}

Expand Down Expand Up @@ -326,10 +343,10 @@ public function dList(
/**
* Create an inline comma separated list with optional item limit
*
* @param iterable<mixed>|null $list
* @param iterable<mixed>|Closure():(iterable<mixed>)|null $list
*/
public function iList(
?iterable $list,
iterable|Closure|null $list,
?callable $renderer = null,
?string $delimiter = null,
?string $finalDelimiter = null,
Expand All @@ -344,7 +361,11 @@ public function iList(
) use ($list, $renderer, $delimiter, $finalDelimiter, $limit) {
$el->setRenderEmpty(false);

if (!$list) {
if($list instanceof Closure) {
$list = $list();
}

if (!is_iterable($list)) {
return;
}

Expand Down
20 changes: 11 additions & 9 deletions stubs/DecodeLabs/Tagged.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
use DecodeLabs\Tagged\Element as Ref1;
use DecodeLabs\Tagged\Buffer as Ref2;
use DecodeLabs\Tagged\ContentCollection as Ref3;
use Stringable as Ref4;
use Traversable as Ref4;
use Closure as Ref5;
use Stringable as Ref6;

class Tagged implements Proxy
{
Expand Down Expand Up @@ -46,28 +48,28 @@ public static function wrap(mixed ...$content): Ref2 {
public static function content(mixed ...$content): Ref3 {
return static::$_veneerInstance->content(...func_get_args());
}
public static function list(?iterable $list, string $container, ?string $name, ?callable $callback = NULL, ?array $attributes = NULL): Ref1 {
public static function list(Ref4|Ref5|array|null $list, string $container, ?string $name, ?callable $callback = NULL, ?array $attributes = NULL): Ref1 {
return static::$_veneerInstance->list(...func_get_args());
}
public static function elements(?iterable $list, ?string $name, ?callable $callback = NULL, ?array $attributes = NULL): Ref2 {
public static function elements(Ref4|Ref5|array|null $list, ?string $name, ?callable $callback = NULL, ?array $attributes = NULL): Ref2 {
return static::$_veneerInstance->elements(...func_get_args());
}
public static function loop(?iterable $list, ?callable $callback = NULL): Ref2 {
public static function loop(Ref4|Ref5|array|null $list, ?callable $callback = NULL): Ref2 {
return static::$_veneerInstance->loop(...func_get_args());
}
public static function uList(?iterable $list, ?callable $renderer = NULL, ?array $attributes = NULL): Ref1 {
public static function uList(Ref4|Ref5|array|null $list, ?callable $renderer = NULL, ?array $attributes = NULL): Ref1 {
return static::$_veneerInstance->uList(...func_get_args());
}
public static function oList(?iterable $list, ?callable $renderer = NULL, ?array $attributes = NULL): Ref1 {
public static function oList(Ref4|Ref5|array|null $list, ?callable $renderer = NULL, ?array $attributes = NULL): Ref1 {
return static::$_veneerInstance->oList(...func_get_args());
}
public static function dList(?iterable $list, ?callable $renderer = NULL, ?array $attributes = NULL): Ref1 {
public static function dList(Ref4|Ref5|array|null $list, ?callable $renderer = NULL, ?array $attributes = NULL): Ref1 {
return static::$_veneerInstance->dList(...func_get_args());
}
public static function iList(?iterable $list, ?callable $renderer = NULL, ?string $delimiter = NULL, ?string $finalDelimiter = NULL, ?int $limit = NULL): Ref1 {
public static function iList(Ref4|Ref5|array|null $list, ?callable $renderer = NULL, ?string $delimiter = NULL, ?string $finalDelimiter = NULL, ?int $limit = NULL): Ref1 {
return static::$_veneerInstance->iList(...func_get_args());
}
public static function image(Ref4|string|null $url, ?string $alt = NULL, string|int|null $width = NULL, string|int|null $height = NULL): Ref1 {
public static function image(Ref6|string|null $url, ?string $alt = NULL, string|int|null $width = NULL, string|int|null $height = NULL): Ref1 {
return static::$_veneerInstance->image(...func_get_args());
}
public static function esc(mixed $value): ?string {
Expand Down

0 comments on commit 0f8a43e

Please sign in to comment.