Skip to content

Commit

Permalink
Create Block: Split JS source file into parts for esnext template (#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo authored Apr 24, 2020
1 parent 2739fa9 commit 605f47d
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 28 deletions.
4 changes: 4 additions & 0 deletions packages/create-block/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Master

### Enhancements

- Update `esnext` template to scaffold 3 JavaScript source files to illustrate how ES modules help to better organize code.

## 0.10.0 (2020-04-01)

### New Features
Expand Down
2 changes: 2 additions & 0 deletions packages/create-block/lib/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ const templates = {
'.editorconfig',
'.gitignore',
'editor.css',
'src/edit.js',
'src/index.js',
'src/save.js',
'$slug.php',
'style.css',
'readme.txt',
Expand Down
24 changes: 24 additions & 0 deletions packages/create-block/lib/templates/esnext/src/edit.js.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Retrieves the translation of text.
*
* @see https://developer.wordpress.org/block-editor/packages/packages-i18n/
*/
import { __ } from '@wordpress/i18n';

/**
* The edit function describes the structure of your block in the context of the
* editor. This represents what the editor will render when the block is used.
*
* @see https://developer.wordpress.org/block-editor/developers/block-api/block-edit-save/#edit
*
* @param {Object} [props] Properties passed from the editor.
*
* @return {WPElement} Element to render.
*/
export default function Edit( { className } ) {
return (
<p className={ className }>
{ __( '{{title}} – hello from the editor!', '{{textdomain}}' ) }
</p>
);
}
38 changes: 10 additions & 28 deletions packages/create-block/lib/templates/esnext/src/index.js.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import { registerBlockType } from '@wordpress/blocks';
*/
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import Edit from './edit';
import save from './save';

/**
* Every block starts by registering a new block type definition.
*
Expand Down Expand Up @@ -61,36 +67,12 @@ registerBlockType( '{{namespace}}/{{slug}}', {
},

/**
* The edit function describes the structure of your block in the context of the editor.
* This represents what the editor will render when the block is used.
*
* @see https://developer.wordpress.org/block-editor/developers/block-api/block-edit-save/#edit
*
* @param {Object} [props] Properties passed from the editor.
*
* @return {WPElement} Element to render.
* @see ./edit.js
*/
edit( { className } ) {
return (
<p className={ className }>
{ __( '{{title}} – hello from the editor!', '{{textdomain}}' ) }
</p>
);
},
edit: Edit,

/**
* The save function defines the way in which the different attributes should be combined
* into the final markup, which is then serialized by the block editor into `post_content`.
*
* @see https://developer.wordpress.org/block-editor/developers/block-api/block-edit-save/#save
*
* @return {WPElement} Element to render.
* @see ./save.js
*/
save() {
return (
<p>
{ __( '{{title}} – hello from the saved content!', '{{textdomain}}' ) }
</p>
);
},
save,
} );
26 changes: 26 additions & 0 deletions packages/create-block/lib/templates/esnext/src/save.js.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Retrieves the translation of text.
*
* @see https://developer.wordpress.org/block-editor/packages/packages-i18n/
*/
import { __ } from '@wordpress/i18n';

/**
* The save function defines the way in which the different attributes should
* be combined into the final markup, which is then serialized by the block
* editor into `post_content`.
*
* @see https://developer.wordpress.org/block-editor/developers/block-api/block-edit-save/#save
*
* @return {WPElement} Element to render.
*/
export default function save() {
return (
<p>
{ __(
'{{title}} – hello from the saved content!',
'{{textdomain}}'
) }
</p>
);
}

0 comments on commit 605f47d

Please sign in to comment.