Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions features/scaffold-block.feature
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Feature: WordPress block code scaffolding
"""
And the {PLUGIN_DIR}/blocks/the-green-mile.php file should contain:
"""
$block_js = 'the-green-mile/block.js';
index_js = 'the-green-mile/index.js';
"""
And the {PLUGIN_DIR}/blocks/the-green-mile.php file should contain:
"""
Expand All @@ -58,24 +58,24 @@ Feature: WordPress block code scaffolding
"""
add_action( 'init', 'the_green_mile_block_init' );
"""
And the {PLUGIN_DIR}/blocks/the-green-mile/block.js file should exist
And the {PLUGIN_DIR}/blocks/the-green-mile/block.js file should contain:
And the {PLUGIN_DIR}/blocks/the-green-mile/index.js file should exist
And the {PLUGIN_DIR}/blocks/the-green-mile/index.js file should contain:
"""
registerBlockType( 'movies/the-green-mile', {
"""
And the {PLUGIN_DIR}/blocks/the-green-mile/block.js file should contain:
And the {PLUGIN_DIR}/blocks/the-green-mile/index.js file should contain:
"""
title: __( 'The green mile' ),
"""
And the {PLUGIN_DIR}/blocks/the-green-mile/block.js file should contain:
And the {PLUGIN_DIR}/blocks/the-green-mile/index.js file should contain:
"""
category: 'widgets',
"""
And the {PLUGIN_DIR}/blocks/the-green-mile/block.js file should contain:
And the {PLUGIN_DIR}/blocks/the-green-mile/index.js file should contain:
"""
__( 'Hello from the editor!' )
"""
And the {PLUGIN_DIR}/blocks/the-green-mile/block.js file should contain:
And the {PLUGIN_DIR}/blocks/the-green-mile/index.js file should contain:
"""
__( 'Hello from the saved content!' )
"""
Expand All @@ -96,7 +96,7 @@ Feature: WordPress block code scaffolding

Scenario: Scaffold a block with a specific title provided
When I run `wp scaffold block shawshank-redemption --plugin=movies --title="The Shawshank Redemption"`
Then the {PLUGIN_DIR}/blocks/shawshank-redemption/block.js file should contain:
Then the {PLUGIN_DIR}/blocks/shawshank-redemption/index.js file should contain:
"""
title: __( 'The Shawshank Redemption' ),
"""
Expand All @@ -107,7 +107,7 @@ Feature: WordPress block code scaffolding

Scenario: Scaffold a block with a specific dashicon provided
When I run `wp scaffold block forrest-gump --plugin=movies --dashicon=movie`
Then the {PLUGIN_DIR}/blocks/forrest-gump/block.js file should contain:
Then the {PLUGIN_DIR}/blocks/forrest-gump/index.js file should contain:
"""
icon: 'movie',
"""
Expand All @@ -118,7 +118,7 @@ Feature: WordPress block code scaffolding

Scenario: Scaffold a block with a specific category provided
When I run `wp scaffold block pulp-fiction --plugin=movies --category=embed`
Then the {PLUGIN_DIR}/blocks/pulp-fiction/block.js file should contain:
Then the {PLUGIN_DIR}/blocks/pulp-fiction/index.js file should contain:
"""
category: 'embed',
"""
Expand All @@ -130,7 +130,7 @@ Feature: WordPress block code scaffolding
Scenario: Scaffold a block for an active theme
When I run `wp scaffold block fight-club --theme`
Then the {THEME_DIR}/blocks/fight-club.php file should exist
And the {THEME_DIR}/blocks/fight-club/block.js file should exist
And the {THEME_DIR}/blocks/fight-club/index.js file should exist
And the {THEME_DIR}/blocks/fight-club/editor.css file should exist
And the {THEME_DIR}/blocks/fight-club/style.css file should exist
And STDOUT should be:
Expand All @@ -148,7 +148,7 @@ Feature: WordPress block code scaffolding
Scenario: Scaffold a block for a specific theme
When I run `wp scaffold block intouchables --theme=p2`
Then the {THEME_DIR}/blocks/intouchables.php file should exist
And the {THEME_DIR}/blocks/intouchables/block.js file should exist
And the {THEME_DIR}/blocks/intouchables/index.js file should exist
And the {THEME_DIR}/blocks/intouchables/editor.css file should exist
And the {THEME_DIR}/blocks/intouchables/style.css file should exist
And STDOUT should be:
Expand Down
2 changes: 1 addition & 1 deletion src/Scaffold_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public function block( $args, $assoc_args ) {

$files_written = $this->create_files( array(
"$block_dir/$slug.php" => self::mustache_render( 'block-php.mustache', $data ),
"$block_dir/$slug/block.js" => self::mustache_render( 'block-block-js.mustache', $data ),
"$block_dir/$slug/index.js" => self::mustache_render( 'block-index-js.mustache', $data ),
"$block_dir/$slug/editor.css" => self::mustache_render( 'block-editor-css.mustache', $data ),
"$block_dir/$slug/style.css" => self::mustache_render( 'block-style-css.mustache', $data ),
), $control_args['force'] );
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions templates/block-php.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ function {{machine_name}}_block_init() {
$dir = get_template_directory() . '/blocks';
{{/theme}}

$block_js = '{{slug}}/block.js';
$index_js = '{{slug}}/index.js';
wp_register_script(
'{{slug}}-block-editor',
{{#plugin}}
plugins_url( $block_js, __FILE__ ),
plugins_url( $index_js, __FILE__ ),
{{/plugin}}
{{#theme}}
get_template_directory_uri() . "/blocks/$block_js",
get_template_directory_uri() . "/blocks/$index_js,
{{/theme}}
array(
'wp-blocks',
'wp-i18n',
'wp-element',
),
filemtime( "$dir/$block_js" )
filemtime( "$dir/$index_js" )
);

$editor_css = '{{slug}}/editor.css';
Expand Down