Skip to content

Commit

Permalink
Merge pull request #6 from ARCANEDEV/develop
Browse files Browse the repository at this point in the history
Adding the ability to skip the escaping for labels
  • Loading branch information
arcanedev-maroc committed Jun 12, 2016
2 parents 0769502 + 6438487 commit 1d9e5d3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/Contracts/FormBuilderInterface.php
Expand Up @@ -109,10 +109,11 @@ public function token();
* @param string $name
* @param string $value
* @param array $options
* @param bool $escaped
*
* @return \Illuminate\Support\HtmlString
*/
public function label($name, $value = null, array $options = []);
public function label($name, $value = null, array $options = [], $escaped = true);

/**
* Create a form input field.
Expand Down
7 changes: 5 additions & 2 deletions src/FormBuilder.php
Expand Up @@ -350,14 +350,17 @@ public function token()
* @param string $name
* @param string $value
* @param array $options
* @param bool $escaped
*
* @return \Illuminate\Support\HtmlString
*/
public function label($name, $value = null, array $options = [])
public function label($name, $value = null, array $options = [], $escaped = true)
{
$this->labels[] = $name;

return $this->toHtmlString(Helpers\Label::make($name, $value, $options));
return $this->toHtmlString(
Helpers\Label::make($name, $value, $options, $escaped)
);
}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/Helpers/Label.php
Expand Up @@ -12,14 +12,17 @@ class Label
* @param string $name
* @param string $value
* @param array $options
* @param bool $escaped
*
* @return string
*/
public static function make($name, $value = null, array $options = [])
public static function make($name, $value = null, array $options = [], $escaped = true)
{
$value = self::format($name, $value);

return implode('', [
'<label for="' . $name . '"' . Attributes::make($options) . '>',
e(self::format($name, $value)),
$escaped ? e($value) : $value,
'</label>'
]);
}
Expand Down
17 changes: 12 additions & 5 deletions tests/FormBuilderTest.php
Expand Up @@ -116,12 +116,13 @@ public function it_can_close_form()
* @param string $name
* @param string $value
* @param array $options
* @param bool $escaped
*/
public function it_can_make_label($expected, $name, $value, $options)
public function it_can_make_label($expected, $name, $value, $options, $escaped = true)
{
$this->assertEquals(
$expected,
$this->form->label($name, $value, $options)
$this->form->label($name, $value, $options, $escaped)
);
}

Expand Down Expand Up @@ -1334,13 +1335,19 @@ public function provideLabels()
'<label for="foo">Foobar</label>',
'foo',
'Foobar',
[]
[],
],[
'<label for="foo" class="control-label">Foobar</label>',
'foo',
'Foobar',
['class' => 'control-label']
]
['class' => 'control-label'],
],[
'<label for="foo">Foobar <i>bar</i></label>',
'foo',
'Foobar <i>bar</i>',
[],
false
],
];
}

Expand Down

0 comments on commit 1d9e5d3

Please sign in to comment.