-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #355 from WordPress/fix/test-glob
Find tests in nested directories
- Loading branch information
Showing
7 changed files
with
116 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* eslint-disable no-console */ | ||
|
||
/** | ||
* Block settings keyed by block slug. | ||
* | ||
* @var {Object} blocks | ||
*/ | ||
const blocks = {}; | ||
|
||
/** | ||
* Registers a new block provided a unique slug and an object defining its | ||
* behavior. Once registered, the block is made available as an option to any | ||
* editor interface where blocks are implemented. | ||
* | ||
* @param {string} slug Block slug | ||
* @param {Object} settings Block settings | ||
* @return {?WPBlock} The block, if it has been successfully | ||
* registered; otherwise `undefined`. | ||
*/ | ||
export function registerBlock( slug, settings ) { | ||
if ( typeof slug !== 'string' ) { | ||
console.error( | ||
'Block slugs must be strings.' | ||
); | ||
return; | ||
} | ||
if ( ! /^[a-z0-9-]+\/[a-z0-9-]+$/.test( slug ) ) { | ||
console.error( | ||
'Block slugs must contain a namespace prefix. Example: my-plugin/my-custom-block' | ||
); | ||
return; | ||
} | ||
if ( blocks[ slug ] ) { | ||
console.error( | ||
'Block "' + slug + '" is already registered.' | ||
); | ||
return; | ||
} | ||
const block = Object.assign( { slug }, settings ); | ||
blocks[ slug ] = block; | ||
return block; | ||
} | ||
|
||
/** | ||
* Unregisters a block. | ||
* | ||
* @param {string} slug Block slug | ||
* @return {?WPBlock} The previous block value, if it has been | ||
* successfully unregistered; otherwise `undefined`. | ||
*/ | ||
export function unregisterBlock( slug ) { | ||
if ( ! blocks[ slug ] ) { | ||
console.error( | ||
'Block "' + slug + '" is not registered.' | ||
); | ||
return; | ||
} | ||
const oldBlock = blocks[ slug ]; | ||
delete blocks[ slug ]; | ||
return oldBlock; | ||
} | ||
|
||
/** | ||
* Returns settings associated with a registered block. | ||
* | ||
* @param {string} slug Block slug | ||
* @return {?Object} Block settings | ||
*/ | ||
export function getBlockSettings( slug ) { | ||
return blocks[ slug ]; | ||
} | ||
|
||
/** | ||
* Returns all registered blocks. | ||
* | ||
* @return {Array} Block settings | ||
*/ | ||
export function getBlocks() { | ||
return Object.values( blocks ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters