Skip to content

Commit

Permalink
Blocks: Refactor all blocks to be exported as name & settings pair
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Jan 19, 2018
1 parent e6d573d commit c108c9b
Show file tree
Hide file tree
Showing 41 changed files with 200 additions and 240 deletions.
7 changes: 4 additions & 3 deletions blocks/library/block/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { __ } from '@wordpress/i18n';
* Internal dependencies
*/
import BlockEdit from '../../block-edit';
import { registerBlockType } from '../../api';
import ReusableBlockEditPanel from './edit-panel';

class ReusableBlockEdit extends Component {
Expand Down Expand Up @@ -156,7 +155,9 @@ const ConnectedReusableBlockEdit = connect(
} )
)( ReusableBlockEdit );

export const registerReusableBlock = () => registerBlockType( 'core/block', {
export const name = 'core/block';

export const settings = {
title: __( 'Reusable Block' ),
category: 'reusable-blocks',
isPrivate: true,
Expand All @@ -174,4 +175,4 @@ export const registerReusableBlock = () => registerBlockType( 'core/block', {

edit: ConnectedReusableBlockEdit,
save: () => null,
} );
};
7 changes: 4 additions & 3 deletions blocks/library/button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { Dashicon, IconButton, PanelColor, withFallbackStyles } from '@wordpress
*/
import './editor.scss';
import './style.scss';
import { registerBlockType } from '../../api';
import Editable from '../../editable';
import UrlInput from '../../url-input';
import BlockControls from '../../block-controls';
Expand Down Expand Up @@ -173,7 +172,9 @@ const blockAttributes = {
},
};

export const registerButtonBlock = () => registerBlockType( 'core/button', {
export const name = 'core/button';

export const settings = {
title: __( 'Button' ),

description: __( 'A nice little button. Call something out with it.' ),
Expand Down Expand Up @@ -235,4 +236,4 @@ export const registerButtonBlock = () => registerBlockType( 'core/button', {
);
},
} ],
} );
};
8 changes: 2 additions & 6 deletions blocks/library/button/test/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
/**
* Internal dependencies
*/
import { registerButtonBlock } from '../';
import { name, settings } from '../';
import { blockEditRender } from 'blocks/test/helpers';

