Skip to content
This repository was archived by the owner on Mar 5, 2023. It is now read-only.

Commit fcbd3ea

Browse files
authored
Merge pull request #50 from 8fold/feed-rss
WebHead initial
2 parents 9c012ad + b124a28 commit fcbd3ea

File tree

4 files changed

+172
-5
lines changed

4 files changed

+172
-5
lines changed

src/UIKit.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,22 @@ static public function stripeElements($formId, $apiKey, $inputLabel, $buttonLabe
9090
}
9191

9292
static public function socialMeta(
93-
string $type,
9493
string $title,
9594
string $url,
9695
string $description,
9796
string $image = "",
97+
string $type = "website",
9898
string $appId = ""
9999
)
100100
{
101101
$class = self::class("socialMeta", self::CLASSES)->unfold();
102-
return new $class($type, $title, $url, $description, $image, $appId);
102+
return new $class($title, $url, $description, $image, $type, $appId);
103+
}
104+
105+
static public function webHead()
106+
{
107+
$class = self::class("webHead", self::CLASSES)->unfold();
108+
return new $class();
103109
}
104110

105111
static public function __callStatic(string $element, array $elements)
@@ -191,7 +197,8 @@ static public function __callStatic(string $element, array $elements)
191197
'doubleWrap' => \Eightfold\Markup\UIKit\Elements\Compound\DoubleWrap::class,
192198
'markdown' => \Eightfold\Markup\UIKit\Elements\Compound\Markdown::class,
193199
'pagination' => \Eightfold\Markup\UIKit\Elements\Compound\Pagination::class,
194-
'socialMeta' => \Eightfold\Markup\UIKit\Elements\Compound\SocialMeta::class
200+
'socialMeta' => \Eightfold\Markup\UIKit\Elements\Compound\SocialMeta::class,
201+
'webHead' => \Eightfold\Markup\UIKit\Elements\Compound\WebHead::class
195202
// , 'primary_nav' => UIKit\Elements\Compound\NavigationPrimary::class
196203
// , 'secondary_nav' => UIKit\Elements\Compound\NavigationSecondary::class
197204
// , 'side_nav' => UIKit\Elements\Compound\NavigationSide::class

src/UIKit/Elements/Compound/SocialMeta.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ class SocialMeta extends HtmlElement
1919
private $meta;
2020

2121
public function __construct(
22-
string $type,
2322
string $title,
2423
string $url,
2524
string $description,
2625
string $image = "",
26+
string $type = "website",
2727
string $appId = ""
2828
)
2929
{
@@ -43,7 +43,7 @@ public function __construct(
4343
}
4444
}
4545

