Skip to content

Commit 4b33042

Browse files
authored
Add Html::div(), Html::span() and Html::p()
1 parent ea31264 commit 4b33042

3 files changed

Lines changed: 60 additions & 0 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ Overall the helper has the following method groups.
8686

8787
### Generating base tags
8888

89+
- div
90+
- span
91+
- p
8992
- ul
9093
- ol
9194
- img

src/Html.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,48 @@ public static function radioList(string $name, $selection = null, array $items =
12241224
return $hidden . static::tag($tag, $visibleContent, $options);
12251225
}
12261226

1227+
/**
1228+
* Generates a div tag. Based on {@see Html::tag()}.
1229+
*
1230+
* @param string $content
1231+
* @param array $options
1232+
* @return string
1233+
*
1234+
* @throws JsonException
1235+
*/
1236+
public static function div(string $content = '', array $options = []): string
1237+
{
1238+
return static::tag('div', $content, $options);
1239+
}
1240+
1241+
/**
1242+
* Generates a span tag. Based on {@see Html::tag()}.
1243+
*
1244+
* @param string $content
1245+
* @param array $options
1246+
* @return string
1247+
*
1248+
* @throws JsonException
1249+
*/
1250+
public static function span(string $content = '', array $options = []): string
1251+
{
1252+
return static::tag('span', $content, $options);
1253+
}
1254+
1255+
/**
1256+
* Generates a paragraph tag. Based on {@see Html::tag()}.
1257+
*
1258+
* @param string $content
1259+
* @param array $options
1260+
* @return string
1261+
*
1262+
* @throws JsonException
1263+
*/
1264+
public static function p(string $content = '', array $options = []): string
1265+
{
1266+
return static::tag('p', $content, $options);
1267+
}
1268+
12271269
/**
12281270
* Generates an unordered list.
12291271
*

tests/HtmlTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,21 @@ public function testRadioList(): void
833833
));
834834
}
835835

836+
public function testDiv(): void
837+
{
838+
$this->assertSame('<div class="red">hello</div>', Html::div('hello', ['class' => 'red']));
839+
}
840+
841+
public function testSpan(): void
842+
{
843+
$this->assertSame('<span class="red">hello</span>', Html::span('hello', ['class' => 'red']));
844+
}
845+
846+
public function testP(): void
847+
{
848+
$this->assertSame('<p class="red">hello</p>', Html::p('hello', ['class' => 'red']));
849+
}
850+
836851
public function testUl(): void
837852
{
838853
$data = [1, 'abc', '<>'];

0 commit comments

Comments
 (0)