Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
rougin committed Oct 16, 2024
2 parents 5d27c27 + f829561 commit ea3bfb4
Show file tree
Hide file tree
Showing 71 changed files with 3,254 additions and 312 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ tests/Fixture/Sample/controllers
tests/Fixture/Sample/models
tests/Fixture/Sample/repositories
tests/Fixture/Sample/views
tests/Fixture/Sample/views/layout
vendor
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ All notable changes to `Combustor` will be documented in this file.

### Added
- Command for creating `combustor.yml` configuration file
- Custom fields in templates using `custom_fields`
- Fields that can be excluded through `excluded_files`
- Specify customized `application` path using `app_path`
- `create:repository` for creating Entity Repositories
- `--empty` for `create:controller`, `create:model`
- `--force` to overwrite existing files

### Changed
- Code coverage provider to `Codecov`
Expand Down
114 changes: 111 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ $ vendor/bin/combustor install:doctrine
```

> [!NOTE]
> Using the `install:wildfire` command installs [Wildfire](https://roug.in/wildfire/) package while the `install:doctrine` installs [Credo](https://roug.in/credo/) package.
> Using the `install:wildfire` command installs the [Wildfire](https://roug.in/wildfire/) package while the `install:doctrine` installs the [Credo](https://roug.in/credo/) package.
## Reminders

Prior in executing any commands, kindly ensure that the **database tables are defined properly** (foreign keys, indexes, relationships, normalizations) in order to minimize the modifications after the code structure has been generated.
Prior in executing any commands, kindly ensure that the _**database tables are defined properly**_ (foreign keys, indexes, relationships, normalizations) in order to minimize the modifications after the code structure has been generated.

Also, please proceed first in generating models, views, or controllers to database tables that are having _**no relationship with other tables**_ in the database.

Expand All @@ -97,6 +97,7 @@ Create a new header and footer file.
**Options**

* `--bootstrap` - adds styling based on Bootstrap
* `--force` - generates file/s even they already exists

**Example**

Expand All @@ -116,6 +117,8 @@ Create a new HTTP controller.

* `--doctrine` - generates a Doctrine-based controller
* `--wildfire` - generates a Wildfire-based controller
* `--empty` - generates an empty HTTP controller
* `--force` - generates file/s even they already exists

> [!NOTE]
> If either `Wildfire` or `Doctrine` is installed, no need to specify it as option for executing a specified command (e.g. `--wildfire`). However if both are installed, a command must have a `--wildfire` or `--doctrine` option added.
Expand All @@ -138,6 +141,8 @@ Create a new model.

* `--doctrine` - generates a Doctrine-based model
* `--wildfire` - generates a Wildfire-based model
* `--empty` - generates an empty model
* `--force` - generates file/s even they already exists

**Example**

Expand All @@ -153,6 +158,10 @@ Create a new entity repository.

* `table` - name of the database table

**Options**

* `--force` - generates file/s even they already exists

**Example**

``` bash
Expand All @@ -175,6 +184,7 @@ Create view templates.
* `--bootstrap` - adds styling based on Bootstrap
* `--doctrine` - generates Doctrine-based views
* `--wildfire` - generates Wildfire-based views
* `--force` - generates file/s even they already exists

**Example**

Expand All @@ -195,6 +205,7 @@ Create a new HTTP controller, model, and view templates.
* `--bootstrap` - adds styling based on Bootstrap
* `--doctrine` - generates a Doctrine-based controller, model, and views
* `--wildfire` - generates a Wildfire-based controller, model, and views
* `--force` - generates file/s even they already exists

**Example**

