Skip to content

Commit

Permalink
Take block selector from block.json
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Apr 7, 2020
1 parent c4fb88e commit 59277f1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
1 change: 0 additions & 1 deletion experimental-default-global-styles.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"core": {
"color": {
"primary": "#52accc",
"background": "white",
"text": "black"
}
Expand Down
31 changes: 23 additions & 8 deletions lib/global-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,29 @@ function gutenberg_experimental_global_styles_get_theme() {
function gutenberg_experimental_global_styles_resolver( $global_styles ) {
$css_rules = '';

// This is only for demo purposes, it should be pluggable
// so new selectors can be register
// (3rd party blocks, custom selectors, etc).
$selectors = array(
'core' => ':root',
'core/paragraph' => '.wp-site-blocks p',
'custom/paragraph-in-quote' => '.wp-site-blocks .wp-block-quote p',
);
$selectors = array( 'core' => ':root' );

// We need to provide a mechanism for blocks to opt-in into this
// that can be used by 3rd party blocks as well.
// This list is an interim approach to avoid the performance cost of
// having to detect support by reading all core block's block.json.
$blocks_supported = [
'paragraph',
];
// The block library dir may not exist if working from a fresh clone => bail out early.
$block_library_dir = dirname( __FILE__ ) . '/../build/block-library/blocks/';
if ( file_exists( $block_library_dir ) ) {
foreach( $blocks_supported as $block_dir ) {
$block_json_file = $block_library_dir . $block_dir . '/block.json';
if ( file_exists( $block_json_file ) ) {
$block_json = json_decode( file_get_contents( $block_json_file ), true );
if ( $block_json['selector'] ) {
$selectors[ $block_json['name'] ] = $block_json['selector'];
}
}
}
}

foreach ( $global_styles as $blockname => $subtree ) {
$token = '--';
$prefix = '--wp' . $token;
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/paragraph/block.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "core/paragraph",
"category": "common",
"selector": "p",
"attributes": {
"align": {
"type": "string"
Expand Down

0 comments on commit 59277f1

Please sign in to comment.