Merge pull request #188 from skyrpex/patch-1
Treat boolean attributes as HTML properties
This commit is contained in:
commit
8956f00475
2 files changed
+17
-1
No files matched your search
@@ -447,6 +447,11 @@ class HtmlBuilder
|
||||
if (is_numeric($key)) {
|
||||
$key = $value;
|
||||
}
|
||||
|
||||
// Treat boolean attributes as HTML properties
|
||||
if (is_bool($value)) {
|
||||
return $value ? $key : '';
|
||||
}
|
||||
|
||||
if (! is_null($value)) {
|
||||
return $key . '="' . e($value) . '"';
|
||||
|
||||
@@ -58,7 +58,7 @@ class HtmlBuilderTest extends PHPUnit_Framework_TestCase
|
||||
$this->htmlBuilder->image('http://example.com/image1'),
|
||||
$this->htmlBuilder->image('http://example.com/image2'),
|
||||
];
|
||||
|
||||
|
||||
$result4 = $this->htmlBuilder->tag('div', $content, ['class' => 'row']);
|
||||
|
||||
$this->assertEquals('<p>' . PHP_EOL . 'Lorem ipsum dolor sit amet.' . PHP_EOL . '</p>' . PHP_EOL, $result1);
|
||||
@@ -115,4 +115,15 @@ class HtmlBuilderTest extends PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('<a href="mailto:person@example.com" class="example-link"><span>First Name Last</span></a>', $result1);
|
||||
$this->assertEquals('<a href="mailto:person@example.com" class="example-link"><span>First Name Last</span></a>', $result2);
|
||||
}
|
||||
|
||||
public function testBooleanAttributes()
|
||||
{
|
||||
$result1 = $this->htmlBuilder->attributes(['my-property' => true]);
|
||||
|
||||
$result2 = $this->htmlBuilder->attributes(['my-property' => false]);
|
||||
|
||||
$this->assertEquals('my-property', trim($result1));
|
||||
|
||||
$this->assertEquals('', trim($result2));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user