Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions .github/workflows/php8.yml

This file was deleted.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
],
"require": {
"php": "^8.0",
"php": "^8.1",
"8fold/php-xml-builder": "^1.0"
},
"require-dev": {
Expand Down
4 changes: 2 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/Components/Copyright.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class Copyright implements Buildable
{
use BuildableImp;

private $useCopyrightSymbol = true;
private bool $useCopyrightSymbol = true;

private $spellOutCopyright = false;
private bool $spellOutCopyright = false;

private $scope = '';
private string $scope = '';

public static function create(
string $holder,
Expand Down
17 changes: 17 additions & 0 deletions src/Components/FaviconMetroColors.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);

namespace Eightfold\HTMLBuilder\Components;

enum FaviconMetroColors: string
{
case Teal = '#00aba9';
case DarkBlue = '#2b5797';
case LightPurple = '#9f00a7';
case DarkPurple = '#603cba';
case DarkRed = '#b91d47';
case DarkOrange = '#da532c'; // default
case Yellow = '#ffc40d';
case Green = '#00a300';
case Blue = '#2d89ef';
}
187 changes: 187 additions & 0 deletions src/Components/Favicons.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
<?php
declare(strict_types=1);

namespace Eightfold\HTMLBuilder\Components;

use Eightfold\XMLBuilder\Contracts\Buildable;

use Eightfold\XMLBuilder\Concatenate;

use Eightfold\XMLBuilder\Implementations\Buildable as BuildableImp;

use Eightfold\HTMLBuilder\Element;

use Eightfold\HTMLBuilder\Components\FaviconMetroColors;

/**
* We use https://realfavicongenerator.net to generate favicon-related assets.
* We presume the names of these assets will not be changed.
*/
class Favicons implements Buildable
{
use BuildableImp;

private string $appName = '';

private bool $metroUsesWhite;

private FaviconMetroColors $metroTileColor = FaviconMetroColors::DarkOrange;

private string $safariThemeColor = '#5bbad5';

public static function create(
string $path = '',
string $themeColor = '#ffffff'
): self {
return new self($path, $themeColor);
}

final private function __construct(
private string $path,
private string $themeColor
) {
}

private function path(): string
{
return $this->path;
}

private function themeColor(): string
{
return $this->themeColor;
}

private function hasPath(): bool
{
return strlen($this->path()) > 0;
}

private function appName(): string
{
return $this->appName;
}

public function withAppName(string $name): self
{
$this->appName = $name;
return $this;
}

private function hasAppName(): bool
{
return strlen($this->appName()) > 0;
}

public function withMetro(
FaviconMetroColors $tileColor = FaviconMetroColors::DarkOrange,
bool $useWhite = false
): self {
$this->metroTileColor = $tileColor;

if ($useWhite !== false) {
$this->metroUsesWhite = $useWhite;
}

return $this;
}

private function hasMetro(): bool
{
if ($this->metroUsesWhite()) {
return true;
}
return false;
}

private function metroUsesWhite(): bool
{
if (isset($this->metroUsesWhite) === false) {
return false;
}
return $this->metroUsesWhite;
}

public function withSafariThemeColor(string $color): self
{
$this->safariThemeColor = $color;
return $this;
}

private function safariThemeColor(): string
{
return $this->safariThemeColor;
}

public function __toString(): string
{
$elements = [
Element::link()->omitEndTag()->props(
'rel apple-touch-icon',
'sizes 180x180',
'href ' . $this->path() . '/apple-touch-icon.png'
),
Element::link()->omitEndTag()->props(
'rel icon',
'type image/png',
'sizes 32x32',
'href ' . $this->path() . '/favicon-32x32.png'
),
Element::link()->omitEndTag()->props(
'rel icon',
'type image/png',
'sizes 16x16',
'href ' . $this->path() . '/favicon-16x16.png'
),
Element::link()->omitEndTag()->props(
'rel manifest',
'href ' . $this->path() . '/site.webmanifest'
),
Element::meta()->omitEndTag()->props(
'name msapplication-TileColor',
'content ' . $this->metroTileColor->value
),
Element::meta()->omitEndTag()->props(
'name theme-color',
'content ' . $this->themeColor()
),
Element::link()->omitEndTag()->props(
'rel mask-icon',
'href ' . $this->path() . '/safari-pinned-tab.svg',
'color ' . $this->safariThemeColor()
)
];

if ($this->hasPath()) {
$elements[] = Element::link()->omitendTag()->props(
'rel shortcut icon',
'href ' . $this->path() . '/favicon.ico'
);

$elements[] = Element::meta()->omitEndTag()->props(
'name msapplication-config',
'content ' . $this->path() . '/browserconfig.xml'
);
}

if ($this->hasMetro() and $this->metroUsesWhite()) {
$elements[] = Element::meta()->omitEndTag()->props(
'name msapplication-TileImage',
'content ' . $this->path() . '/mstile-144x144.png'
);
}

if ($this->hasAppName()) {
$elements[] = Element::meta()->omitEndTag()->props(
'name application-name',
'content ' . $this->appName()
);

$elements[] = Element::meta()->omitEndTag()->props(
'name apple-mobile-web-app-title',
'content ' . $this->appName()
);
}
return (string) Concatenate::create(...$elements);
}
}
17 changes: 7 additions & 10 deletions src/Document.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<?php

declare(strict_types=1);

namespace Eightfold\HTMLBuilder;

use Stringable;

use Eightfold\XMLBuilder\Comment;
use Eightfold\XMLBuilder\Contracts\Buildable;
use Eightfold\XMLBuilder\Implementations\Buildable as BuildableImp;

use Eightfold\HTMLBuilder\Element;

class Document implements Buildable
{
use BuildableImp;

/**
* @var array<string|Stringable>
*/
Expand All @@ -32,8 +34,8 @@ public static function create(

final private function __construct(
private string $title,
private string $lang = 'en',
private string $charset = 'utf-8'
private string $lang,
private string $charset
) {
}

Expand All @@ -49,7 +51,7 @@ public function body(string|Stringable ...$content): Document
return $this;
}

public function build(): string
public function __toString(): string
{
$doctype = '<!doctype html>' . "\n";
return $doctype . Element::html(
Expand All @@ -62,11 +64,6 @@ public function build(): string
)->props($this->lang())->build();
}

public function __toString(): string
{
return $this->build();
}

private function title(): string
{
return $this->title;
Expand Down
1 change: 0 additions & 1 deletion src/Element.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

declare(strict_types=1);

namespace Eightfold\HTMLBuilder;
Expand Down
Loading