Skip to content

Commit

Permalink
Merge pull request #29 from php-forge/agregar-tags-div-span
Browse files Browse the repository at this point in the history
Agregar metodos div(), span() a Tag::class.
  • Loading branch information
terabytesoftw committed Jul 22, 2022
2 parents e37febb + bf3225a commit 5dd711d
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/Tag/Tag.php
Expand Up @@ -220,6 +220,26 @@ public static function create(string $tag, string $content = '', array $attribut
return $voidElement . PHP_EOL . $content . '</' . $tag . '>';
}

/**
* The `<div>` HTML element is the generic container for flow content. It has no effect on the content or layout
* until styled in some way using CSS (e.g. styling is directly applied to it, or some kind of layout model like
* Flexbox is applied to its parent element).
*
* @param array $attributes The tag attributes in terms of name-value pairs. These will be rendered as the
* attributes of the resulting tag. The values will be HTML-encoded using {@see Attributes::encode()}.
* See {@see Attributes::render()} for details on how attributes are being rendered.
* @param string $content The content of the tag.
*
* @return string The generated `<div>` HTML element.
*
* @link https://html.spec.whatwg.org/multipage/grouping-content.html#the-div-element
* @link https://html.spec.whatwg.org/multipage/dom.html#global-attributes
*/
public static function div(array $attributes = [], string $content = ''): string
{
return self::create('div', $content, $attributes);
}

/**
* Create a closing tag.
*
Expand Down Expand Up @@ -340,6 +360,28 @@ public static function p(array $attributes = [], string $content = ''): string
return self::create('p', $content, $attributes);
}

/**
* The `<span>` HTML element is a generic inline container for phrasing content, which does not inherently represent
* anything. It can be used to group elements for styling purposes (using the class or id attributes), or because
* they share attribute values, such as lang. It should be used only when no other semantic element is appropriate.
* `<span>` is very much like a `<div>` element, but `<div>` is a block-level element whereas a `<span>` is an
* inline element.
*
* @param array $attributes The tag attributes in terms of name-value pairs. These will be rendered as the
* attributes of the resulting tag. The values will be HTML-encoded using {@see Attributes::encode()}.
* See {@see Attributes::render()} for details on how attributes are being rendered.
* @param string $content The content of the tag.
*
* @return string The generated `<span>` HTML element.
*
* @link https://html.spec.whatwg.org/multipage/text-level-semantics.html#the-span-element
* @link https://html.spec.whatwg.org/multipage/dom.html#global-attributes
*/
public static function span(array $attributes = [], string $content = ''): string
{
return self::create('span', $content, $attributes);
}

/**
* The `<ul>` HTML element represents an unordered list of items, typically rendered as a bulleted list.
*
Expand Down
35 changes: 35 additions & 0 deletions tests/Tag/DivTest.php
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Forge\Html\Tests\Tag;

use Forge\Html\Tag\Tag;
use Forge\TestUtils\Assert;
use PHPUnit\Framework\TestCase;

final class DivTest extends TestCase
{
public function createProvider(): array
{
return [
[[], '', '<div>' . PHP_EOL . '</div>'],
[['class' => 'class'], '', '<div class="class">' . PHP_EOL . '</div>'],
[[], 'Content', '<div>' . PHP_EOL . 'Content' . PHP_EOL . '</div>'],
];
}

/**
* @dataProvider createProvider
*
* @param array $attributes Tag attributes.
* @param string $content Tag content.
* @param string $expected Expected result.
*/
public function testCreate(array $attributes, string $content, string $expected): void
{
$assert = new Assert();

$assert->equalsWithoutLE($expected, Tag::div($attributes, $content));
}
}
35 changes: 35 additions & 0 deletions tests/Tag/SpanTest.php
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Forge\Html\Tests\Tag;

use Forge\Html\Tag\Tag;
use Forge\TestUtils\Assert;
use PHPUnit\Framework\TestCase;

final class SpanTest extends TestCase
{
public function createProvider(): array
{
return [
[[], '', '<span></span>'],
[['class' => 'class'], '', '<span class="class"></span>'],
[[], 'Content', '<span>Content</span>'],
];
}

/**
* @dataProvider createProvider
*
* @param array $attributes Tag attributes.
* @param string $content Tag content.
* @param string $expected Expected result.
*/
public function testCreate(array $attributes, string $content, string $expected): void
{
$assert = new Assert();

$assert->equalsWithoutLE($expected, Tag::span($attributes, $content));
}
}

0 comments on commit 5dd711d

Please sign in to comment.