diff --git a/composer.json b/composer.json index a95a167..3e25918 100644 --- a/composer.json +++ b/composer.json @@ -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" }, diff --git a/composer.lock b/composer.lock index 5ab767e..dcce2e8 100644 --- a/composer.lock +++ b/composer.lock @@ -164,27 +164,27 @@ }, { "name": "8fold/php-shoop-shelf", - "version": "0.8.5", + "version": "0.8.6", "source": { "type": "git", "url": "https://github.com/8fold/php-shoop-shelf.git", - "reference": "2ca01d3f2d80b0c2a493bdc506e46f70c49617e5" + "reference": "4086354b9926892f57cab856bdc311defa171928" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/8fold/php-shoop-shelf/zipball/2ca01d3f2d80b0c2a493bdc506e46f70c49617e5", - "reference": "2ca01d3f2d80b0c2a493bdc506e46f70c49617e5", + "url": "https://api.github.com/repos/8fold/php-shoop-shelf/zipball/4086354b9926892f57cab856bdc311defa171928", + "reference": "4086354b9926892f57cab856bdc311defa171928", "shasum": "" }, "require": { - "8fold/php-shoop": "~0.10", - "league/commonmark": "~2.0.1", - "league/flysystem": "~2.0", - "php": "^7.2|^8.0", - "spatie/yaml-front-matter": "~2.0.5" + "8fold/php-shoop": "^0.10.19", + "league/commonmark": "^2.0.2", + "league/flysystem": "^1.1.5|^2.2.3", + "php": "^7.0|^8.0", + "spatie/yaml-front-matter": "^2.0.5" }, "require-dev": { - "phpunit/phpunit": "~9.3.3" + "phpunit/phpunit": "^9.5.8" }, "type": "library", "autoload": { @@ -205,7 +205,7 @@ "description": "Shoop-like objects that do not fit at the 8fold Shoop table.", "support": { "issues": "https://github.com/8fold/php-shoop-shelf/issues", - "source": "https://github.com/8fold/php-shoop-shelf/tree/0.8.5" + "source": "https://github.com/8fold/php-shoop-shelf/tree/0.8.6" }, "funding": [ { @@ -217,7 +217,7 @@ "type": "github" } ], - "time": "2021-08-15T18:47:10+00:00" + "time": "2021-09-21T22:13:37+00:00" }, { "name": "dflydev/dot-access-data", @@ -786,20 +786,20 @@ }, { "name": "nette/utils", - "version": "v3.2.3", + "version": "v3.2.5", "source": { "type": "git", "url": "https://github.com/nette/utils.git", - "reference": "5c36cc1ba9bb6abb8a9e425cf054e0c3fd5b9822" + "reference": "9cd80396ca58d7969ab44fc7afcf03624dfa526e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nette/utils/zipball/5c36cc1ba9bb6abb8a9e425cf054e0c3fd5b9822", - "reference": "5c36cc1ba9bb6abb8a9e425cf054e0c3fd5b9822", + "url": "https://api.github.com/repos/nette/utils/zipball/9cd80396ca58d7969ab44fc7afcf03624dfa526e", + "reference": "9cd80396ca58d7969ab44fc7afcf03624dfa526e", "shasum": "" }, "require": { - "php": ">=7.2 <8.1" + "php": ">=7.2 <8.2" }, "conflict": { "nette/di": "<3.0.6" @@ -865,9 +865,9 @@ ], "support": { "issues": "https://github.com/nette/utils/issues", - "source": "https://github.com/nette/utils/tree/v3.2.3" + "source": "https://github.com/nette/utils/tree/v3.2.5" }, - "time": "2021-08-16T21:05:00+00:00" + "time": "2021-09-20T10:50:11+00:00" }, { "name": "nikic/iter", @@ -1710,16 +1710,16 @@ }, { "name": "nikic/php-parser", - "version": "v4.12.0", + "version": "v4.13.0", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "6608f01670c3cc5079e18c1dab1104e002579143" + "reference": "50953a2691a922aa1769461637869a0a2faa3f53" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/6608f01670c3cc5079e18c1dab1104e002579143", - "reference": "6608f01670c3cc5079e18c1dab1104e002579143", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/50953a2691a922aa1769461637869a0a2faa3f53", + "reference": "50953a2691a922aa1769461637869a0a2faa3f53", "shasum": "" }, "require": { @@ -1760,9 +1760,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.12.0" + "source": "https://github.com/nikic/PHP-Parser/tree/v4.13.0" }, - "time": "2021-07-21T10:44:31+00:00" + "time": "2021-09-20T12:20:58+00:00" }, { "name": "phar-io/manifest", 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..cc287a9 --- /dev/null +++ b/src/UIKit/Elements/Simple/PageTitle.php @@ -0,0 +1,56 @@ +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; + } +} 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..d551355 100755 --- a/tests/UIKit/SimpleTest.php +++ b/tests/UIKit/SimpleTest.php @@ -28,6 +28,48 @@ 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() + ); + + 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 */ @@ -68,7 +110,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 +133,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 +145,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 +166,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")