Expand Down Expand Up @@ -315,7 +326,104 @@ excluded_fields:
```

> [!NOTE]
> By default, the timestamps are added when creating a `combustor.yml` for the first time as they are usually populated automatically by installed ORMs such as `Wildfire` or `Doctrine`.
> The timestamps are added by default when creating a `combustor.yml` for the first time as they are usually populated automatically by installed ORMs such as `Wildfire` or `Doctrine`.

### `custom_fields`

By default, all of the fields generated by `Combustor` to `create` and `edit` pages will use the `form_input` helper:

``` php
<div class="mb-3">
<?= form_label('Email', '', ['class' => 'form-label mb-0']) ?>
<?= form_input('email', set_value('email'), 'class="form-control"') ?>
<?= form_error('email', '<div><span class="text-danger small">', '</span></div>') ?>
</div>
```

However, some fields like `email` and `boolean` types may need to use other form helpers:

``` php
<div class="mb-3">
<?= form_label('Email', '', ['class' => 'form-label mb-0']) ?>
// Still using form_input, but the type is "email" instead
<?= form_input(['type' => 'email', 'name' => 'email', 'value' => set_value('email'), 'class' => 'form-control']) ?>
<?= form_error('email', '<div><span class="text-danger small">', '</span></div>') ?>
</div>
```

``` php
<div class="mb-3">
<?= form_label('Admin', '', ['class' => 'form-label mb-0']) ?>
// Use "form_checkbox" for boolean-based data types
<div>
<?= form_checkbox('admin', true, set_value('admin'), 'class="form-check-input"') ?>
</div>
<?= form_error('admin', '<div><span class="text-danger small">', '</span></div>') ?>
</div>
```

To achieve this, `Combustor` provides a utility for handling specified field names or data types using `custom_fields`:

``` yaml
# combustor.yml
# ...
custom_fields:
- Rougin\Combustor\Template\Fields\BooleanField
```

When adding a custom field, kindly create a class that extends to the `Colfield` class:

``` php
namespace Acme\Fields;
use Rougin\Combustor\Colfield;
class EmailField extends Colfield
{
protected $class = 'form-control';
/**
* If $name is specified, it will check if the current field
* name matches the in this $name field.
*/
protected $name = 'email';
public function getPlate()
{
$field = $this->accessor;
$class = $this->getClass();
/** @var string */
$name = $this->getName();
$html = '<?= form_input([\'type\' => \'email\', \'name\' => \'' . $name . '\', \'value\' => set_value(\'' . $name . '\')]) ?>';
if ($this->edit)
{
$html = str_replace('set_value(\'' . $name . '\')', 'set_value(\'' . $name . '\', ' . $field . ')', $html);
}
$html = str_replace(')]) ?>', '), \'class\' => \'' . $class . '\']) ?>', $html);
return array($html);
}
}
```

Then after creating the custom field, simply add the class name to the `combustor.yml`:

``` yaml
# combustor.yml
# ...
custom_fields:
- Rougin\Combustor\Template\Fields\BooleanField
- Acme\Fields\EmailField
```

## Changelog

Expand Down
8 changes: 0 additions & 8 deletions TODO.txt

This file was deleted.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{
"php": ">=5.4.0",
"rougin/blueprint": "dev-master",
"rougin/classidy": "dev-master",
"rougin/classidy": "~0.1",
"rougin/describe": "dev-master",
"rougin/spark-plug": "~0.6"
},
Expand Down
1 change: 1 addition & 0 deletions phpstyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
$groups = [];
$groups[] = ['template', 'extends'];
$groups[] = ['deprecated', 'link', 'see', 'since', 'codeCoverageIgnore'];
$groups[] = ['ManyToOne', 'JoinColumn'];
$groups[] = ['property', 'property-read', 'property-write'];
$groups[] = ['method'];
$groups[] = ['author', 'copyright', 'license'];
Expand Down
145 changes: 145 additions & 0 deletions src/Colfield.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<?php

namespace Rougin\Combustor;

/**
* @package Combustor
*
* @author Rougin Gutib <rougingutib@gmail.com>
*/
class Colfield
{
/**
* @var string|null
*/
protected $accessor = null;

/**
* @var string|null
*/
protected $class = null;

/**
* @var boolean
*/
protected $edit = false;

/**
* @var string|null
*/
protected $name = null;

/**
* @var boolean
*/
protected $styling = false;

/**
* @var string
*/
protected $tab = '';

/**
* @var string|null
*/
protected $type = null;

/**
* @param boolean $edit
*
* @return self
*/
public function asEdit($edit = true)
{
$this->edit = $edit;

return $this;
}

/**
* @return string|null
*/
public function getClass()
{
if ($this->styling)
{
return $this->class;
}

return null;
}

/**
* @return string|null
*/
public function getName()
{
return $this->name;
}

/**
* @codeCoverageIgnore
*
* @return string[]
*/
public function getPlate()
{
return array();
}

/**
* @return string|null
*/
public function getType()
{
return $this->type;
}

/**
* @param string $accessor
*
* @return self
*/
public function setAccessor($accessor)
{
$this->accessor = $accessor;

return $this;
}

/**
* @param string $name
*
* @return self
*/
public function setName($name)
{
$this->name = $name;

return $this;
}

/**
* @param string $tab
*
* @return self
*/
public function setSpacing($tab = '')
{
$this->tab = $tab;

return $this;
}

/**
* @param boolean $styling
*
* @return self
*/
public function useStyling($styling = true)
{
$this->styling = $styling;

return $this;
}
}
Loading

0 comments on commit ea3bfb4

Please sign in to comment.