diff --git a/src/UIKit.php b/src/UIKit.php index 41c279d..696bcee 100755 --- a/src/UIKit.php +++ b/src/UIKit.php @@ -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(); diff --git a/src/UIKit/Elements/Simple/PageTitle.php b/src/UIKit/Elements/Simple/PageTitle.php new file mode 100755 index 0000000..f533644 --- /dev/null +++ b/src/UIKit/Elements/Simple/PageTitle.php @@ -0,0 +1,44 @@ +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); + + return Html::title($string)->attr(...$this->attributes)->unfold(); + } + + public function reversed(): PageTitle + { + $this->reversed = true; + return $this; + } +} diff --git a/tests/Element/ElementTest.php b/tests/Element/ElementTest.php index 6c22690..2f315c7 100644 --- a/tests/Element/ElementTest.php +++ b/tests/Element/ElementTest.php @@ -88,7 +88,7 @@ public function self_contained_element() AssertEquals::applyWith( '', "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) diff --git a/tests/Html/HtmlElementTest.php b/tests/Html/HtmlElementTest.php index 9432de8..bbcefe2 100644 --- a/tests/Html/HtmlElementTest.php +++ b/tests/Html/HtmlElementTest.php @@ -26,7 +26,7 @@ public function test_ordering_lightweight() AssertEquals::applyWith( '', "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') @@ -148,7 +148,7 @@ public function nested_elements_with_string() AssertEquals::applyWith( 'Hello', "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') diff --git a/tests/UIKit/CompoundTest.php b/tests/UIKit/CompoundTest.php index 5e63b97..6eec9a1 100755 --- a/tests/UIKit/CompoundTest.php +++ b/tests/UIKit/CompoundTest.php @@ -63,7 +63,7 @@ public function web_head() AssertEquals::applyWith( '', "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() diff --git a/tests/UIKit/PageTest.php b/tests/UIKit/PageTest.php index 2540285..5af9945 100755 --- a/tests/UIKit/PageTest.php +++ b/tests/UIKit/PageTest.php @@ -21,7 +21,7 @@ public function web_view() AssertEquals::applyWith( 'UIKit

Hello, World!

', "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( diff --git a/tests/UIKit/SimpleTest.php b/tests/UIKit/SimpleTest.php index ce3603e..61ecae0 100755 --- a/tests/UIKit/SimpleTest.php +++ b/tests/UIKit/SimpleTest.php @@ -28,6 +28,39 @@ public function uikit_falls_back_to_html() ); } + /** + * @test + */ + public function page_title() + { + AssertEquals::applyWith( + 'Hello, World!', + "string", + 3.31, // 2.31, // 0.91, // 0.71, // 0.6, + 5 // 4 + )->unfoldUsing( + UIKit::pageTitle(["Hello, World!"]) + ); + + AssertEquals::applyWith( + 'How are you? | Hello, World!', + "string", + 2.13, // 1.94, // 1.66, // 0.91, // 0.71, // 0.6, + 3 + )->unfoldUsing( + UIKit::pageTitle(["How are you?", "Hello, World!"]) + ); + + 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() + ); + } + /** * @test */ @@ -68,7 +101,7 @@ public function simple_lists() '', "string", 11.32, // 6.34, // 4.93, // 4.69, // 3.8, - 72 // 8 + 73 // 72 // 8 )->unfoldUsing( UIKit::listWith( "hello", @@ -91,7 +124,7 @@ public function simple_lists() AssertEquals::applyWith( '
hello
good-bye
', "string", - 6.44, // 3.52, // 3.2, + 8.69, // 6.44, // 3.52, // 3.2, 1 )->unfoldUsing( UIKit::listWith( @@ -103,7 +136,7 @@ public function simple_lists() AssertEquals::applyWith( '
hello
good-bye
hello
good-bye
good-bye
', "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( @@ -124,7 +157,7 @@ public function images() AssertEquals::applyWith( '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")