From 6e459dc8081803c57f67d880e7a9008088229555 Mon Sep 17 00:00:00 2001 From: Devin Dombrowski - Locutus Date: Wed, 18 Feb 2015 13:57:38 -0800 Subject: [PATCH 1/2] Proposal: add a dl method to HtmlBuilder Method generates a description list of items. --- src/HtmlBuilder.php | 23 ++++++++++++++++++++ tests/HtmlBuilderTest.php | 45 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 tests/HtmlBuilderTest.php diff --git a/src/HtmlBuilder.php b/src/HtmlBuilder.php index 7c5d5fe..55014be 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 From 45857bf2eeaf7bb69eea3cb9a72830afd38e8e3a Mon Sep 17 00:00:00 2001 From: Devin Dombrowski - Locutus Date: Wed, 18 Feb 2015 14:01:17 -0800 Subject: [PATCH 2/2] spaces to tabs --- src/HtmlBuilder.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/HtmlBuilder.php b/src/HtmlBuilder.php index 55014be..6b8f41f 100755 --- a/src/HtmlBuilder.php +++ b/src/HtmlBuilder.php @@ -247,20 +247,20 @@ class HtmlBuilder { * @return string */ public function dl(array $list, array $attributes = []) - { - $attributes = $this->attributes($attributes); + { + $attributes = $this->attributes($attributes); - $html = ""; + $html = ""; - foreach ($list as $key => $value) - { - $html .= "
$key
$value
"; - } + foreach ($list as $key => $value) + { + $html .= "
$key
$value
"; + } - $html .= ''; + $html .= ''; - return $html; - } + return $html; + } /** * Create a listing HTML element.