Skip to content

Commit

Permalink
feat: add assets with closure
Browse files Browse the repository at this point in the history
  • Loading branch information
lee-to committed Nov 30, 2023
1 parent 0851bf2 commit 43ceb56
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/Theme/AssetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,18 @@ protected function getMainJs(): string
return $this->mainJs;
}

public function add(string|array $assets): void
public function add(string|array|Closure $assets): void
{
$this->assets = array_unique(
array_merge(
$this->assets,
is_array($assets) ? $assets : [$assets]
)
);
if (is_closure($assets)) {
$this->lazyAssign($assets);
} else {
$this->assets = array_unique(
array_merge(
$this->assets,
is_array($assets) ? $assets : [$assets]
)
);
}
}

public function getAssets(): array
Expand All @@ -73,8 +77,8 @@ public function js(): string
)
->map(
fn ($asset): string => "<script defer src='" . asset(
$asset
) . (str_contains((string) $asset, '?') ? '&' : '?') . "v={$this->getVersion()}'></script>"
$asset
) . (str_contains((string) $asset, '?') ? '&' : '?') . "v={$this->getVersion()}'></script>"
)->implode(PHP_EOL);
}

Expand All @@ -87,8 +91,8 @@ public function css(): string
)
->map(
fn ($asset): string => "<link href='" . asset(
$asset
) . (str_contains((string) $asset, '?') ? '&' : '?') . "v={$this->getVersion()}' rel='stylesheet'>"
$asset
) . (str_contains((string) $asset, '?') ? '&' : '?') . "v={$this->getVersion()}' rel='stylesheet'>"
)->implode(PHP_EOL);
}

Expand Down

0 comments on commit 43ceb56

Please sign in to comment.