describe( 'core/button', () => {
beforeAll( () => {
registerButtonBlock();
} );

test( 'block edit matches snapshot', () => {
const wrapper = blockEditRender( 'core/button' );
const wrapper = blockEditRender( name, settings );

expect( wrapper ).toMatchSnapshot();
} );
Expand Down
7 changes: 4 additions & 3 deletions blocks/library/categories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import { __ } from '@wordpress/i18n';
*/
import './editor.scss';
import './style.scss';
import { registerBlockType } from '../../api';
import CategoriesBlock from './block';

export const registerCategoriesBlock = () => registerBlockType( 'core/categories', {
export const name = 'core/categories';

export const settings = {
title: __( 'Categories' ),

description: __( 'Shows a list of your site\'s categories.' ),
Expand Down Expand Up @@ -54,4 +55,4 @@ export const registerCategoriesBlock = () => registerBlockType( 'core/categories
save() {
return null;
},
} );
};
8 changes: 5 additions & 3 deletions blocks/library/code/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import { __ } from '@wordpress/i18n';
* Internal dependencies
*/
import './editor.scss';
import { registerBlockType, createBlock } from '../../api';
import { createBlock } from '../../api';

export const registerCodeBlock = () => registerBlockType( 'core/code', {
export const name = 'core/code';

export const settings = {
title: __( 'Code' ),

description: __( 'The code block maintains spaces and tabs, great for showing code snippets.' ),
Expand Down Expand Up @@ -71,4 +73,4 @@ export const registerCodeBlock = () => registerBlockType( 'core/code', {
save( { attributes } ) {
return <pre><code>{ attributes.content }</code></pre>;
},
} );
};
8 changes: 2 additions & 6 deletions blocks/library/code/test/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
/**
* Internal dependencies
*/
import { registerCodeBlock } from '../';
import { name, settings } from '../';
import { blockEditRender } from 'blocks/test/helpers';

describe( 'core/code', () => {
beforeAll( () => {
registerCodeBlock();
} );

test( 'block edit matches snapshot', () => {
const wrapper = blockEditRender( 'core/code' );
const wrapper = blockEditRender( name, settings );

expect( wrapper ).toMatchSnapshot();
} );
Expand Down
8 changes: 5 additions & 3 deletions blocks/library/cover-image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import classnames from 'classnames';
*/
import './editor.scss';
import './style.scss';
import { registerBlockType, createBlock } from '../../api';
import { createBlock } from '../../api';
import Editable from '../../editable';
import MediaUpload from '../../media-upload';
import ImagePlaceHolder from '../../image-placeholder';
Expand All @@ -27,7 +27,9 @@ import RangeControl from '../../inspector-controls/range-control';

const validAlignments = [ 'left', 'center', 'right', 'wide', 'full' ];

export const registerCoverImageBlock = () => registerBlockType( 'core/cover-image', {
export const name = 'core/cover-image';

export const settings = {
title: __( 'Cover Image' ),

description: __( 'Cover Image is a bold image block with an optional title.' ),
Expand Down Expand Up @@ -215,7 +217,7 @@ export const registerCoverImageBlock = () => registerBlockType( 'core/cover-imag
</section>
);
},
} );
};

function dimRatioToClass( ratio ) {
return ( ratio === 0 || ratio === 50 ) ?
Expand Down
8 changes: 2 additions & 6 deletions blocks/library/cover-image/test/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
/**
* Internal dependencies
*/
import { registerCoverImageBlock } from '../';
import { name, settings } from '../';
import { blockEditRender } from 'blocks/test/helpers';

jest.mock( 'blocks/media-upload', () => () => '*** Mock(Media upload button) ***' );

describe( 'core/cover-image', () => {
beforeAll( () => {
registerCoverImageBlock();
} );

test( 'block edit matches snapshot', () => {
const wrapper = blockEditRender( 'core/cover-image' );
const wrapper = blockEditRender( name, settings );

expect( wrapper ).toMatchSnapshot();
} );
Expand Down
37 changes: 17 additions & 20 deletions blocks/library/freeform/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,30 @@ import { __ } from '@wordpress/i18n';
* Internal dependencies
*/
import './editor.scss';
import { registerBlockType, setUnknownTypeHandlerName } from '../../api';
import OldEditor from './old-editor';

export const registerFreeformBlock = () => {
registerBlockType( 'core/freeform', {
title: __( 'Classic' ),
export const name = 'core/freeform';

desription: __( 'The classic editor, in block form.' ),
export const settings = {
title: __( 'Classic' ),

icon: 'editor-kitchensink',
desription: __( 'The classic editor, in block form.' ),

category: 'formatting',
icon: 'editor-kitchensink',

attributes: {
content: {
type: 'string',
source: 'html',
},
},

edit: OldEditor,
category: 'formatting',

save( { attributes } ) {
const { content } = attributes;
return content;
attributes: {
content: {
type: 'string',
source: 'html',
},
} );
},

edit: OldEditor,

setUnknownTypeHandlerName( 'core/freeform' );
save( { attributes } ) {
const { content } = attributes;
return content;
},
};
8 changes: 2 additions & 6 deletions blocks/library/freeform/test/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
/**
* Internal dependencies
*/
import { registerFreeformBlock } from '../';
import { name, settings } from '../';
import { blockEditRender } from 'blocks/test/helpers';

describe( 'core/freeform', () => {
beforeAll( () => {
registerFreeformBlock();
} );

test( 'block edit matches snapshot', () => {
const wrapper = blockEditRender( 'core/freeform' );
const wrapper = blockEditRender( name, settings );

expect( wrapper ).toMatchSnapshot();
} );
Expand Down
9 changes: 5 additions & 4 deletions blocks/library/gallery/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { createMediaFromFile, preloadImage } from '@wordpress/utils';
*/
import './editor.scss';
import './style.scss';
import { registerBlockType, createBlock } from '../../api';
import { createBlock } from '../../api';
import { default as GalleryBlock, defaultColumnsNumber } from './block';

const blockAttributes = {
Expand Down Expand Up @@ -56,7 +56,9 @@ const blockAttributes = {
},
};

export const registerGalleryBlock = () => registerBlockType( 'core/gallery', {
export const name = 'core/gallery';

export const settings = {
title: __( 'Gallery' ),
description: __( 'Image galleries are a great way to share groups of pictures on your site.' ),
icon: 'format-gallery',
Expand Down Expand Up @@ -228,5 +230,4 @@ export const registerGalleryBlock = () => registerBlockType( 'core/gallery', {
},
},
],

} );
};
8 changes: 2 additions & 6 deletions blocks/library/gallery/test/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
/**
* Internal dependencies
*/
import { registerGalleryBlock } from '../';
import { name, settings } from '../';
import { blockEditRender } from 'blocks/test/helpers';

jest.mock( 'blocks/media-upload', () => () => '*** Mock(Media upload button) ***' );

describe( 'core/gallery', () => {
beforeAll( () => {
registerGalleryBlock();
} );

test( 'block edit matches snapshot', () => {
const wrapper = blockEditRender( 'core/gallery' );
const wrapper = blockEditRender( name, settings );

expect( wrapper ).toMatchSnapshot();
} );
Expand Down
8 changes: 5 additions & 3 deletions blocks/library/heading/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import { Toolbar } from '@wordpress/components';
* Internal dependencies
*/
import './editor.scss';
import { registerBlockType, createBlock } from '../../api';
import { createBlock } from '../../api';
import Editable from '../../editable';
import BlockControls from '../../block-controls';
import InspectorControls from '../../inspector-controls';
import AlignmentToolbar from '../../alignment-toolbar';

export const registerHeadingBlock = () => registerBlockType( 'core/heading', {
export const name = 'core/heading';

export const settings = {
title: __( 'Heading' ),

description: __( 'Search engines use the headings to index the structure and content of your web pages.' ),
Expand Down Expand Up @@ -178,4 +180,4 @@ export const registerHeadingBlock = () => registerBlockType( 'core/heading', {
</Tag>
);
},
} );
};
8 changes: 2 additions & 6 deletions blocks/library/heading/test/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
/**
* Internal dependencies
*/
import { registerHeadingBlock } from '../';
import { name, settings } from '../';
import { blockEditRender } from 'blocks/test/helpers';

describe( 'core/heading', () => {
beforeAll( () => {
registerHeadingBlock();
} );

test( 'block edit matches snapshot', () => {
const wrapper = blockEditRender( 'core/heading' );
const wrapper = blockEditRender( name, settings );

expect( wrapper ).toMatchSnapshot();
} );
Expand Down
7 changes: 4 additions & 3 deletions blocks/library/html/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import { withState } from '@wordpress/components';
* Internal dependencies
*/
import './editor.scss';
import { registerBlockType } from '../../api';
import BlockControls from '../../block-controls';

export const registerHtmlBlock = () => registerBlockType( 'core/html', {
export const name = 'core/html';

export const settings = {
title: __( 'Custom HTML' ),

description: __( 'Add custom HTML code and preview it right here in the editor.' ),
Expand Down Expand Up @@ -75,4 +76,4 @@ export const registerHtmlBlock = () => registerBlockType( 'core/html', {
save( { attributes } ) {
return attributes.content;
},
} );
};
8 changes: 2 additions & 6 deletions blocks/library/html/test/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
/**
* Internal dependencies
*/
import { registerHtmlBlock } from '../';
import { name, settings } from '../';
import { blockEditRender } from 'blocks/test/helpers';

describe( 'core/html', () => {
beforeAll( () => {
registerHtmlBlock();
} );

test( 'block edit matches snapshot', () => {
const wrapper = blockEditRender( 'core/html' );
const wrapper = blockEditRender( name, settings );

expect( wrapper ).toMatchSnapshot();
} );
Expand Down
8 changes: 5 additions & 3 deletions blocks/library/image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import { createMediaFromFile, preloadImage } from '@wordpress/utils';
*/
import './style.scss';
import './editor.scss';
import { registerBlockType, createBlock, getBlockAttributes, getBlockType } from '../../api';
import { createBlock, getBlockAttributes, getBlockType } from '../../api';
import ImageBlock from './block';

export const registerImageBlock = () => registerBlockType( 'core/image', {
export const name = 'core/image';

export const settings = {
title: __( 'Image' ),

description: __( 'Worth a thousand words.' ),
Expand Down Expand Up @@ -179,4 +181,4 @@ export const registerImageBlock = () => registerBlockType( 'core/image', {
</figure>
);
},
} );
};
Loading

0 comments on commit c108c9b

Please sign in to comment.