diff --git a/src/HtmlBuilder.php b/src/HtmlBuilder.php index 7c5d5fe..6b8f41f 100755 --- a/src/HtmlBuilder.php +++ b/src/HtmlBuilder.php @@ -239,6 +239,29 @@ class HtmlBuilder { return $this->listing('ul', $list, $attributes); } + /** + * Generate a description list of items. + * + * @param array $list + * @param array $attributes + * @return string + */ + public function dl(array $list, array $attributes = []) + { + $attributes = $this->attributes($attributes); + + $html = ""; + + foreach ($list as $key => $value) + { + $html .= "
$key
$value
"; + } + + $html .= ''; + + return $html; + } + /** * Create a listing HTML element. * diff --git a/tests/HtmlBuilderTest.php b/tests/HtmlBuilderTest.php new file mode 100644 index 0000000..f78d5b8 --- /dev/null +++ b/tests/HtmlBuilderTest.php @@ -0,0 +1,45 @@ +urlGenerator = new UrlGenerator(new RouteCollection, Request::create('/foo', 'GET')); + $this->htmlBuilder = new HtmlBuilder($this->urlGenerator); + } + + + /** + * Destroy the test environment. + */ + public function tearDown() + { + m::close(); + } + + public function testDl() + { + $list = [ + 'foo' => 'bar', + 'bing' => 'baz' + ]; + + $attributes = ['class' => 'example']; + + $result = $this->htmlBuilder->dl($list, $attributes); + + $this->assertEquals('
foo
bar
bing
baz
', $result); + } + +} \ No newline at end of file