Skip to content

Commit

Permalink
Merge branch 'release/v0.15.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
betterthanclay committed Jun 20, 2024
2 parents f27aaec + 74dd05f commit c803d46
Show file tree
Hide file tree
Showing 9 changed files with 582 additions and 6 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/integrate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ jobs:
ini-values: "post_max_size=256M"

- name: "Checkout code"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"

- name: Install Effigy
run: |
composer global config --no-plugins allow-plugins.phpstan/extension-installer true
composer global require decodelabs/effigy
- name: "Install dependencies"
uses: "ramsey/composer-install@v2"
uses: "ramsey/composer-install@v3"
with:
dependency-versions: "highest"

Expand Down Expand Up @@ -72,7 +72,7 @@ jobs:
ini-values: "post_max_size=256M"

- name: "Checkout code"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"

- name: Install Effigy
run: |
Expand All @@ -83,7 +83,7 @@ jobs:
run: "composer validate --strict"

- name: "Install dependencies"
uses: "ramsey/composer-install@v2"
uses: "ramsey/composer-install@v3"
with:
dependency-versions: "highest"

Expand All @@ -106,7 +106,7 @@ jobs:
ini-values: "post_max_size=256M"

- name: "Checkout code"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"

- name: "Check EditorConfig configuration"
run: "test -f .editorconfig"
Expand All @@ -120,7 +120,7 @@ jobs:
composer global require decodelabs/effigy
- name: "Install dependencies"
uses: "ramsey/composer-install@v2"
uses: "ramsey/composer-install@v3"
with:
dependency-versions: "highest"

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v0.15.1 (2024-06-20)
* Added ViewAssetContainer structure
* Added initial Asset implementations

## v0.15.0 (2024-05-07)
* Added JsonSerializable to Markup interface

Expand Down
18 changes: 18 additions & 0 deletions src/Asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/**
* @package Tagged
* @license http://opensource.org/licenses/MIT
*/

declare(strict_types=1);

namespace DecodeLabs\Tagged;

use DecodeLabs\Collections\AttributeContainer;

interface Asset extends AttributeContainer
{
public function getPriority(): int;
public function render(): Element;
}
69 changes: 69 additions & 0 deletions src/Asset/InlineScript.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

/**
* @package Tagged
* @license http://opensource.org/licenses/MIT
*/

declare(strict_types=1);

namespace DecodeLabs\Tagged\Asset;

use DecodeLabs\Coercion;
use DecodeLabs\Tagged\AssetTrait;
use DecodeLabs\Tagged\Element;

class RemoteScript implements Script
{
use AssetTrait;

protected string $source;

/**
* Init with script
*
* @param array<string, mixed> $attributes
*/
public function __construct(
int $priority,
string $source,
array $attributes = []
) {
$this->priority = $priority;
$this->source = $source;

if (!isset($attributes['type'])) {
$attributes['type'] = 'text/javascript';
}

$this->setAttributes($attributes);
}

/**
* Set type
*/
public function setType(
string $type
): void {
$this->setAttribute('type', $type);
}

/**
* Get type
*/
public function getType(): string
{
return Coercion::toString(
$this->getAttribute('type') ?? 'text/javascript'
);
}

/**
* Render
*/
public function render(): Element
{
unset($this->attributes['src']);
return new Element('script', $this->source, $this->attributes);
}
}
105 changes: 105 additions & 0 deletions src/Asset/Link.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

/**
* @package Tagged
* @license http://opensource.org/licenses/MIT
*/

declare(strict_types=1);

namespace DecodeLabs\Tagged\Asset;

use DecodeLabs\Coercion;
use DecodeLabs\Tagged\Asset;
use DecodeLabs\Tagged\AssetTrait;
use DecodeLabs\Tagged\Element;

class Link implements Asset
{
use AssetTrait;

/**
* Init with URL
*
* @param array<string, mixed> $attributes
*/
public function __construct(
int $priority,
string $href,
array $attributes = []
) {
$this->priority = $priority;
$attributes['href'] = $href;

if (!isset($attributes['rel'])) {
$attributes['rel'] = 'stylesheet';
}

$this->setAttributes($attributes);
}

/**
* Set URL
*/
public function setHref(
string $href
): void {
$this->setAttribute('href', $href);
}

/**
* Get URL
*/
public function getHref(): string
{
return Coercion::toString(
$this->getAttribute('href')
);
}

/**
* Set rel
*/
public function setRel(
string $rel
): void {
$this->setAttribute('rel', $rel);
}

/**
* Get rel
*/
public function getRel(): string
{
return Coercion::toString(
$this->getAttribute('rel') ?? 'stylesheet'
);
}

/**
* Set type
*/
public function setType(
string $type
): void {
$this->setAttribute('type', $type);
}

/**
* Get type
*/
public function getType(): ?string
{
return Coercion::toStringOrNull(
$this->getAttribute('type')
);
}

/**
* Render
*/
public function render(): Element
{
return new Element('link', null, $this->attributes);
}
}
120 changes: 120 additions & 0 deletions src/Asset/RemoteScript.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?php

/**
* @package Tagged
* @license http://opensource.org/licenses/MIT
*/

declare(strict_types=1);

namespace DecodeLabs\Tagged\Asset;

use DecodeLabs\Coercion;
use DecodeLabs\Tagged\AssetTrait;
use DecodeLabs\Tagged\Element;

class RemoteScript implements Script
{
use AssetTrait;

/**
* Init with URL
*
* @param array<string, mixed> $attributes
*/
public function __construct(
int $priority,
string $src,
array $attributes = []
) {
$this->priority = $priority;
$attributes['src'] = $src;

if (!isset($attributes['type'])) {
$attributes['type'] = 'text/javascript';
}

$this->setAttributes($attributes);
}

/**
* Set URL
*/
public function setSrc(
string $src
): void {
$this->setAttribute('src', $src);
}

/**
* Get URL
*/
public function getSrc(): string
{
return Coercion::toString(
$this->getAttribute('src')
);
}

/**
* Set async
*/
public function setAsync(
bool $async
): void {
$this->setAttribute('async', $async);
}

/**
* Is async
*/
public function isAsync(): bool
{
return Coercion::toBool($this->getAttribute('async') ?? false);
}

/**
* Set deferred
*/
public function setDeferred(
bool $deferred
): void {
$this->setAttribute('defer', $deferred);
}

/**
* Is deferred
*/
public function isDeferred(): bool
{
return Coercion::toBool($this->getAttribute('defer') ?? false);
}

/**
* Set type
*/
public function setType(
string $type
): void {
$this->setAttribute('type', $type);
}

/**
* Get type
*/
public function getType(): string
{
return Coercion::toString(
$this->getAttribute('type') ?? 'text/javascript'
);
}


/**
* Render
*/
public function render(): Element
{
return new Element('script', null, $this->attributes);
}
}
16 changes: 16 additions & 0 deletions src/Asset/Script.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/**
* @package Tagged
* @license http://opensource.org/licenses/MIT
*/

declare(strict_types=1);

namespace DecodeLabs\Tagged\Asset;

use DecodeLabs\Tagged\Asset;

interface Script extends Asset
{
}
Loading

0 comments on commit c803d46

Please sign in to comment.