46-
public function twitter($card = "summary_large_image", $site = "")
46+
public function twitter($site = "", $card = "summary_large_image")
4747
{
4848
$this->meta = $this->meta->plus("twitter:card {$card}");
4949
Shoop::string($site)->isNotEmpty(function($result, $site) {
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?php
2+
3+
namespace Eightfold\Markup\UIKit\Elements\Compound;
4+
5+
use Eightfold\Shoop\Shoop;
6+
7+
use Eightfold\Markup\Html\Elements\HtmlElement;
8+
use Eightfold\Markup\Html;
9+
use Eightfold\Markup\UIKit;
10+
11+
class WebHead extends HtmlElement
12+
{
13+
private $favicons = [];
14+
private $styles = [];
15+
private $scripts = [];
16+
private $social = "";
17+
18+
public function __construct()
19+
{
20+
}
21+
22+
/**
23+
*
24+
* @param string $baseIcon ico - base icon
25+
* @param string $appleTouch No specific image type required - for apple touch devices
26+
* @param string $icon32 PNG only - 32px varient (Android)
27+
* @param string $icon16 PNG only - 16px varient (Android)
28+
*
29+
* @return this
30+
*/
31+
public function favicons(
32+
string $baseIcon,
33+
string $appleTouch = "",
34+
string $icon32 = "",
35+
string $icon16 = ""
36+
)
37+
{
38+
$this->favicons = Shoop::array([
39+
Html::link()->attr("type image/x-icon", "rel icon", "href {$baseIcon}")
40+
]);
41+
42+
if (Shoop::string($appleTouch)->isNotEmpty) {
43+
$this->favicons = $this->favicons->plus(
44+
Html::link()->attr("rel apple-touch-icon", "href {$appleTouch}", "sizes 180x180")
45+
);
46+
}
47+
48+
if (Shoop::string($icon32)->isNotEmpty) {
49+
$this->favicons = $this->favicons->plus(
50+
Html::link()->attr("rel image/png", "href {$icon32}", "sizes 32x32")
51+
);
52+
}
53+
54+
if (Shoop::string($icon16)->isNotEmpty) {
55+
$this->favicons = $this->favicons->plus(
56+
Html::link()->attr("rel image/png", "href {$icon16}", "sizes 16x16")
57+
);
58+
}
59+
return $this;
60+
}
61+
62+
public function styles(...$paths)
63+
{
64+
$this->styles = Shoop::array($paths)->each(function($path) {
65+
return Html::link()->attr("rel stylesheet", "href {$path}");
66+
});
67+
return $this;
68+
}
69+
70+
public function scripts(...$paths)
71+
{
72+
$this->scripts = Shoop::array($paths)->each(function($path) {
73+
return Html::script()->attr("src {$path}");
74+
});
75+
return $this;
76+
}
77+
78+
public function social(
79+
string $title,
80+
string $url,
81+
string $description,
82+
string $image = "",
83+
string $type = "website",
84+
string $appId = ""
85+
)
86+
{
87+
$this->social = UIKit::socialMeta(
88+
$title,
89+
$url,
90+
$description,
91+
$image,
92+
$type,
93+
$appId
94+
);
95+
return $this;
96+
}
97+
98+
public function socialTwitter(
99+
string $twitterHandle = "",
100+
string $twitterCard = "summary_large_image"
101+
)
102+
{
103+
$this->social = $this->social->twitter($twitterHandle, $twitterCard);
104+
return $this;
105+
}
106+
107+
public function unfold(): string
108+
{
109+
return Shoop::array([
110+
Html::meta()->attr(
111+
"name viewport",
112+
"content width=device-width,initial-scale=1"
113+
)
114+
])->plus(...$this->favicons)
115+
->plus($this->social)
116+
->plus(...$this->styles)
117+
->plus(...$this->scripts)
118+
->noEmpties()
119+
->each(function($element) {
120+
return $element->unfold();
121+
})->join("");
122+
}
123+
}

tests/UIKit/CompoundTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,41 @@ public function testPaginationUnfold()
156156
$actual = UIKit::pagination(10, 100);
157157
$this->assertEquals($expected, $actual->unfold());
158158
}
159+
160+
public function testWebHead()
161+
{
162+
$expected = '<meta name="viewport" content="width=device-width,initial-scale=1">';
163+
$actual = UIKit::webHead();
164+
$this->assertEquals($expected, $actual->unfold());
165+
166+
$expected = '<meta name="viewport" content="width=device-width,initial-scale=1"><link type="image/x-icon" rel="icon" href="favicon.ico"><link rel="apple-touch-icon" href="apple-touch-icon.png" sizes="180x180"><link rel="image/png" href="favicon-32x32.png" sizes="32x32"><link rel="image/png" href="favicon-16x16.png" sizes="16x16">';
167+
$actual = UIKit::webHead()->favicons(
168+
"favicon.ico",
169+
"apple-touch-icon.png",
170+
"favicon-32x32.png",
171+
"favicon-16x16.png"
172+
);
173+
$this->assertEquals($expected, $actual->unfold());
174+
175+
$expected = '<meta name="viewport" content="width=device-width,initial-scale=1"><link type="image/x-icon" rel="icon" href="favicon.ico"><link rel="stylesheet" href="main.css"><script src="main.js"></script>';
176+
$actual = UIKit::webHead()
177+
->favicons("favicon.ico")
178+
->styles("main.css")
179+
->scripts("main.js");
180+
$this->assertEquals($expected, $actual->unfold());
181+
182+
// <meta content="https://liberatedelephant.com/media/poster.png" property="og:image">
183+
184+
// <meta content="1280" property="og:image:width">
185+
// <meta content="720" property="og:image:height">
186+
// <meta name="twitter:card" content="summary_large_image">
187+
// <meta content="@ElephantTaming" property="twitter:site">
188+
$expected = '<meta name="viewport" content="width=device-width,initial-scale=1"><meta content="website" property="og:type"><meta content="8fold PHP Markup" property="og:title"><meta content="https://8fold.dev/open-source/markup/php" property="og:url"><meta content="Get the HTML out of your PHP with this HTML generator." property="og:description"><meta name="twitter:card" content="summary_large_image"><meta name="twitter:" content="site 8foldPros">';
189+
$actual = UIKit::webHead()->social(
190+
"8fold PHP Markup",
191+
"https://8fold.dev/open-source/markup/php",
192+
"Get the HTML out of your PHP with this HTML generator."
193+
)->socialTwitter("8foldPros");
194+
$this->assertEquals($expected, $actual->unfold());
195+
}
159196
}

0 commit comments

Comments
 (0)