Skip to content

Commit

Permalink
Add some docblocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
pento committed Dec 16, 2019
1 parent e262431 commit b56162c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/embed-block/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
* Internal dependencies
*/
export * from './icons';
export * from './settings';
export { getEmbedBlockSettings } from './settings';
export { isFromWordPress } from './util';
7 changes: 7 additions & 0 deletions packages/embed-block/src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ const embedAttributes = {
},
};

/**
* Generate the settings object for an embed block to register with.
*
* @param {Object} settings The settings object to pass to `registerBlockType())`. The `save` and `edit`
* attributes will be overriden, if passed.
* @return {Object} The settings object configured as an embed block.
*/
export function getEmbedBlockSettings( { title, description, icon, category = 'embed', transforms, keywords = [], supports = {}, responsive = true } ) {
const blockDescription = description || __( 'Add a block that displays content pulled from other sites, like Twitter, Instagram or YouTube.' );
const edit = getEmbedEditComponent( title, icon, responsive );
Expand Down
12 changes: 12 additions & 0 deletions packages/embed-block/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ import memoize from 'memize';
import { renderToString } from '@wordpress/element';
import { createBlock } from '@wordpress/blocks';

/**
* Given a photo object, generate the HTML to show a preview of the photo.
*
* @param {Object} photo The photo data.
* @return {string} The preview HTML, rendered as a string.
*/
export const getPhotoHtml = ( photo ) => {
// 100% width for the preview so it fits nicely into the document, some "thumbnails" are
// actually the full size photo. If thumbnails not found, use full image.
Expand All @@ -24,6 +30,12 @@ export const getPhotoHtml = ( photo ) => {
return renderToString( photoPreview );
};

/**
* Determines if the HTML passed is an embed generated by WordPress.
*
* @param {string} html The HTML to check.
* @return {boolean} Whether it was generated by WordPress or not.
*/
export const isFromWordPress = ( html ) => {
return includes( html, 'class="wp-embedded-content"' );
};
Expand Down

0 comments on commit b56162c

Please sign in to comment.