Skip to content

Commit

Permalink
Merge pull request #32 from WebDevStudios/feature/#24-block-save-to-r…
Browse files Browse the repository at this point in the history
…ender-php

Feature/#24 block save to render php
  • Loading branch information
coreymcollins authored Mar 23, 2018
2 parents f026269 + f452ac6 commit 4573cbd
Show file tree
Hide file tree
Showing 5 changed files with 295 additions and 5 deletions.
8 changes: 4 additions & 4 deletions dist/blocks.build.js

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions src/blocks/call-to-action/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,52 @@ export default registerBlockType(
</section>
);
},
deprecated: [
{
attributes: {
message: {
type: 'array',
source: 'children',
selector: '.content-block',
},
...BlockTitleAttributes,
...BackgroundOptionsAttributes,
...TextOptionsAttributes,
...OtherOptionsAttributes,
...ButtonLinkAttributes,
},
save( props ) {
return (
<section
className={ classnames(
props.className,
...BackgroundOptionsClasses( props ),
...OtherOptionsClasses( props ),
) }
style={ {
...BackgroundOptionsInlineStyles( props ),
...TextOptionsInlineStyles( props ),
} }
>

{ BackgroundOptionsVideoOutput( props ) }

<BlockTitleOutput
{ ...props }
/>

<div className="content-block-content content-block">
{ props.attributes.message }
</div>

<ButtonLinkOutput
{ ...props }
/>

</section>
);
}
}
]
},
);
40 changes: 40 additions & 0 deletions src/blocks/default/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,44 @@ export default registerBlockType( 'wds/default', { // Namespaced with 'wds/', lo
</section>
);
},
deprecated: [
{
attributes: {
message: {
type: 'array',
source: 'children',
selector: '.content-block',
},
...BackgroundOptionsAttributes,
...TextOptionsAttributes,
...OtherOptionsAttributes,
},
save( props ) {
return (
<section
className={ classnames(
props.className,
...BackgroundOptionsClasses( props ),
...OtherOptionsClasses( props ),
) }
style={ {
...BackgroundOptionsInlineStyles( props ),
...TextOptionsInlineStyles( props ),
} }
>

{ BackgroundOptionsVideoOutput( props ) }

<header className="content-block-header">
<h2>{ __( 'WDS Example Block with Options' ) }</h2>
</header>

<div className="content-block-content content-block">
{ props.attributes.message }
</div>
</section>
);
},
},
],
} );
57 changes: 57 additions & 0 deletions src/blocks/hero/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,62 @@ export default registerBlockType(
</section>
);
},
deprecated: [
{
attributes: {
message: {
type: 'array',
source: 'children',
selector: '.content-block',
},
alignment: {
type: 'string',
},
...BlockTitleAttributes,
...BackgroundOptionsAttributes,
...TextOptionsAttributes,
...OtherOptionsAttributes,
...ButtonLinkAttributes,
},
save( props ) {
return (
<section
className={ classnames(
props.className,
...BackgroundOptionsClasses( props ),
...OtherOptionsClasses( props ),
) }
style={ {
...BackgroundOptionsInlineStyles( props ),
...TextOptionsInlineStyles( props ),
textAlign: props.attributes.alignment,
} }
>

{ BackgroundOptionsVideoOutput( props ) }

<BlockTitleOutput
{ ...props }
/>

<div className="content-block-content content-block">
{ props.attributes.message }
</div>

{ props.attributes.buttonUrl ? (
<footer className="contenet-block-footer">
<ButtonLinkOutput
{ ...props }
/>
</footer>
) : (
null
) }

</section>
);
},
},
],
},
);
148 changes: 147 additions & 1 deletion src/blocks/two-column-block/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import OtherOptions, { OtherOptionsAttributes, OtherOptionsClasses } from '../..
*/
export default registerBlockType( 'wds/two-column', { // Namespaced with 'wds/', lowercase, hyphenated.
// Localize title using wp.i18n.__()
title: __( 'Two-Column Block' ),
title: __( 'WDS Two-Column Block' ),
// Description: Write a quick description.
description: __( 'Two equal-width columns displaying a combination of text and/or an image.' ),
// Category options: common, formatting, layout, widgets, embed.
Expand Down Expand Up @@ -493,4 +493,150 @@ export default registerBlockType( 'wds/two-column', { // Namespaced with 'wds/',
</section>
);
},
deprecated: [
{
attributes: {
contentLeft: {
type: 'array',
source: 'children',
selector: '.content-block-left',
},
contentRight: {
type: 'array',
source: 'children',
selector: '.content-block-right',
},
alignmentLeft: {
type: 'string',
},
alignmentRight: {
type: 'string',
},
imgURL: {
type: 'string',
source: 'attribute',
attribute: 'src',
selector: 'img',
},
imgID: {
type: 'number',
},
imgAlt: {
type: 'string',
source: 'attribute',
attribute: 'alt',
selector: 'img',
},
layout: {
type: 'string',
},
columnOrder: {
type: 'boolean',
default: false,
},
...BlockTitleAttributes,
...BackgroundOptionsAttributes,
...TextOptionsAttributes,
...OtherOptionsAttributes,
},
save(props) {
// Display the output of the Left content block.
function displayLeftContentOutput() {
return (
<div
key="content-block"
className="content-block-content content-block-left"
style={ { textAlign: props.attributes.alignmentLeft } }
>
{ props.attributes.contentLeft }
</div>
);
}

// Display the output of the Right content block.
function displayRightContentOutput() {
return (
<div
key="content-block"
className="content-block-content content-block-right"
style={ { textAlign: props.attributes.alignmentRight } }
>
{ props.attributes.contentRight }
</div>
);
}

// Display the output of the Image block.
function displayImageOutput() {
return (
<div
key="content-block-image"
className="content-block-content content-block"
style={ { textAlign: props.attributes.alignmentRight } }
>
<img
src={ props.attributes.imgURL }
alt={ props.attributes.imgAlt }
/>
</div>
);
}

// Check our layout type and display blocks as needed.
function displayLayoutOutput() {
if ( 'text-image' === props.attributes.layout ) {
return [
displayLeftContentOutput(),
displayImageOutput(),
];
} else if ( 'image-text' === props.attributes.layout ) {
return [
displayImageOutput(),
displayLeftContentOutput(),
];
} else if ( 'text-text' === props.attributes.layout || ! props.attributes.layout ) {
// If the toggle is clicked, display the Right column first.
if ( props.attributes.columnOrder ) {
return [
displayRightContentOutput(),
displayLeftContentOutput(),
];
}

// Otherwise, display the columns as usual.
return [
displayLeftContentOutput(),
displayRightContentOutput(),
];
}
}

return (
<section
className={ classnames(
props.className,
'content-block grid-container two-column',
...BackgroundOptionsClasses( props ),
...OtherOptionsClasses( props ),
) }
style={ {
...BackgroundOptionsInlineStyles( props ),
...TextOptionsInlineStyles( props ),
} }
>

{ BackgroundOptionsVideoOutput( props ) }

<BlockTitleOutput
{ ...props }
/>

<div className="content-block-container">
{ displayLayoutOutput() }
</div>
</section>
);
}
}
]
} );

0 comments on commit 4573cbd

Please sign in to comment.