Skip to content

Commit

Permalink
Merge branch 'release/1.0.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubmikita committed Apr 12, 2021
2 parents 0ea22ce + 033465c commit beeadbf
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog
All notable changes to this project will be documented in this file.

## 1.0.5

* [Fixed] Invalid `micropackage/acf-block-creator/config` hookname
* [Added] Filters for block tamplate and style file paths

## 1.0.4

* [Fixed] block setup fields behavior
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "micropackage/acf-block-creator",
"version": "1.0.4",
"version": "1.0.5",
"description": "ACF Block Creator - automatic block creation add-on for ACF",
"license": "GPL-3.0-or-later",
"authors": [
Expand Down
41 changes: 36 additions & 5 deletions src/ACFBlockCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static function init( $config = [] ) {
*/
protected function __construct( $config ) {
$this->config = apply_filters(
'micropackage/acf-block-loader/config',
'micropackage/acf-block-creator/config',
wp_parse_args( $config, [
'blocks_dir' => 'blocks',
'scss_dir' => false,
Expand Down Expand Up @@ -276,14 +276,45 @@ public function update_field_group( $field_group ) {
$template
);

$this->root_fs->put_contents( "{$this->config['blocks_dir']}/{$slug}.php", preg_replace( '/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/', "\n\n", $template ) );
$template_dir = apply_filters(
'micropackage/acf-block-creator/block-template-dir',
$this->config['blocks_dir'],
$slug
);

$template_file = apply_filters(
'micropackage/acf-block-creator/block-template-file',
"{$slug}.php",
$slug
);

if ( ! $this->maybe_mkdir( $template_dir ) ) {
return;
}

$this->root_fs->put_contents(
"{$template_dir}/{$template_file}",
preg_replace( '/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/', "\n\n", $template )
);

$scss_dir = apply_filters(
'micropackage/acf-block-creator/block-style-dir',
$this->config['scss_dir'],
$slug
);

// Create block scss partial.
if ( is_string( $this->config['scss_dir'] ) ) {
if ( is_string( $scss_dir ) ) {
$scss_file = apply_filters(
'micropackage/acf-block-creator/block-style-file',
"_{$slug}.scss",
$slug
);

$scss = ".block.$slug {\n/* stylelint-disable */\n}";

if ( $this->maybe_mkdir( $this->config['scss_dir'] ) ) {
$this->root_fs->put_contents( "{$this->config['scss_dir']}/_{$slug}.scss", $scss );
if ( $this->maybe_mkdir( $scss_dir ) ) {
$this->root_fs->put_contents( "{$scss_dir}/{$scss_file}", $scss );
}
}

Expand Down

0 comments on commit beeadbf

Please sign in to comment.