generated from yii-tools/template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b05cf7f
commit 6ae5c67
Showing
17 changed files
with
271 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# Title | ||
|
||
The `<title>` `HTML` element defines the document's title shown in a browser's title bar or a page's tab. | ||
|
||
It only contains text; tags within the element are ignored. | ||
|
||
## Basic Usage | ||
|
||
Instantiate the `Title` class using `Title::widget()`. | ||
|
||
```php | ||
$title = Title::widget(); | ||
``` | ||
|
||
Or, block style instantiation. | ||
|
||
```php | ||
<?= Title::begin() ?> | ||
// ... content to be wrapped by `div` element | ||
<?= Title::end() ?> | ||
``` | ||
|
||
## Setting Attributes | ||
|
||
Use the provided methods to set specific attributes for the a element. | ||
|
||
```php | ||
// setting class attribute | ||
$title->class('container'); | ||
``` | ||
|
||
Or, use the `attributes` method to set multiple attributes at once. | ||
|
||
```php | ||
$title->attributes(['class' => 'container', 'style' => 'background-color: #eee;']); | ||
``` | ||
|
||
## Adding Content | ||
|
||
If you want to include content within the `div` tag, use the `content` method. | ||
|
||
```php | ||
$title->content('My content'); | ||
``` | ||
|
||
Or, use `begin()` and `end()` methods to wrap content. | ||
|
||
```php | ||
<?= Title::begin() ?> | ||
My content | ||
<?= Title::end() ?> | ||
``` | ||
|
||
## Rendering | ||
|
||
Generate the `HTML` output using the `render` method, for simple instantiation. | ||
|
||
```php | ||
$html = $title->render(); | ||
``` | ||
|
||
Or, use the magic `__toString` method. | ||
|
||
```php | ||
$html = (string) $title; | ||
``` | ||
|
||
## Common Use Cases | ||
|
||
Below are examples of common use cases: | ||
|
||
```php | ||
// adding multiple attributes | ||
$title->class('external')->content('My content'); | ||
|
||
// using data attributes | ||
$title->dataAttributes(['analytics' => 'trackClick']); | ||
``` | ||
|
||
Explore additional methods for setting various attributes such as `lang`, `name`, `style`, `title`, etc. | ||
|
||
## Attributes | ||
|
||
Refer to the [Attribute Tests](https://github.com/php-forge/html/blob/main/tests/Title/AttributeTest.php) for | ||
comprehensive examples. | ||
|
||
The following methods are available for setting attributes: | ||
|
||
| Method | Description | | ||
| ----------------- | ------------------------------------------------------------------------------------------------ | | ||
| `attributes()` | Set multiple `attributes` at once. | | ||
| `class()` | Set the `class` attribute. | | ||
| `content()` | Set the `content` within the `div` element. | | ||
| `dataAttributes()`| Set multiple `data-attributes` at once. | | ||
| `id()` | Set the `id` attribute. | | ||
| `lang()` | Set the `lang` attribute. | | ||
| `name()` | Set the `name` attribute. | | ||
| `style()` | Set the `style` attribute. | | ||
| `title()` | Set the `title` attribute. | | ||
|
||
## Custom methods | ||
|
||
Refer to the [Custom Methods Tests](https://github.com/php-forge/html/blob/main/tests/Title/CustomMethodTest.php) for | ||
comprehensive examples. | ||
|
||
The following methods are available for customizing the `HTML` output: | ||
|
||
| Method | Description | | ||
| --------- | -------------------------------------------------------------------------------------------------------- | | ||
| `begin()` | Initializes the `Title` widget. | | ||
| `end()` | Finalizes the `Title` widget. | | ||
| `render()`| Generates the `HTML` output. | | ||
| `widget()`| Instantiates the `Title::class`. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PHPForge\Html\Tests\Title; | ||
|
||
use PHPForge\Html\Title; | ||
use PHPForge\Support\Assert; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @psalm-suppress PropertyNotSetInConstructor | ||
*/ | ||
final class AttributeTest extends TestCase | ||
{ | ||
public function testAttributes(): void | ||
{ | ||
Assert::equalsWithoutLE( | ||
<<<HTML | ||
<title class="value"> | ||
</title> | ||
HTML, | ||
Title::widget()->attributes(['class' => 'value'])->render() | ||
); | ||
} | ||
|
||
public function testClass(): void | ||
{ | ||
Assert::equalsWithoutLE( | ||
<<<HTML | ||
<title class="value"> | ||
</title> | ||
HTML, | ||
Title::widget()->class('value')->render() | ||
); | ||
} | ||
|
||
public function testContent(): void | ||
{ | ||
Assert::equalsWithoutLE( | ||
<<<HTML | ||
<title> | ||
value | ||
</title> | ||
HTML, | ||
Title::widget()->content('value')->render() | ||
); | ||
} | ||
|
||
public function testDataAttributes(): void | ||
{ | ||
Assert::equalsWithoutLE( | ||
<<<HTML | ||
<title data-value="value"> | ||
</title> | ||
HTML, | ||
Title::widget()->dataAttributes(['value' => 'value'])->render() | ||
); | ||
} | ||
|
||
public function testId(): void | ||
{ | ||
Assert::equalsWithoutLE( | ||
<<<HTML | ||
<title id="value"> | ||
</title> | ||
HTML, | ||
Title::widget()->id('value')->render() | ||
); | ||
} | ||
|
||
public function testLang(): void | ||
{ | ||
Assert::equalsWithoutLE( | ||
<<<HTML | ||
<title lang="value"> | ||
</title> | ||
HTML, | ||
Title::widget()->lang('value')->render() | ||
); | ||
} | ||
|
||
public function testName(): void | ||
{ | ||
Assert::equalsWithoutLE( | ||
<<<HTML | ||
<title name="value"> | ||
</title> | ||
HTML, | ||
Title::widget()->name('value')->render() | ||
); | ||
} | ||
|
||
public function testStyle(): void | ||
{ | ||
Assert::equalsWithoutLE( | ||
<<<HTML | ||
<title style="value"> | ||
</title> | ||
HTML, | ||
Title::widget()->style('value')->render() | ||
); | ||
} | ||
|
||
public function testTitle(): void | ||
{ | ||
Assert::equalsWithoutLE( | ||
<<<HTML | ||
<title title="value"> | ||
</title> | ||
HTML, | ||
Title::widget()->title('value')->render() | ||
); | ||
} | ||
} |
Oops, something went wrong.