Skip to content

Commit

Permalink
Framework: Create custom React serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Dec 15, 2017
1 parent bbf06e2 commit ff695ba
Show file tree
Hide file tree
Showing 15 changed files with 396 additions and 25 deletions.
2 changes: 1 addition & 1 deletion blocks/library/audio/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ registerBlockType( 'core/audio', {
const { align, src, caption } = attributes;
return (
<figure className={ align ? `align${ align }` : null }>
<audio controls="controls" src={ src } />
<audio controls src={ src } />
{ caption && caption.length > 0 && <figcaption>{ caption }</figcaption> }
</figure>
);
Expand Down
3 changes: 2 additions & 1 deletion blocks/library/code/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* External dependencies
*/
import TextareaAutosize from 'react-autosize-textarea';
import { escape as escapeString } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -75,6 +76,6 @@ registerBlockType( 'core/code', {
},

save( { attributes } ) {
return <pre><code>{ attributes.content }</code></pre>;
return <pre><code>{ escapeString( attributes.content ) }</code></pre>;
},
} );
2 changes: 1 addition & 1 deletion blocks/test/fixtures/core__audio.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- wp:core/audio {"align":"right"} -->
<figure class="wp-block-audio alignright">
<audio controls="" src="https://media.simplecast.com/episodes/audio/80564/draft-podcast-51-livePublish2.mp3"></audio>
<audio controls="true" src="https://media.simplecast.com/episodes/audio/80564/draft-podcast-51-livePublish2.mp3"></audio>
</figure>
<!-- /wp:core/audio -->
2 changes: 1 addition & 1 deletion blocks/test/fixtures/core__audio.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"align": "right",
"caption": []
},
"originalContent": "<figure class=\"wp-block-audio alignright\">\n <audio controls=\"\" src=\"https://media.simplecast.com/episodes/audio/80564/draft-podcast-51-livePublish2.mp3\"></audio>\n</figure>"
"originalContent": "<figure class=\"wp-block-audio alignright\">\n <audio controls=\"true\" src=\"https://media.simplecast.com/episodes/audio/80564/draft-podcast-51-livePublish2.mp3\"></audio>\n</figure>"
}
]
2 changes: 1 addition & 1 deletion blocks/test/fixtures/core__audio.parsed.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"align": "right"
},
"innerBlocks": [],
"innerHTML": "\n<figure class=\"wp-block-audio alignright\">\n <audio controls=\"\" src=\"https://media.simplecast.com/episodes/audio/80564/draft-podcast-51-livePublish2.mp3\"></audio>\n</figure>\n"
"innerHTML": "\n<figure class=\"wp-block-audio alignright\">\n <audio controls=\"true\" src=\"https://media.simplecast.com/episodes/audio/80564/draft-podcast-51-livePublish2.mp3\"></audio>\n</figure>\n"
},
{
"attrs": {},
Expand Down
2 changes: 1 addition & 1 deletion blocks/test/fixtures/core__audio.serialized.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<!-- wp:audio {"align":"right"} -->
<figure class="wp-block-audio alignright"><audio controls="" src="https://media.simplecast.com/episodes/audio/80564/draft-podcast-51-livePublish2.mp3"></audio></figure>
<figure class="wp-block-audio alignright"><audio controls="true" src="https://media.simplecast.com/episodes/audio/80564/draft-podcast-51-livePublish2.mp3"></audio></figure>
<!-- /wp:audio -->
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- wp:image {"align":"center"} -->
<figure class="wp-block-image aligncenter"><img src="https://cldup.com/YLYhpou2oq.jpg" />
<figcaption>Give it a try. Press the &quot;really wide&quot; button on the image toolbar.</figcaption>
<figcaption>Give it a try. Press the "really wide" button on the image toolbar.</figcaption>
</figure>
<!-- /wp:image -->
4 changes: 2 additions & 2 deletions blocks/test/fixtures/core__list__ul.serialized.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- wp:list -->
<ul>
<li>Text &amp; Headings</li>
<li>Images &amp; Videos</li>
<li>Text & Headings</li>
<li>Images & Videos</li>
<li>Galleries</li>
<li>Embeds, like YouTube, Tweets, or other WordPress posts.</li>
<li>Layout blocks, like Buttons, Hero Images, Separators, etc.</li>
Expand Down
2 changes: 1 addition & 1 deletion blocks/test/fixtures/core__video.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<!-- wp:core/video -->
<figure class="wp-block-video"><video src="https://awesome-fake.video/file.mp4" controls=""></video></figure>
<figure class="wp-block-video"><video src="https://awesome-fake.video/file.mp4" controls="true"></video></figure>
<!-- /wp:core/video -->
2 changes: 1 addition & 1 deletion blocks/test/fixtures/core__video.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"src": "https://awesome-fake.video/file.mp4",
"caption": []
},
"originalContent": "<figure class=\"wp-block-video\"><video src=\"https://awesome-fake.video/file.mp4\" controls=\"\"></video></figure>"
"originalContent": "<figure class=\"wp-block-video\"><video src=\"https://awesome-fake.video/file.mp4\" controls=\"true\"></video></figure>"
}
]
2 changes: 1 addition & 1 deletion blocks/test/fixtures/core__video.parsed.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"blockName": "core/video",
"attrs": null,
"innerBlocks": [],
"innerHTML": "\n<figure class=\"wp-block-video\"><video src=\"https://awesome-fake.video/file.mp4\" controls=\"\"></video></figure>\n"
"innerHTML": "\n<figure class=\"wp-block-video\"><video src=\"https://awesome-fake.video/file.mp4\" controls=\"true\"></video></figure>\n"
},
{
"attrs": {},
Expand Down
2 changes: 1 addition & 1 deletion blocks/test/fixtures/core__video.serialized.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<!-- wp:video -->
<figure class="wp-block-video"><video controls="" src="https://awesome-fake.video/file.mp4"></video></figure>
<figure class="wp-block-video"><video controls="true" src="https://awesome-fake.video/file.mp4"></video></figure>
<!-- /wp:video -->
8 changes: 6 additions & 2 deletions element/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
*/
import { createElement, Component, cloneElement, Children } from 'react';
import { render, findDOMNode, createPortal, unmountComponentAtNode } from 'react-dom';
import { renderToStaticMarkup } from 'react-dom/server';
import { camelCase, flowRight, isString, upperFirst } from 'lodash';

/**
* Internal dependencies
*/
import serialize from './serialize';

/**
* Returns a new element of given type. Type can be either a string tag name or
* another function which itself returns an element.
Expand Down Expand Up @@ -74,7 +78,7 @@ export { createPortal };
* @param {WPElement} element Element to render
* @return {String} HTML
*/
export { renderToStaticMarkup as renderToString };
export { serialize as renderToString };

/**
* Concatenate two or more React children objects
Expand Down
Loading

0 comments on commit ff695ba

Please sign in to comment.