-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* enhance(console): Add make:form command * chore(docs): Add console command to docs * chore(docs): Add error message customization to docs * fix(component): Fix hidden slot * fix(ci): Fix CircleCI
- Loading branch information
Showing
7 changed files
with
244 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,52 @@ | ||
version: 2.1 | ||
|
||
orbs: | ||
php: circleci/php@0.1 | ||
|
||
# To be removed after https://github.com/CircleCI-Public/php-orb/pull/11 | ||
executors: | ||
default: | ||
executors: | ||
php-73: | ||
docker: | ||
- image: 'circleci/php:7.3-stretch' | ||
jobs: | ||
build-php: | ||
executor: php-73 | ||
steps: | ||
- run: php -v | ||
- checkout | ||
- restore_cache: | ||
keys: | ||
- composer-v1-{{ checksum "composer.lock" }} | ||
- composer-v1- | ||
- run: composer install -n --prefer-dist --no-scripts --no-suggest | ||
- run: composer lint | ||
- save_cache: | ||
key: composer-v1-{{ checksum "composer.lock" }} | ||
paths: | ||
- vendor | ||
description: The official next-gen CircleCI PHP Docker image. | ||
parameters: | ||
tag: | ||
description: The `cimg/php` Docker image version tag. | ||
type: string | ||
docker: | ||
- image: 'cimg/php:<< parameters.tag >>' | ||
|
||
# To be removed after https://github.com/CircleCI-Public/php-orb/issues/23 | ||
jobs: | ||
build-php: | ||
parameters: | ||
version: | ||
default: '7.4' | ||
description: The `cimg/php` Docker image version tag. | ||
type: string | ||
executor: | ||
name: default | ||
tag: << parameters.version >> | ||
steps: | ||
# Because squizlabs/php_codesniffer requires ext-simplexml. | ||
# To be removed after https://github.com/CircleCI-Public/cimg-php/pull/51 | ||
- run: sudo apt-get update | ||
- run: sudo apt-get install -y php<< parameters.version >>-xml | ||
- run: php -v | ||
- run: composer --version | ||
# To be removed after https://github.com/CircleCI-Public/cimg-php/pull/52 | ||
- run: sudo chown $(whoami):$(whoami) ~/.composer | ||
- checkout | ||
- php/load-cache: | ||
key: v1 | ||
- run: composer install -n --prefer-dist | ||
- run: composer lint | ||
- php/save-cache: | ||
key: v1 | ||
|
||
workflows: | ||
build: | ||
jobs: | ||
- default/build-php | ||
- build-php: | ||
name: build-php-<< matrix.version >> | ||
matrix: | ||
parameters: | ||
version: ['7.4', '7.3', '7.2'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
<?php | ||
|
||
namespace Log1x\HtmlForms\Console; | ||
|
||
use Illuminate\Support\Str; | ||
use Roots\Acorn\Console\Commands\GeneratorCommand; | ||
|
||
class FormMakeCommand extends GeneratorCommand | ||
{ | ||
/** | ||
* The console command signature. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'make:form {name* : The form slug.}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Create a new form view for the HTML Forms plugin.'; | ||
|
||
/** | ||
* The view stub used when generated. | ||
* | ||
* @var string|bool | ||
*/ | ||
protected $view = 'default'; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle() | ||
{ | ||
$this->task("Generating {$this->getViewName()}", function () { | ||
if (! $this->files->exists($this->getViewPath())) { | ||
$this->files->makeDirectory($this->getViewPath()); | ||
} | ||
|
||
if ($this->files->exists($this->getView())) { | ||
return; | ||
} | ||
|
||
$this->files->put($this->getView(), $this->files->get($this->getViewStub())); | ||
}); | ||
|
||
return $this->summary(); | ||
} | ||
|
||
/** | ||
* Return the full view destination. | ||
* | ||
* @return string | ||
*/ | ||
public function getView() | ||
{ | ||
return Str::finish($this->getViewPath(), $this->getViewName()); | ||
} | ||
|
||
/** | ||
* Return the view destination filename. | ||
* | ||
* @return string | ||
*/ | ||
public function getViewName() | ||
{ | ||
return Str::finish( | ||
str_replace('.', '/', Str::slug(Str::snake($this->getNameInput()))), | ||
'.blade.php' | ||
); | ||
} | ||
|
||
/** | ||
* Return the view destination path. | ||
* | ||
* @return string | ||
*/ | ||
public function getViewPath() | ||
{ | ||
return Str::finish($this->getPaths(), '/forms/'); | ||
} | ||
|
||
/** | ||
* Get the view stub file for the generator. | ||
* | ||
* @return string | ||
*/ | ||
protected function getViewStub() | ||
{ | ||
return __DIR__ . "/stubs/views/{$this->view}.stub"; | ||
} | ||
|
||
/** | ||
* Return the applications view path. | ||
* | ||
* @param string $name | ||
* @return void | ||
*/ | ||
protected function getPaths() | ||
{ | ||
$paths = $this->app['view.finder']->getPaths(); | ||
|
||
if (count($paths) === 1) { | ||
return head($paths); | ||
} | ||
|
||
return $this->choice('Where do you want to create the view(s)?', $paths, head($paths)); | ||
} | ||
|
||
/** | ||
* Return the block creation summary. | ||
* | ||
* @return void | ||
*/ | ||
protected function summary() | ||
{ | ||
$this->line(''); | ||
$this->line('<fg=blue;options=bold>Form View Created</>'); | ||
$this->line(" ⮑ <fg=blue>{$this->shortenPath($this->getView(), 4)}</>"); | ||
} | ||
|
||
/** | ||
* Returns a shortened path. | ||
* | ||
* @param string $path | ||
* @param int $i | ||
* @return string | ||
*/ | ||
protected function shortenPath($path, $i = 3) | ||
{ | ||
return collect( | ||
explode('/', $path) | ||
)->slice(-$i, $i)->implode('/'); | ||
} | ||
|
||
/** | ||
* Get the stub file for the generator. | ||
* | ||
* @return string | ||
*/ | ||
protected function getStub() | ||
{ | ||
// | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<x-html-forms :form="$form" class="my-form"> | ||
<input | ||
name="name" | ||
type="text" | ||
placeholder="Full Name" | ||
required | ||
> | ||
|
||
<input | ||
name="emailAddress" | ||
type="email" | ||
placeholder="Email Address" | ||
required | ||
> | ||
|
||
<input | ||
type="submit" | ||
value="Submit" | ||
/> | ||
</x-html-forms> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters