Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: tanthammar/tall-blueprint-addon
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.9.3
Choose a base ref
...
head repository: tanthammar/tall-blueprint-addon
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 19 commits
  • 20 files changed
  • 3 contributors

Commits on Aug 9, 2021

  1. Update README.md

    tanthammar authored Aug 9, 2021
    Copy the full SHA
    533800c View commit details

Commits on Oct 5, 2021

  1. Copy the full SHA
    1bed0cd View commit details

Commits on Oct 17, 2021

  1. Copy the full SHA
    4cfb937 View commit details
  2. Copy the full SHA
    56f71e6 View commit details
  3. Merge pull request #1 from lintaba/lintaba-patch-1

    class.stub, set dummymodel to an existing value
    lintaba authored Oct 17, 2021
    Copy the full SHA
    ed73c30 View commit details
  4. Copy the full SHA
    5af0da2 View commit details

Commits on Oct 19, 2021

  1. Merge pull request #2 from lintaba/dev-master

    Upgrade blueprint to support ^2.0
    tanthammar authored Oct 19, 2021
    Copy the full SHA
    8b7046a View commit details
  2. Merge pull request #3 from lintaba/patch-1

    class.stub, set dummymodel to an existing value
    tanthammar authored Oct 19, 2021
    Copy the full SHA
    18ab33b View commit details

Commits on Jan 10, 2022

  1. upd blueprint dependency

    tanthammar authored Jan 10, 2022
    Copy the full SHA
    0cddae8 View commit details
  2. tall-forms dependency

    tanthammar authored Jan 10, 2022
    Copy the full SHA
    c940964 View commit details
  3. upd dependency

    tanthammar authored Jan 10, 2022
    Copy the full SHA
    851022f View commit details
  4. requirements

    tanthammar authored Jan 10, 2022
    Copy the full SHA
    b0af922 View commit details
  5. upd installation

    tanthammar committed Jan 10, 2022
    Copy the full SHA
    ea6135b View commit details

Commits on Feb 16, 2022

  1. Laravel 9

    tanthammar committed Feb 16, 2022
    Copy the full SHA
    d4df46c View commit details

Commits on Nov 18, 2022

  1. typhints

    tanthammar committed Nov 18, 2022
    Copy the full SHA
    3892f55 View commit details

Commits on Jun 18, 2023

  1. Copy the full SHA
    d89c680 View commit details
  2. import Str

    ljoboy committed Jun 18, 2023
    Copy the full SHA
    5038401 View commit details
  3. import Str

    ljoboy committed Jun 18, 2023
    Copy the full SHA
    20f04b5 View commit details

