Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transforms: Shortcode: Support `isMatch` predicate #18459

Merged
merged 4 commits into from Nov 19, 2019

Conversation

@mcsf
Copy link
Contributor

mcsf commented Nov 12, 2019

Description

Fixes #10674

How has this been tested?

Expanded unit tests for shortcode conversion.

Types of changes

Enhancement, API.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR. .
<p>[my-broccoli id="42"]</p>
<p>[my-broccoli id="1000"]</p>`;

const transformed = segmentHTMLToShortcodeBlock( original );

This comment has been minimized.

Copy link
@ellatrix

ellatrix Nov 12, 2019

Member

Could we add some integration tests as well?

This comment has been minimized.

Copy link
@mcsf

mcsf Nov 15, 2019

Author Contributor

@ellatrix, a few of questions:

  1. How would they differ from the current ones? It's not like any core blocks are using isMatch, nor that there are multiple core blocks interested in the same shortcode tag.
  2. Looking at blocks-raw-handling.test.js, I notice that there are now three "areas" for testing:
  • individual tests under Blocks raw handling
  • the fixture-based tests under pasteHandler
  • individual tests under rawHandler

Seems like we could revisit this? I personally don't really know where to start adding tests for this.

  1. That readFile helper silently bails if the provided file path doesn't exist, meaning that types in pasteHandler can just silently pass even when there are missing fixtures. Case in point: caption-shortcode no longer runs. Seems like something to fix too, I don't see a reason not to throw an error if a file is missing.

This comment has been minimized.

Copy link
@pento

pento Nov 18, 2019

Member

It's not like any core blocks are using isMatch, nor that there are multiple core blocks interested in the same shortcode tag.

Interestingly, this could be changed. An example off the top of my head is that the [video] shortcode in Core explicitly supports YouTube and Vimeo URLs in the src attribute. These shortcodes could be transformed into their respective core-embed block, rather than the core/video block.

This comment has been minimized.

Copy link
@ellatrix

ellatrix Nov 18, 2019

Member
  1. How would they differ from the current ones? It's not like any core blocks are using isMatch, nor that there are multiple core blocks interested in the same shortcode tag.

That's true, but we could add a test block?

Seems like we could revisit this? I personally don't really know where to start adding tests for this.

Yeah, we should clean that up :) Ideally, if applicable, tests should be run for both the raw and paste handler.

That readFile helper silently bails if the provided file path doesn't exist, meaning that types in pasteHandler can just silently pass even when there are missing fixtures. Case in point: caption-shortcode no longer runs. Seems like something to fix too, I don't see a reason not to throw an error if a file is missing.

Me neither. Sounds good to throw an error.

@ellatrix

This comment has been minimized.

Copy link
Member

ellatrix commented Nov 12, 2019

Looks great, but would really love some integration tests for an extra layer of confidence. :)

@pento

This comment has been minimized.

Copy link
Member

pento commented Nov 12, 2019

Thank you for getting onto this one, @mcsf!

For consistency, is it worth looking at having the shortcode transform use a transform function, too, so it matches all of the other types? It seems a bit weird to have a different pattern just for shortcodes. @ellatrix, I don't suppose you recall any additional conversations around #2874?

@ellatrix

This comment has been minimized.

Copy link
Member

ellatrix commented Nov 13, 2019

@pento What kind of additional conversation? I believe we use isMatch for other transforms too.

@pento

This comment has been minimized.

Copy link
Member

pento commented Nov 13, 2019

Talking about the difference between the examples in the docs, all of the transform types provide a transform property, which is a function to create the block, except for the shortcode type, which has the attributes property, instead. I wasn't sure if this had been discussed in Slack or somewhere else, I couldn't find any relevant conversation. 🙂

@ellatrix

This comment has been minimized.

Copy link
Member

ellatrix commented Nov 13, 2019

I don't think so. I'm fine with revising that. The difference is that the other transform functions are provided with block attributes, in this case they would be shortcode attributes.

@mcsf

This comment has been minimized.

Copy link
Contributor Author

mcsf commented Nov 15, 2019

Talking about the difference between the examples in the docs, all of the transform types provide a transform property, which is a function to create the block, except for the shortcode type, which has the attributes property, instead. I wasn't sure if this had been discussed in Slack or somewhere else, I couldn't find any relevant conversation.

I know I raised this way way back somewhere in a comment, deep in the GitHub mist.

type: 'shortcode',
tag: 'gallery',
isMatch( { named: { ids } } ) {
return ids.indexOf( 42 ) > -1;

This comment has been minimized.

Copy link
@ellatrix

ellatrix Nov 18, 2019

Member

Is this your answer to everything? :)

This comment has been minimized.

Copy link
@mcsf

mcsf Nov 19, 2019

Author Contributor

😄

@mcsf mcsf force-pushed the add/shortcodes-isMatch-support branch from 6c020eb to 9a1848b Nov 19, 2019
@mcsf mcsf merged commit f63b197 into master Nov 19, 2019
2 checks passed
2 checks passed
pull-request-automation
Details
Travis CI - Pull Request Build Passed
Details
@mcsf mcsf deleted the add/shortcodes-isMatch-support branch Nov 19, 2019
mkevins added a commit that referenced this pull request Nov 19, 2019
* Transforms: Shortcode: Support `isMatch` predicate

* Docs: Transforms: Extend `isMatch` support to shortcodes

* Tests: Raw Handling: Cover Shortcode's `isMatch`

* Tests: Raw Handling: Error if missing fixtures
@pento pento added this to the Gutenberg 7.0 milestone Nov 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.