Compare commits

...
12 Commits
Author SHA1 Message Date
Robin Malfait 819a87d564 Merge pull request #10 from RobinMalfait/5.0
Adding date form input.
2015-02-20 17:13:49 +01:00
Robin Malfait d5618c3b22 Adding Carbon support 2015-02-20 17:07:06 +01:00
Robin Malfait 3cd9e81140 Adding date form input. 2015-02-20 16:56:57 +01:00
Robin Malfait d6157b709b Merge pull request #7 from devinfd/5.0
Proposal: add a dl method to HtmlBuilder
2015-02-19 17:13:31 +01:00
Kayla Daniels 2d25e47fb6 Merge pull request #8 from driesvints/feature/number-field
Add number input field. Fixes #4
2015-02-19 11:12:30 -05:00
Dries Vints 6a4f601e8b Add number input field. Fixes #4 2015-02-19 15:15:32 +01:00
Devin Dombrowski - Locutus 45857bf2ee spaces to tabs 2015-02-18 14:01:17 -08:00
Devin Dombrowski - Locutus 6e459dc808 Proposal: add a dl method to HtmlBuilder
Method generates a description list of items.
2015-02-18 13:57:38 -08:00
Adam Engebretson f229d1e629 Merge branch 'master' into 5.0 2015-02-05 11:11:09 -06:00
Adam Engebretson 2c93fdf913 Updating blade syntax docs
Signed-off-by: Adam Engebretson <adam@enge.me>
2015-02-05 11:10:57 -06:00
Adam Engebretson 9be410c461 Adding Alias docs
Signed-off-by: Adam Engebretson <adam@enge.me>
2015-02-05 11:10:07 -06:00
Adam Engebretson 8451f29340 Merge branch '5.0' 2015-02-05 10:40:56 -06:00
5 changed files with 140 additions and 4 deletions

No files matched your search

+15 -4
View File
@@ -33,14 +33,25 @@ Next, update Composer from the Terminal:
composer update composer update
Finally, add your new provider to the `providers` array of `config/app.php`: Next, add your new provider to the `providers` array of `config/app.php`:
```php ```php
'providers' => [ 'providers' => [
// ... // ...
'Collective\Html\HtmlServiceProvider', 'Collective\Html\HtmlServiceProvider',
// ... // ...
]; ],
```
Finally, add two class aliases to the `aliases` array of `config/app.php`:
```php
'aliases' => [
// ...
'Form' => 'Collective\Html\FormFacade',
'Html' => 'Collective\Html\HtmlFacade',
// ...
],
``` ```
<a name="opening-a-form"></a> <a name="opening-a-form"></a>
@@ -48,9 +59,9 @@ Finally, add your new provider to the `providers` array of `config/app.php`:
#### Opening A Form #### Opening A Form
{{ Form::open(array('url' => 'foo/bar')) }} {!! Form::open(array('url' => 'foo/bar')) !!}
// //
{{ Form::close() }} {!! Form::close() !!}
By default, a `POST` method will be assumed; however, you are free to specify another method: By default, a `POST` method will be assumed; however, you are free to specify another method:
+32
View File
@@ -1,5 +1,6 @@
<?php namespace Collective\Html; <?php namespace Collective\Html;
use Carbon\Carbon;
use Illuminate\Routing\UrlGenerator; use Illuminate\Routing\UrlGenerator;
use Illuminate\Session\Store as Session; use Illuminate\Session\Store as Session;
use Illuminate\Support\Traits\Macroable; use Illuminate\Support\Traits\Macroable;
@@ -298,6 +299,37 @@ class FormBuilder {
return $this->input('email', $name, $value, $options); return $this->input('email', $name, $value, $options);
} }
/**
* Create a number input field.
*
* @param string $name
* @param string $value
* @param array $options
* @return string
*/
public function number($name, $value = null, $options = array())
{
return $this->input('number', $name, $value, $options);
}
/**
* Create a date input field.
*
* @param string $name
* @param string $value
* @param array $options
* @return string
*/
public function date($name, $value = null, $options = array())
{
if ($value instanceof Carbon)
{
$value = $value->format('Y-m-d');
}
return $this->input('date', $name, $value, $options);
}
/** /**
* Create a url input field. * Create a url input field.
* *
+23
View File
@@ -239,6 +239,29 @@ class HtmlBuilder {
return $this->listing('ul', $list, $attributes); 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 = "<dl{$attributes}>";
foreach ($list as $key => $value)
{
$html .= "<dt>$key</dt><dd>$value</dd>";
}
$html .= '</dl>';
return $html;
}
/** /**
* Create a listing HTML element. * Create a listing HTML element.
* *
+25
View File
@@ -171,6 +171,31 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
} }
public function testFormNumber()
{
$form1 = $this->formBuilder->number('foo');
$form2 = $this->formBuilder->number('foo', 1);
$form3 = $this->formBuilder->number('foo', null, ['class' => 'span2']);
$this->assertEquals('<input name="foo" type="number">', $form1);
$this->assertEquals('<input name="foo" type="number" value="1">', $form2);
$this->assertEquals('<input class="span2" name="foo" type="number">', $form3);
}
public function testFormDate()
{
$form1 = $this->formBuilder->date('foo');
$form2 = $this->formBuilder->date('foo', '2015-02-20');
$form3 = $this->formBuilder->date('foo', \Carbon\Carbon::now());
$form4 = $this->formBuilder->date('foo', null, ['class' => 'span2']);
$this->assertEquals('<input name="foo" type="date">', $form1);
$this->assertEquals('<input name="foo" type="date" value="2015-02-20">', $form2);
$this->assertEquals('<input name="foo" type="date" value="' . \Carbon\Carbon::now()->format('Y-m-d') . '">', $form3);
$this->assertEquals('<input class="span2" name="foo" type="date">', $form4);
}
public function testFormFile() public function testFormFile()
{ {
$form1 = $this->formBuilder->file('foo'); $form1 = $this->formBuilder->file('foo');
+45
View File
@@ -0,0 +1,45 @@
<?php
use Illuminate\Session\Store;
use Mockery as m;
use Illuminate\Http\Request;
use Collective\Html\FormBuilder;
use Collective\Html\HtmlBuilder;
use Illuminate\Routing\UrlGenerator;
use Illuminate\Routing\RouteCollection;
class HtmlBuilderTest extends PHPUnit_Framework_TestCase {
/**
* Setup the test environment.
*/
public function setUp()
{
$this->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('<dl class="example"><dt>foo</dt><dd>bar</dd><dt>bing</dt><dd>baz</dd></dl>', $result);
}
}