From 6f35784c8b985ec0c0fcd2a2cbfe1b9ed6f9eda9 Mon Sep 17 00:00:00 2001 From: Paul Vidal Date: Tue, 19 Jan 2016 14:37:12 -0500 Subject: [PATCH] added function tag --- src/HtmlBuilder.php | 15 +++++++++++++++ tests/HtmlBuilderTest.php | 21 +++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/HtmlBuilder.php b/src/HtmlBuilder.php index 0b3495f..bcc5088 100755 --- a/src/HtmlBuilder.php +++ b/src/HtmlBuilder.php @@ -486,6 +486,21 @@ class HtmlBuilder return $this->toHtmlString('attributes($attributes) . '>' . PHP_EOL); } + /** + * Generate an html tag. + * + * @param string $tag + * @param mixed $content + * @param array $attributes + * + * @return \Illuminate\Support\HtmlString + */ + public function tag($tag, $content, array $attributes = []) + { + $content = is_array($content) ? implode(PHP_EOL, $content) : $content; + return $this->toHtmlString('<' . $tag . $this->attributes($attributes) . '>' . PHP_EOL . $this->toHtmlString($content) . PHP_EOL . '' . $tag . '>' . PHP_EOL); + } + /** * Transform the string to an Html serializable object * diff --git a/tests/HtmlBuilderTest.php b/tests/HtmlBuilderTest.php index 5aaa38e..837328c 100644 --- a/tests/HtmlBuilderTest.php +++ b/tests/HtmlBuilderTest.php @@ -46,6 +46,27 @@ class HtmlBuilderTest extends PHPUnit_Framework_TestCase $this->assertEquals('' . PHP_EOL, $result); } + public function testTag() + { + $result1 = $this->htmlBuilder->tag('p', 'Lorem ipsum dolor sit amet.'); + + $result2 = $this->htmlBuilder->tag('p', 'Lorem ipsum dolor sit amet.', ['class' => 'text-center']); + + $result3 = $this->htmlBuilder->tag('div', '
Lorem ipsum dolor sit amet.
', ['class' => 'row']); + + $content = [ + $this->htmlBuilder->image('http://example.com/image1'), + $this->htmlBuilder->image('http://example.com/image2'), + ]; + + $result4 = $this->htmlBuilder->tag('div', $content, ['class' => 'row']); + + $this->assertEquals('' . PHP_EOL . 'Lorem ipsum dolor sit amet.' . PHP_EOL . '
' . PHP_EOL, $result1); + $this->assertEquals('' . PHP_EOL . 'Lorem ipsum dolor sit amet.' . PHP_EOL . '
' . PHP_EOL, $result2); + $this->assertEquals('Lorem ipsum dolor sit amet.
' . PHP_EOL . '