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
0218b7a
commit d57e50e
Showing
10 changed files
with
248 additions
and
92 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# Meta | ||
|
||
The `<meta>` `HTML` element represents metadata that cannot be represented by other HTML meta-related elements, like | ||
`<base>`, `<link>`, `<script>`, `<style>`, or `<title>`. | ||
|
||
## Basic Usage | ||
|
||
Instantiate the `Meta` class using `Meta::widget()`. | ||
|
||
```php | ||
$meta = Meta::widget(); | ||
``` | ||
|
||
## Setting Attributes | ||
|
||
Use the provided methods to set specific attributes for the a element. | ||
|
||
```php | ||
// setting class attribute | ||
$meta->class('external'); | ||
``` | ||
|
||
Or, use the `attributes` method to set multiple attributes at once. | ||
|
||
```php | ||
$meta->attributes(['class' => 'external', 'id' => 'MyId']); | ||
``` | ||
|
||
## Adding Content | ||
|
||
If you want to include content within the `meta` tag, use the `content` method. | ||
|
||
The first parameter is the `name` attribute and the second parameter is the `content` value. | ||
|
||
```php | ||
$meta->content('csrf', 'value'); | ||
``` | ||
|
||
### Adding HTTP-Equiv | ||
|
||
If you want to include `http-equiv` within the `meta` tag, use the `httpEquiv` method. | ||
|
||
The first parameter is the `http-equiv` attribute and the second parameter is the `content` value. | ||
|
||
```php | ||
$meta->httpEquiv('refresh', '30'); | ||
``` | ||
|
||
## Rendering | ||
|
||
Generate the `HTML` output using the `render` method. | ||
|
||
```php | ||
$html = $meta->render(); | ||
``` | ||
|
||
Or, use the magic `__toString` method. | ||
|
||
```php | ||
$html = (string) $meta; | ||
``` | ||
|
||
## Common Use Cases | ||
|
||
Below are examples of common use cases: | ||
|
||
```php | ||
// adding multiple attributes | ||
$meta->class('external')->content('viewport', 'width=device-width, initial-scale=1'); | ||
``` | ||
|
||
Explore additional methods for setting various attributes such as `httpEquiv`, `id`, `lang` and more. | ||
|
||
## Attributes | ||
|
||
Refer to the [Attribute Tests](https://github.com/php-forge/html/blob/main/tests/Meta/AttributeTest.php) for comprehensive | ||
examples. | ||
|
||
The following methods are available for setting attributes: | ||
|
||
| Method | Description | | ||
| ----------------- | ------------------------------------------------------------------------------------------------ | | ||
| `attributes()` | Set multiple `attributes` at once. | | ||
| `charset()` | Set the `charset` attribute. | | ||
| `class()` | Set the `class` attribute. | | ||
| `content()` | Set the `content` within the `meta` element. | | ||
| `httpEquiv()` | Set the `http-equiv` attribute. | | ||
| `id()` | Set the `id` attribute. | | ||
| `lang()` | Set the `lang` attribute. | | ||
| `name()` | Set the `name` attribute. | | ||
| `style()` | Set the `style` attribute. | | ||
|
||
## Custom methods | ||
|
||
Refer to the [Custom Method Test](https://github.com/php-forge/html/blob/main/tests/Meta/CustomMethodTest.php) for | ||
comprehensive examples. | ||
|
||
The following methods are available for customizing the `HTML` output: | ||
|
||
| Method | Description | | ||
| ---------------------------- | ------------------------------------------------------------------------------------- | | ||
| `render()` | Generates the `HTML` output. | | ||
| `widget()` | Instantiates the `Meta::class`. | |
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,95 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PHPForge\Html\Tests\Meta; | ||
|
||
use PHPForge\Html\Meta; | ||
use PHPForge\Support\Assert; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @psalm-suppress PropertyNotSetInConstructor | ||
*/ | ||
final class AttributeTest extends TestCase | ||
{ | ||
public function testAttributes(): void | ||
{ | ||
Assert::equalsWithoutLE( | ||
<<<HTML | ||
<meta class="value"> | ||
HTML, | ||
Meta::widget()->attributes(['class' => 'value'])->render() | ||
); | ||
} | ||
|
||
public function testCharset(): void | ||
{ | ||
Assert::equalsWithoutLE( | ||
<<<HTML | ||
<meta charset="value"> | ||
HTML, | ||
Meta::widget()->charset('value')->render() | ||
); | ||
} | ||
|
||
public function testClass(): void | ||
{ | ||
Assert::equalsWithoutLE( | ||
<<<HTML | ||
<meta class="value"> | ||
HTML, | ||
Meta::widget()->attributes(['class' => 'value'])->render() | ||
); | ||
} | ||
|
||
public function testContent(): void | ||
{ | ||
Assert::equalsWithoutLE( | ||
<<<HTML | ||
<meta name="name" content="value"> | ||
HTML, | ||
Meta::widget()->content('name', 'value')->render() | ||
); | ||
} | ||
|
||
public function testHttpEquiv(): void | ||
{ | ||
Assert::equalsWithoutLE( | ||
<<<HTML | ||
<meta http-equiv="name" content="value"> | ||
HTML, | ||
Meta::widget()->httpEquiv('name', 'value')->render() | ||
); | ||
} | ||
|
||
public function testId(): void | ||
{ | ||
Assert::equalsWithoutLE( | ||
<<<HTML | ||
<meta id="value"> | ||
HTML, | ||
Meta::widget()->id('value')->render() | ||
); | ||
} | ||
|
||
public function testLang(): void | ||
{ | ||
Assert::equalsWithoutLE( | ||
<<<HTML | ||
<meta lang="value"> | ||
HTML, | ||
Meta::widget()->lang('value')->render() | ||
); | ||
} | ||
|
||
public function testStyle(): void | ||
{ | ||
Assert::equalsWithoutLE( | ||
<<<HTML | ||
<meta style="value"> | ||
HTML, | ||
Meta::widget()->style('value')->render() | ||
); | ||
} | ||
} |
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,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PHPForge\Html\Tests\Meta; | ||
|
||
use PHPForge\Html\Meta; | ||
use PHPForge\Support\Assert; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @psalm-suppress PropertyNotSetInConstructor | ||
*/ | ||
final class CustomMethodTest extends TestCase | ||
{ | ||
public function testRender(): void | ||
{ | ||
Assert::equalsWithoutLE( | ||
<<<HTML | ||
<meta> | ||
HTML, | ||
Meta::widget()->render() | ||
); | ||
} | ||
} |
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,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PHPForge\Html\Tests\Meta; | ||
|
||
use PHPForge\Html\Meta; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @psalm-suppress PropertyNotSetInConstructor | ||
*/ | ||
final class ImmutableTest extends TestCase | ||
{ | ||
public function testImmutable(): void | ||
{ | ||
$meta = Meta::widget(); | ||
|
||
$this->assertNotSame($meta, $meta->content('', '')); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.