Skip to content
This repository was archived by the owner on Mar 5, 2023. It is now read-only.
Closed
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"require": {
"php": "^7.2|^8.0",
"8fold/php-shoop-shelf": "^0.8.5",
"8fold/php-shoop-shelf": "^0.8.6",
"8fold/php-html-spec": "^0.0.5",
"nesbot/carbon": "^2.5"
},
Expand Down
50 changes: 25 additions & 25 deletions composer.lock

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

5 changes: 5 additions & 0 deletions src/UIKit.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ static public function webView($title, ...$content)
return new UIKit\Elements\Pages\WebView($title, ...$content);
}

static public function pageTitle($titleParts, $separater = " | ")
{
return new UIKit\Elements\Simple\PageTitle($titleParts, $separater);
}

static public function webHead()
{
return new UIKit\Elements\Compound\WebHead();
Expand Down
56 changes: 56 additions & 0 deletions src/UIKit/Elements/Simple/PageTitle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Eightfold\Markup\UIKit\Elements\Simple;

use Eightfold\Markup\Html\HtmlElement;

use Eightfold\Markup\Html;

use Eightfold\Markup\UIKit;

class PageTitle extends HtmlElement
{
private $separater = " | ";

private $reversed = false;

private $stringOnly = false;

public function __construct(array $titleParts, string $separater = " | ")
{
$this->main = $titleParts;

$this->separater = $separater;
}

public function unfold(): string
{
if (count($this->main) === 0) {
return "";
}

if ($this->reversed) {
$this->main = array_reverse($this->main);
}

$string = implode($this->separater, $this->main);

if ($this->stringOnly) {
return $string;
}

return Html::title($string)->attr(...$this->attributes)->unfold();
}

public function reversed(): PageTitle
{
$this->reversed = true;
return $this;
}

public function stringOnly(): PageTitle
{
$this->stringOnly = true;
return $this;
}
}
2 changes: 1 addition & 1 deletion tests/Element/ElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function self_contained_element()
AssertEquals::applyWith(
'<a href="/path"></a>',
"string",
1.33, // 1.25, // 1.23, // 1.21, // 1.03, // 0.32, // 0.3, // 0.27, // 0.21, // 0.2,
1.38, // 1.33, // 1.25, // 1.23, // 1.21, // 1.03, // 0.32, // 0.3, // 0.27, // 0.21, // 0.2,
1
)->unfoldUsing(
new Element("a", ["href /path"], false)
Expand Down
4 changes: 2 additions & 2 deletions tests/Html/HtmlElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function test_ordering_lightweight()
AssertEquals::applyWith(
'<p role="alert" id="something" class="somethingElse somethingElse2" style="background: red;" type="some_type" tabindex="1" accesskey="S">Hello</p>',
"string",
10.03, // 9.89, // 9.69, // 8.42, // 8.34, // 7.8, // 7.38, // updated shoop 8.11 // 7.82 // 7.6 // 6.85
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
559
)->unfoldUsing(
Html::p('Hello')
Expand Down Expand Up @@ -148,7 +148,7 @@ public function nested_elements_with_string()
AssertEquals::applyWith(
'<a class="some-class" href="http://example.com">Hello</a>',
"string",
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
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
1
)->unfoldUsing(
Html::a('Hello')->attr('class some-class', 'href http://example.com')
Expand Down
2 changes: 1 addition & 1 deletion tests/UIKit/CompoundTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function web_head()
AssertEquals::applyWith(
'<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>',
"string",
14.08, // 13.84, // 13.31, // 10.88, // 6.17, // 5.86, // 5.14, // 4.95, // 4.47, // 3.73,
14.36, // 14.24, // 14.08, // 13.84, // 13.31, // 10.88, // 6.17, // 5.86, // 5.14, // 4.95, // 4.47, // 3.73,
4 // 3
)->unfoldUsing(
UIKit::webHead()
Expand Down
2 changes: 1 addition & 1 deletion tests/UIKit/PageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function web_view()
AssertEquals::applyWith(
'<!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>',
"string",
18.66, // 17.82, // 17.28, // 13.74, // 10.21 // 9.69 // 9.46
26.99, // 18.66, // 17.82, // 17.28, // 13.74, // 10.21 // 9.69 // 9.46
596
)->unfoldUsing(
UIKit::webView(
Expand Down
50 changes: 46 additions & 4 deletions tests/UIKit/SimpleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,48 @@ public function uikit_falls_back_to_html()
);
}

/**
* @test
*/
public function page_title()
{
AssertEquals::applyWith(
'<title>Hello, World!</title>',
"string",
3.31, // 2.31, // 0.91, // 0.71, // 0.6,
5 // 4
)->unfoldUsing(
UIKit::pageTitle(["Hello, World!"])
);

AssertEquals::applyWith(
'<title>How are you? | Hello, World!</title>',
"string",
2.13, // 1.94, // 1.66, // 0.91, // 0.71, // 0.6,
3
)->unfoldUsing(
UIKit::pageTitle(["How are you?", "Hello, World!"])
);

AssertEquals::applyWith(
'<title>How are you? : Hello, World!</title>',
"string",
1.95, // 1.82, // 0.91, // 0.71, // 0.6,
3
)->unfoldUsing(
UIKit::pageTitle(["Hello, World!", "How are you?"], " : ")->reversed()
);

AssertEquals::applyWith(
'How are you? : Hello, World!',
"string",
1.95, // 1.82, // 0.91, // 0.71, // 0.6,
3
)->unfoldUsing(
UIKit::pageTitle(["Hello, World!", "How are you?"], " : ")->reversed()->stringOnly()
);
}

/**
* @test
*/
Expand Down Expand Up @@ -68,7 +110,7 @@ public function simple_lists()
'<ul><li>hello</li><li>good-bye</li></ul>',
"string",
11.32, // 6.34, // 4.93, // 4.69, // 3.8,
72 // 8
73 // 72 // 8
)->unfoldUsing(
UIKit::listWith(
"hello",
Expand All @@ -91,7 +133,7 @@ public function simple_lists()
AssertEquals::applyWith(
'<dl><dt>hello</dt><dd>good-bye</dd></dl>',
"string",
6.44, // 3.52, // 3.2,
8.69, // 6.44, // 3.52, // 3.2,
1
)->unfoldUsing(
UIKit::listWith(
Expand All @@ -103,7 +145,7 @@ public function simple_lists()
AssertEquals::applyWith(
'<dl><dt>hello</dt><dd>good-bye</dd><dt>hello</dt><dd>good-bye</dd><dd>good-bye</dd></dl>',
"string",
12.37, // 12.16, // 11.53, // 10.71, // 5.25, // 4.59, // 4.49,
12.48, // 12.37, // 12.16, // 11.53, // 10.71, // 5.25, // 4.59, // 4.49,
1
)->unfoldUsing(
UIKit::listWith(
Expand All @@ -124,7 +166,7 @@ public function images()
AssertEquals::applyWith(
'<img src="https://path.to/image.jpg" alt="Alt text">',
"string",
4.4, // 3.94, // 3.31, // 2.37, // 2.3, // 2.03,
5.2, // 4.4, // 3.94, // 3.31, // 2.37, // 2.3, // 2.03,
3
)->unfoldUsing(
UIKit::image("Alt text", "https://path.to/image.jpg")
Expand Down