Skip to content

Commit

Permalink
Updated :: Namespace params and package name on block.json
Browse files Browse the repository at this point in the history
  • Loading branch information
bplv112 committed Nov 10, 2022
1 parent aecffa7 commit 9c87dc8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion documentation/WP-CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
With WP CLI you can create blocks easily and quickly. This is a great way to create blocks for your project. Use the following command to scaffold a block.

```bash
wp abs create_portable_block myblock --title="This is myblock" --desc="This block is used for wds." --keyword="myblock" --icon="table-row-before"
wp abs create_portable_block myblock --title="This is myblock" --desc="This block is used for wds." --keyword="myblock" --icon="table-row-before" --namespace="abs"
```

## Parameters
Expand Down
21 changes: 8 additions & 13 deletions wpcli/class-blocks-scaffold.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function create_portable_block( $name, $assoc_args ) {
'desc' => '',
'keywords' => strtolower( $this->name ),
'icon' => 'table-row-before',
'namespace' => 'WebDevStudios\abs',
'namespace' => 'abs/',
]
);

Expand Down Expand Up @@ -133,19 +133,12 @@ private function create_block_dir() {
* @since 2.0.0
* @author Biplav Subedi <[email protected]>
*/
private function create_block_render_php( $args ) {
$local_file = ABS_ROOT_PATH . 'wpcli/block-starter/block.php';
$content = '';
private function create_block_render_php() {
$dir = ABS_ROOT_PATH . 'wpcli/block-starter/block.php';

if ( $this->init_filesystem()->exists( $local_file ) ) {
$content = $this->init_filesystem()->get_contents( $local_file );
$content = str_replace( 'WebDevStudios\abs', esc_html( $args['namespace'] ), $content );

if ( ! $this->init_filesystem()->put_contents( ABS_ROOT_PATH . 'src/blocks/' . $this->name . '/block.php', $content ) ) {
WP_CLI::error( 'ERROR :: Could not create a render file.', true );
}
} else {
WP_CLI::error( 'ERROR :: Could not create a render file.', true );
// copy block render file.
if ( ! $this->init_filesystem()->copy( $dir, ABS_ROOT_PATH . 'src/blocks/' . $this->name . '/' . $this->name . '.php' ) ) {
WP_CLI::error( 'ERROR :: Could not create render file.', true );
}

}
Expand Down Expand Up @@ -191,12 +184,14 @@ private function create_block_json( $args ) {
'{{title}}',
'{{description}}',
'{{icon}}',
'abs/',
],
[
$this->name,
$args['title'],
$args['desc'],
$args['icon'],
trailingslashit( $args['namespace'] ),
],
$content
);
Expand Down

0 comments on commit 9c87dc8

Please sign in to comment.