Skip to content

Commit

Permalink
Merge branch 'release/1.0.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubmikita committed Apr 12, 2021
2 parents 2afdfc7 + d00733c commit c91739a
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 8 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Changelog
All notable changes to this project will be documented in this file.

## 1.0.4

* [Added] Possibility to load blocks from subfolders (block-name/template.php instead of the default block-name.php)
* [Fixed] Error with invalid array key if file didn't have a block header
* [Fixed] Hardcoded default blocks path
* [Fixed] Missing Filesystem dependency, thanks to @joshuafredrickson

## 1.0.3

* [Added] Filters for config
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "micropackage/block-loader",
"version": "1.0.3",
"version": "1.0.4",
"description": "Block Loader - automatic Gutenberg blocks from template files.",
"license": "GPL-3.0-or-later",
"authors": [
Expand All @@ -20,7 +20,8 @@
"require": {
"php": ">=5.6",
"micropackage/singleton": "^1.1",
"micropackage/dochooks": "^1.0"
"micropackage/dochooks": "^1.0",
"micropackage/filesystem": "^1.1"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",
Expand Down
47 changes: 45 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions src/BlockLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public function register_metabox_blocks( $meta_boxes ) {
public function get_blocks() {
$paths = apply_filters(
'micropackage/block-loader/paths',
[ wp_normalize_path( "$this->root_dir/blocks" ) ]
[ wp_normalize_path( "{$this->root_dir}/{$this->config['dir']}" ) ]
);

$blocks = [];
Expand All @@ -210,11 +210,19 @@ private function get_blocks_from_path( $path ) {

if ( $files ) {
foreach ( $files as $file ) {
$filepath = $fs->path( $file['name'] );
if ( $fs->is_file( $file['name'] ) ) {
$filename = $file['name'];
} elseif ( $fs->is_file( "{$file['name']}/template.php" ) ) {
$filename = "{$file['name']}/template.php";
} else {
continue;
}

$filepath = $fs->path( $filename );
$data = $this->get_block_data( $filepath );
$slug = basename( $filepath, '.php' );
$slug = basename( $file['name'], '.php' );

if ( ! $data['title'] ) {
if ( ! isset( $data['title'] ) ) {
continue;
}

Expand Down

0 comments on commit c91739a

Please sign in to comment.