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

Commit c4d2d98

Browse files
authored
Page title (#80)
* Page title * update tests * tests * Update SimpleTest.php * Update SimpleTest.php * Update SimpleTest.php * Update SimpleTest.php * tests * Update SimpleTest.php * Update SimpleTest.php
1 parent 3ff13f5 commit c4d2d98

File tree

7 files changed

+91
-9
lines changed

7 files changed

+91
-9
lines changed

src/UIKit.php

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ static public function webView($title, ...$content)
1515
return new UIKit\Elements\Pages\WebView($title, ...$content);
1616
}
1717

18+
static public function pageTitle($titleParts, $separater = " | ")
19+
{
20+
return new UIKit\Elements\Simple\PageTitle($titleParts, $separater);
21+
}
22+
1823
static public function webHead()
1924
{
2025
return new UIKit\Elements\Compound\WebHead();
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace Eightfold\Markup\UIKit\Elements\Simple;
4+
5+
use Eightfold\Markup\Html\HtmlElement;
6+
7+
use Eightfold\Markup\Html;
8+
9+
use Eightfold\Markup\UIKit;
10+
11+
class PageTitle extends HtmlElement
12+
{
13+
private $separater = " | ";
14+
15+
private $reversed = false;
16+
17+
public function __construct(array $titleParts, string $separater = " | ")
18+
{
19+
$this->main = $titleParts;
20+
21+
$this->separater = $separater;
22+
}
23+
24+
public function unfold(): string
25+
{
26+
if (count($this->main) === 0) {
27+
return "";
28+
}
29+
30+
if ($this->reversed) {
31+
$this->main = array_reverse($this->main);
32+
}
33+
34+
$string = implode($this->separater, $this->main);
35+
36+
return Html::title($string)->attr(...$this->attributes)->unfold();
37+
}
38+
39+
public function reversed(): PageTitle
40+
{
41+
$this->reversed = true;
42+
return $this;
43+
}
44+
}

tests/Element/ElementTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function self_contained_element()
8888
AssertEquals::applyWith(
8989
'<a href="/path"></a>',
9090
"string",
91-
1.33, // 1.25, // 1.23, // 1.21, // 1.03, // 0.32, // 0.3, // 0.27, // 0.21, // 0.2,
91+
1.38, // 1.33, // 1.25, // 1.23, // 1.21, // 1.03, // 0.32, // 0.3, // 0.27, // 0.21, // 0.2,
9292
1
9393
)->unfoldUsing(
9494
new Element("a", ["href /path"], false)

tests/Html/HtmlElementTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function test_ordering_lightweight()
2626
AssertEquals::applyWith(
2727
'<p role="alert" id="something" class="somethingElse somethingElse2" style="background: red;" type="some_type" tabindex="1" accesskey="S">Hello</p>',
2828
"string",
29-
10.03, // 9.89, // 9.69, // 8.42, // 8.34, // 7.8, // 7.38, // updated shoop 8.11 // 7.82 // 7.6 // 6.85
29+
10.52, // 10.03, // 9.89, // 9.69, // 8.42, // 8.34, // 7.8, // 7.38, // updated shoop 8.11 // 7.82 // 7.6 // 6.85
3030
559
3131
)->unfoldUsing(
3232
Html::p('Hello')
@@ -148,7 +148,7 @@ public function nested_elements_with_string()
148148
AssertEquals::applyWith(
149149
'<a class="some-class" href="http://example.com">Hello</a>',
150150
"string",
151-
4.04, // 3.99, // 3.93, // 3.9, // 3.75, // 3.32, // 1.76, // 1.6, // 1.56, // 1.21, // 1.13, // 0.97, // 0.87, // 2.37
151+
4.87, // 4.5, // 4.04, // 3.99, // 3.93, // 3.9, // 3.75, // 3.32, // 1.76, // 1.6, // 1.56, // 1.21, // 1.13, // 0.97, // 0.87, // 2.37
152152
1
153153
)->unfoldUsing(
154154
Html::a('Hello')->attr('class some-class', 'href http://example.com')

tests/UIKit/CompoundTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function web_head()
6363
AssertEquals::applyWith(
6464
'<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>',
6565
"string",
66-
14.08, // 13.84, // 13.31, // 10.88, // 6.17, // 5.86, // 5.14, // 4.95, // 4.47, // 3.73,
66+
14.36, // 14.24, // 14.08, // 13.84, // 13.31, // 10.88, // 6.17, // 5.86, // 5.14, // 4.95, // 4.47, // 3.73,
6767
4 // 3
6868
)->unfoldUsing(
6969
UIKit::webHead()

tests/UIKit/PageTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function web_view()
2121
AssertEquals::applyWith(
2222
'<!doctype html><html><head><title>UIKit</title><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"></head><body class="theme"><p>Hello, World!</p></body></html>',
2323
"string",
24-
18.66, // 17.82, // 17.28, // 13.74, // 10.21 // 9.69 // 9.46
24+
26.99, // 18.66, // 17.82, // 17.28, // 13.74, // 10.21 // 9.69 // 9.46
2525
596
2626
)->unfoldUsing(
2727
UIKit::webView(

tests/UIKit/SimpleTest.php

+37-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,39 @@ public function uikit_falls_back_to_html()
2828
);
2929
}
3030

31+
/**
32+
* @test
33+
*/
34+
public function page_title()
35+
{
36+
AssertEquals::applyWith(
37+
'<title>Hello, World!</title>',
38+
"string",
39+
3.31, // 2.31, // 0.91, // 0.71, // 0.6,
40+
5 // 4
41+
)->unfoldUsing(
42+
UIKit::pageTitle(["Hello, World!"])
43+
);
44+
45+
AssertEquals::applyWith(
46+
'<title>How are you? | Hello, World!</title>',
47+
"string",
48+
2.13, // 1.94, // 1.66, // 0.91, // 0.71, // 0.6,
49+
3
50+
)->unfoldUsing(
51+
UIKit::pageTitle(["How are you?", "Hello, World!"])
52+
);
53+
54+
AssertEquals::applyWith(
55+
'<title>How are you? : Hello, World!</title>',
56+
"string",
57+
1.95, // 1.82, // 0.91, // 0.71, // 0.6,
58+
3
59+
)->unfoldUsing(
60+
UIKit::pageTitle(["Hello, World!", "How are you?"], " : ")->reversed()
61+
);
62+
}
63+
3164
/**
3265
* @test
3366
*/
@@ -68,7 +101,7 @@ public function simple_lists()
68101
'<ul><li>hello</li><li>good-bye</li></ul>',
69102
"string",
70103
11.32, // 6.34, // 4.93, // 4.69, // 3.8,
71-
72 // 8
104+
73 // 72 // 8
72105
)->unfoldUsing(
73106
UIKit::listWith(
74107
"hello",
@@ -91,7 +124,7 @@ public function simple_lists()
91124
AssertEquals::applyWith(
92125
'<dl><dt>hello</dt><dd>good-bye</dd></dl>',
93126
"string",
94-
6.44, // 3.52, // 3.2,
127+
8.69, // 6.44, // 3.52, // 3.2,
95128
1
96129
)->unfoldUsing(
97130
UIKit::listWith(
@@ -103,7 +136,7 @@ public function simple_lists()
103136
AssertEquals::applyWith(
104137
'<dl><dt>hello</dt><dd>good-bye</dd><dt>hello</dt><dd>good-bye</dd><dd>good-bye</dd></dl>',
105138
"string",
106-
12.37, // 12.16, // 11.53, // 10.71, // 5.25, // 4.59, // 4.49,
139+
12.48, // 12.37, // 12.16, // 11.53, // 10.71, // 5.25, // 4.59, // 4.49,
107140
1
108141
)->unfoldUsing(
109142
UIKit::listWith(
@@ -124,7 +157,7 @@ public function images()
124157
AssertEquals::applyWith(
125158
'<img src="https://path.to/image.jpg" alt="Alt text">',
126159
"string",
127-
4.4, // 3.94, // 3.31, // 2.37, // 2.3, // 2.03,
160+
5.2, // 4.4, // 3.94, // 3.31, // 2.37, // 2.3, // 2.03,
128161
3
129162
)->unfoldUsing(
130163
UIKit::image("Alt text", "https://path.to/image.jpg")

0 commit comments

Comments
 (0)