Commits on Jun 21, 2023

  1. Copy the full SHA
    4fd3bb9 View commit details
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
composer.lock
/vendor
/vendor
/.idea
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ Auto generate [TALL-forms](https://github.com/tanthammar/tall-forms/wiki) for al
* Review generated code, it's not perfect :)

## Requirements
* tall-forms >= v7.8.4
* tall-forms >= v7.8.4 || v8
* blueprint >= 1.20


11 changes: 5 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -20,15 +20,14 @@
}
],
"require": {
"illuminate/pipeline": "^6.0 || ^7.0 || ^8.0",
"illuminate/support": "^6.0 || ^7.0 || ^8.0",
"laravel-shift/blueprint": "^1.20",
"tanthammar/tall-forms": "^7.9.3 || ^8.0 || dev-master"
"laravel/framework": "^8.0|^9.0",
"laravel-shift/blueprint": "^2.0",
"tanthammar/tall-forms": "^8.0|dev-master|v9.x-dev"
},
"require-dev": {
"orchestra/testbench": "^4.0 || ^5.0 || ^6.0",
"mockery/mockery": "^1.3",
"phpunit/phpunit": "^9.0"
"orchestra/testbench": "^6.0",
"phpunit/phpunit": "^9.3"
},
"autoload": {
"psr-4": {
29 changes: 13 additions & 16 deletions src/Generators/ViewGenerator.php
Original file line number Diff line number Diff line change
@@ -5,26 +5,24 @@


use Blueprint\Contracts\Generator;
use Blueprint\Models\Controller;
use Blueprint\Models\Statements\RenderStatement;
use Blueprint\Tree;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Str;

class ViewGenerator implements Generator
{
/**
* @var \Illuminate\Contracts\Filesystem\Filesystem
*/
private $files;

const tall_forms_actions = [
private ?Filesystem $files;

private const tall_forms_actions = [
'create', 'store', 'edit', 'update', 'destroy'
];

/**
* @var bool
*/
private $is_tall_form = false;
private bool $is_tall_form = false;

private $model = '';
private ?string $model = '';

public function __construct($files)
{
@@ -37,13 +35,13 @@ public function output(Tree $tree): array

$stub = $this->files->stub('view.stub');

/** @var \Blueprint\Models\Controller $controller */
/** @var Controller $controller */
foreach ($tree->controllers() as $controller) {
foreach ($controller->methods() as $method => $statements) {
//start tall-forms
if (in_array($method, self::tall_forms_actions)) {
if (in_array($method, self::tall_forms_actions, false)) {
$this->is_tall_form = true;
$this->model = \Str::lower($controller->name());
$this->model = Str::lower($controller->name());
} else {
$this->is_tall_form = false;
$this->model = '';
@@ -80,16 +78,15 @@ public function types(): array
return ['controllers', 'views'];
}

protected function getPath(string $view)
protected function getPath(string $view): string
{
return 'resources/views/' . str_replace('.', '/', $view) . '.blade.php';
}

protected function populateStub(string $stub, RenderStatement $renderStatement): string
{
if ($this->is_tall_form) {
$stub = str_replace('{{--', null, $stub);
$stub = str_replace('--}}', null, $stub);
$stub = str_replace(['{{--', '--}}'], [null, null], $stub);
$template = '<livewire:forms.' . $this->model . '-form :' . $this->model . '="$' . $this->model . '"/>';
$stub = str_replace('{{ view }} template', $template, $stub);
} else {
2 changes: 0 additions & 2 deletions src/HasStubPath.php
Original file line number Diff line number Diff line change
@@ -6,8 +6,6 @@ trait HasStubPath
{
/**
* Returns the stub path for this package.
*
* @return string
*/
protected function stubPath(): string
{
8 changes: 3 additions & 5 deletions src/TallBlueprintAddonServiceProvider.php
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ class TallBlueprintAddonServiceProvider extends ServiceProvider implements Defer
/**
* Bootstrap the application services.
*/
public function boot()
public function boot(): void
{
if ($this->app->runningInConsole()) {
$this->publishes([
@@ -31,7 +31,7 @@ public function boot()
/**
* Register the application services.
*/
public function register()
public function register(): void
{
$this->mergeConfigFrom(
dirname(__DIR__) . '/config/tall_forms_blueprint.php',
@@ -65,10 +65,8 @@ public function register()

/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
public function provides(): array
{
return [
'command.blueprint.build',
18 changes: 8 additions & 10 deletions src/TallBlueprintGenerator.php
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
use Blueprint\Contracts\Generator;
use Blueprint\Models\Model;
use Blueprint\Tree;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Pipeline\Pipeline;
use Illuminate\Support\Str;
use Tanthammar\TallBlueprintAddon\Contracts\Task;
@@ -16,14 +17,11 @@ class TallBlueprintGenerator implements Generator
{
use HasStubPath, HasSharedGeneratorFunctions;

/** @var \Illuminate\Contracts\Filesystem\Filesystem */
protected $files;
protected ?Filesystem $files;

/** @var array */
private $imports = [];
private array $imports = [];

/** @var array */
private $tasks = [];
private array $tasks = [];

public function __construct($files)
{
@@ -36,7 +34,7 @@ public function output(Tree $tree): array

$stub = $this->getStub();

/** @var \Blueprint\Models\Model $model */
/** @var Model $model */
foreach ($tree->models() as $model) {

$path = $this->outputPath($model->name());
@@ -71,12 +69,12 @@ protected function populateStub(string $stub, Model $model): string
->thenReturn();


$stub = $this->sharedStrReplace($stub, $model->name(), $model->fullyQualifiedClassName());
$stub = (string)$this->sharedStrReplace($stub, $model->name(), $model->fullyQualifiedClassName());
$stub = str_replace('// fields...', $data['fields'], $stub);

$this->imports = array_unique(array_merge($this->imports, $data['imports']));
$stub = str_replace('use Tanthammar\TallForms\TallFormComponent;', implode(PHP_EOL, $data['imports']), $stub);

return $stub;
return str_replace('use Tanthammar\TallForms\TallFormComponent;', implode(PHP_EOL, $data['imports']), $stub);
}


30 changes: 16 additions & 14 deletions src/TallMethodsBlueprintGenerator.php
Original file line number Diff line number Diff line change
@@ -3,8 +3,9 @@
namespace Tanthammar\TallBlueprintAddon;

use Blueprint\Contracts\Generator;
use Blueprint\Models\Controller;
use Blueprint\Tree;
use Illuminate\Support\Str;
use Illuminate\Filesystem\Filesystem;
use Tanthammar\TallBlueprintAddon\Tasks\HasSharedGeneratorFunctions;
use Tanthammar\TallBlueprintAddon\Tasks\OnCreate;
use Tanthammar\TallBlueprintAddon\Tasks\OnDelete;
@@ -14,8 +15,7 @@ class TallMethodsBlueprintGenerator implements Generator
{
use HasStubPath, HasSharedGeneratorFunctions;

/** @var \Illuminate\Contracts\Filesystem\Filesystem */
protected $files;
protected ?Filesystem $files;

public function __construct($files)
{
@@ -28,7 +28,7 @@ public function output(Tree $tree): array

$stub = $this->getStub();

/** @var \Blueprint\Models\Controller $controller */
/** @var Controller $controller */
foreach ($tree->controllers() as $controller) {
if (!$controller->isApiResource()) {
$path = $this->outputPath($controller->name());
@@ -51,35 +51,37 @@ protected function outputPath($name): string
}


protected function populateStub(string $stub, \Blueprint\Models\Controller $controller)
protected function populateStub(string $stub, Controller $controller): array|string
{
$data = [];

foreach ($controller->methods() as $name => $statements) {
data_set($data, 'name', $controller->name());
//switch action name
if ($name == 'store') {
if ($name === 'store') {
data_set($data, 'action', 'create');
$data = (new onCreate($statements, $data))->handle();
}
if ($name == 'update') {
if ($name === 'update') {
data_set($data, 'action', 'update');
$data = (new onUpdate($statements, $data))->handle();
}
if ($name == 'destroy') {
if ($name === 'destroy') {
data_set($data, 'action', 'delete');
$data = (new onDelete($statements, $data))->handle();
}
}

$stub = str_replace('// create...', data_get($data, 'create'), $stub);
$stub = str_replace('// update...', data_get($data, 'update'), $stub);
$stub = str_replace('// delete...', data_get($data, 'delete'), $stub);
$stub = $this->sharedStrReplace($stub, $controller->name(), $controller->fullyQualifiedClassName());
$stub = str_replace(
['// create...', '// update...', '// delete...'],
[data_get($data, 'create'), data_get($data, 'update'), data_get($data, 'delete')],
$stub);

$stub = (string)$this->sharedStrReplace($stub, $controller->name(), $controller->fullyQualifiedClassName());

$imports = array_unique(data_get($data, 'imports', []));
$stub = str_replace('use Controllers;', implode(PHP_EOL, $imports), $stub);

return $stub;
return str_replace('use Controllers;', implode(PHP_EOL, $imports), $stub);
}


6 changes: 3 additions & 3 deletions src/Tasks/AddIdentifierField.php
Original file line number Diff line number Diff line change
@@ -12,14 +12,14 @@ class AddIdentifierField implements Task
{
use InteractWithRelationships;

const INDENT = ' ';
protected const INDENT = ' ';

public function handle($data, Closure $next): array
{
$column = $this->identifierColumn($data['model']);

$identifierName = $column->name() === 'id' ? '"ID", "id"' : "'".$column->name()."'";
if(config('tall-forms-blueprint.sponsor')) {
$identifierName = $column->name() === 'id' ? '"ID", "id"' : "'" . $column->name() . "'";
if (config('tall-forms-blueprint.sponsor')) {
$data['fields'] .= 'Number::make(' . $identifierName . '),' . PHP_EOL . PHP_EOL;
$data['imports'][] = 'Number';
} else {
16 changes: 10 additions & 6 deletions src/Tasks/AddRegularFields.php
Original file line number Diff line number Diff line change
@@ -10,9 +10,9 @@

class AddRegularFields implements Task
{
const INDENT = ' ';
const INDENT_PLUS = ' ';
const LICENCE_TYPE_FIELDS = [
protected const INDENT = ' ';
protected const INDENT_PLUS = ' ';
protected const LICENCE_TYPE_FIELDS = [
'Input' => 'Input',
'Number' => 'Input',
'DatePicker' => 'Input',
@@ -74,7 +74,9 @@ public function handle($data, Closure $next): array
'unsignedtinyinteger',
]
)) {
if (!$sponsor) $field .= PHP_EOL . self::INDENT_PLUS . "->type('number')";
if (!$sponsor) {
$field .= PHP_EOL . self::INDENT_PLUS . "->type('number')";
}
$field .= PHP_EOL . self::INDENT_PLUS . '->step(1)->min(1)';
}

@@ -85,7 +87,9 @@ public function handle($data, Closure $next): array
'unsigneddecimal',
]
)) {
if (!$sponsor) $field .= PHP_EOL . self::INDENT_PLUS . "->type('number')";
if (!$sponsor) {
$field .= PHP_EOL . self::INDENT_PLUS . "->type('number')";
}
$field .= PHP_EOL . self::INDENT_PLUS . '->step(0.10)->min(0.10)';
}

@@ -130,7 +134,7 @@ private function addRules(Column $column, string $tableName): string
return PHP_EOL . self::INDENT_PLUS . '->rules([' . trim(implode(',', $rules)) . '])';
}

private function fieldType(string $dataType)
private function fieldType(string $dataType): string
{
static $fieldTypes = [
'id' => 'Number',
Loading