Skip to content

Commit

Permalink
Parser: Treat attributes with "undefined" source as "comment" attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Nov 10, 2017
1 parent 5f10764 commit 456f054
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 20 deletions.
3 changes: 2 additions & 1 deletion blocks/api/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ export function matcherFromSource( sourceConfig ) {
export function getBlockAttribute( attributeKey, attributeSchema, innerHTML, commentAttributes ) {
let value;
switch ( attributeSchema.source ) {
case 'comment':
// undefined source means that it's an attribute serialized to the block's "comment"
case undefined:
value = commentAttributes ? commentAttributes[ attributeKey ] : undefined;
break;
case 'attribute':
Expand Down
5 changes: 1 addition & 4 deletions blocks/api/raw-handling/shortcode-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ export default function( HTML ) {
getBlockAttributes(
{
...blockType,
attributes: mapValues( transform.attributes, attribute => ( {
source: 'comment',
...attribute,
} ) ),
attributes: transform.attributes,
},
match.shortcode.content,
attributes,
Expand Down
9 changes: 3 additions & 6 deletions blocks/api/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* External dependencies
*/
import { get, isFunction, some, mapValues } from 'lodash';
import { get, isFunction, some } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -116,15 +116,12 @@ export function registerBlockType( name, settings ) {

const attributes = settings.attributes ?
settings.attributes :
get( window._wpBlocksAttributes, name );
get( window._wpBlocksAttributes, name, {} );

const block = blocks[ name ] = {
...settings,
name,
attributes: mapValues( attributes, ( attribute ) => ( {
source: 'comment',
...attribute,
} ) ),
attributes,
};

return block;
Expand Down
2 changes: 1 addition & 1 deletion blocks/api/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export function getCommentAttributes( allAttributes, blockType ) {
}

// Ignore values sources from content and post meta
if ( attributeSchema.source !== 'comment' ) {
if ( attributeSchema.source !== undefined ) {
return result;
}

Expand Down
3 changes: 0 additions & 3 deletions blocks/api/test/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ describe( 'block parser', () => {
'number',
{
type: 'number',
source: 'comment',
},
'',
{ number: 10 }
Expand Down Expand Up @@ -138,12 +137,10 @@ describe( 'block parser', () => {
},
align: {
type: 'string',
source: 'comment',
},
topic: {
type: 'string',
default: 'none',
source: 'comment',
},
},
};
Expand Down
1 change: 0 additions & 1 deletion blocks/api/test/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ describe( 'blocks', () => {
title: 'block title',
icon: 'block-default',
attributes: { ok: {
source: 'comment',
type: 'boolean',
} },
} );
Expand Down
4 changes: 0 additions & 4 deletions blocks/api/test/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,9 @@ describe( 'block serializer', () => {
},
category: {
type: 'string',
source: 'comment',
},
ripeness: {
type: 'string',
source: 'comment',
},
} } );

Expand All @@ -195,11 +193,9 @@ describe( 'block serializer', () => {
}, { attributes: {
fruit: {
type: 'string',
source: 'comment',
},
ripeness: {
type: 'string',
source: 'comment',
},
} } );

Expand Down

0 comments on commit 456f054

Please sign in to comment.