-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from michalsn/feat/decorators
feat: configurable view decorators
- Loading branch information
Showing
14 changed files
with
224 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
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,38 @@ | ||
# Configuration | ||
|
||
To make changes to the config file, we have to have our copy in the `app/Config/Htmx.php`. Luckily, this package comes with handy command that will make this easy. | ||
|
||
When we run: | ||
|
||
php spark htmx:publish | ||
|
||
We will get our copy ready for modifications. | ||
|
||
--- | ||
|
||
Available options: | ||
|
||
- [$toolbarDecorator](#$toolbarDecorator) | ||
- [$errorModalDecorator](#$errorModalDecorator) | ||
- [$skipViewDecoratorsString](#$skipViewDecoratorsString) | ||
|
||
### $toolbarDecorator | ||
|
||
This allows us to disable the `ToolbarDecorator` class. Please read [Debug Toolbar](debug_toolbar.md) page for more information. | ||
|
||
### $errorModalDecorator | ||
|
||
This allows us to disable the `ErrorModalDecorator` class. Please read [Error handling](error_handling.md) page for more information. | ||
|
||
### $skipViewDecoratorsString | ||
|
||
If this string appears in the content of the file, it will prevent CodeIgniter from using both View Decorator classes above - even if they are enabled. | ||
|
||
You can change this string to whatever you want. Just remember to make it unique enough to not use it by accident. | ||
|
||
This may be useful when we want to send an e-mail, which message is prepared via the View file. | ||
Since these decorators are used automatically in the `development` mode (or to be more strict - when `CI_DEBUG` is enabled), we may want to disable all the scripts for the e-mail messages. | ||
|
||
We can add the defined string as an `id` or `class` to the html tag. | ||
|
||
In the `production` environment these decorators are ignored by design. So this is useful only for the `development` mode. |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# Error handling | ||
|
||
By default, when an HTTP error response occurs, htmx is not displaying the error. This library changes it so that in the development mode, errors are displayed in a modal window. | ||
|
||
This feature can be disabled in the [Config](configuration.md) file. |
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
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,45 @@ | ||
<?php | ||
|
||
namespace Michalsn\CodeIgniterHtmx\Commands; | ||
|
||
use CodeIgniter\CLI\BaseCommand; | ||
use CodeIgniter\CLI\CLI; | ||
use CodeIgniter\Publisher\Publisher; | ||
use Throwable; | ||
|
||
class HtmxPublish extends BaseCommand | ||
{ | ||
protected $group = 'Htmx'; | ||
protected $name = 'htmx:publish'; | ||
protected $description = 'Publish Htmx config file into the current application.'; | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function run(array $params) | ||
{ | ||
$source = service('autoloader')->getNamespace('Michalsn\\CodeIgniterHtmx')[0]; | ||
|
||
$publisher = new Publisher($source, APPPATH); | ||
|
||
try { | ||
$publisher->addPaths([ | ||
'Config/Htmx.php', | ||
])->merge(false); | ||
} catch (Throwable $e) { | ||
$this->showError($e); | ||
|
||
return; | ||
} | ||
|
||
foreach ($publisher->getPublished() as $file) { | ||
$contents = file_get_contents($file); | ||
$contents = str_replace('namespace Michalsn\\CodeIgniterHtmx\\Config', 'namespace Config', $contents); | ||
$contents = str_replace('use CodeIgniter\\Config\\BaseConfig', 'use Michalsn\\CodeIgniterHtmx\\Config\\Htmx as BaseHtmx', $contents); | ||
$contents = str_replace('class Htmx extends BaseConfig', 'class Htmx extends BaseHtmx', $contents); | ||
file_put_contents($file, $contents); | ||
} | ||
|
||
CLI::write(CLI::color(' Published! ', 'green') . 'You can customize the configuration by editing the "app/Config/Htmx.php" file.'); | ||
} | ||
} |
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,25 @@ | ||
<?php | ||
|
||
namespace Michalsn\CodeIgniterHtmx\Config; | ||
|
||
use CodeIgniter\Config\BaseConfig; | ||
|
||
class Htmx extends BaseConfig | ||
{ | ||
/** | ||
* Enable / disable ToolbarDecorator. | ||
*/ | ||
public bool $toolbarDecorator = true; | ||
|
||
/** | ||
* Enable / diable ErrorModalDecorator. | ||
*/ | ||
public bool $errorModalDecorator = true; | ||
|
||
/** | ||
* The appearance of this string in the view | ||
* content will skip the htmx decorators. Even | ||
* when they are enabled. | ||
*/ | ||
public string $skipViewDecoratorsString = 'htmxSkipViewDecorators'; | ||
} |
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
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