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

Add parsing and validation for block.json files #2

Merged
merged 8 commits into from
Jun 17, 2020

Conversation

coreymckrill
Copy link
Collaborator

@coreymckrill coreymckrill commented Jun 12, 2020

Similar to the readme parser, this adds a Parser class and a Validator class for block.json files. The parser attempts to capture helpful error messages if they arise while decoding JSON to a PHP object. The validator collects two levels of error messages during validation, error and warning, which are returned in a single WP_Error object so they can be handled according to the context.

This also incorporates the parser and validator into the find_blocks_in_file method in the Importer class.

@coreymckrill coreymckrill marked this pull request as ready for review June 12, 2020 22:50
@coreymckrill coreymckrill requested a review from tellyworth June 12, 2020 22:50
'type' => 'string',
),
),
'required' => array( 'name', 'title', 'category' ),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The category will become optional as of WordPress 5.5.

"message": "This is a notice!"
}
},
"editorScript": "build/editor.js",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up with a more nuanced way of defining assets, for example:
https://github.com/WordPress/gutenberg/blob/master/docs/rfc/block-registration.md#editor-script

{ "script": "file:./build/script.js" }

Full description here:
https://github.com/WordPress/gutenberg/blob/master/docs/rfc/block-registration.md#wpdefinedasset

Long story short, developers can provide a relative path as before or a script/style handle. For the Block Directory, you could say that file is the only option.

"script": "build/main.js",
"editorStyle": "build/editor.css",
"style": "build/style.css"
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are going to be added two more fields:

  • context (name might change because context is reserved in REST API)
  • providesContext

Tracking ticket: https://core.trac.wordpress.org/ticket/49927
Documentation update: WordPress/gutenberg#22686

@tellyworth tellyworth merged commit cb2dd35 into experiment/block-checker Jun 17, 2020
@gziolo
Copy link

gziolo commented Jul 8, 2020

I opened a ticket in WordPress trac to start the discussion on how we could maintain a shared JSON schema in one place: https://core.trac.wordpress.org/ticket/50615.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants