Skip to content

Commit

Permalink
Refactored output printing
Browse files Browse the repository at this point in the history
  • Loading branch information
juniwalk committed Apr 24, 2024
1 parent 3dd2d8f commit b6214c2
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions src/TessaRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,33 @@ public function clearHistory(): void

public function renderCss(?string $bundle = null): void
{
$type = Type::StyleSheet;
$this->renderType(Type::StyleSheet, $bundle);
}

if (!$bundle) {
$this->render($type);
return;
}

echo implode(PHP_EOL, $this->compile($bundle, $type)).PHP_EOL;
public function renderJs(?string $bundle = null): void
{
$this->renderType(Type::JavaScript, $bundle);
}


public function renderJs(?string $bundle = null): void
/**
* @throws AssetTypeException
*/
public function renderType(Type|string $type, ?string $bundle = null): void
{
$type = Type::JavaScript;
$type = Type::make($type, false) ?? $type;

if (!$bundle) {
$this->render($type);
return;
if (!$type instanceof Type) {
throw AssetTypeException::fromType($type);
}

echo implode(PHP_EOL, $this->compile($bundle, $type)).PHP_EOL;
match (true) {
$bundle => $this->print(
$this->compile($bundle, $type)
),
default => $this->render($type),
};
}


Expand Down Expand Up @@ -96,7 +102,7 @@ public function render(Type|string $type): void
$output = array_merge($output, $assets);
}

echo implode(PHP_EOL, $output).PHP_EOL;
$this->print($output);
}


Expand Down Expand Up @@ -124,6 +130,15 @@ private function compile(string $bundle, Type $type): array
}


/**
* @param Html[] $assets
*/
private function print(array $assets): void
{
echo implode(PHP_EOL, $assets).PHP_EOL;
}


private function createStyleSheet(Asset $asset): ?Html
{
$path = $this->createFilePath($asset);
Expand Down

0 comments on commit b6214c2

Please sign in to comment.