Skip to content

Commit

Permalink
Reverting emptytheme theme.json
Browse files Browse the repository at this point in the history
Pleasing the linter

Remove elements const
  • Loading branch information
ramonjd committed Jul 11, 2022
1 parent fdd01ec commit b2c2734
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 40 deletions.
48 changes: 29 additions & 19 deletions packages/style-engine/class-wp-style-engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,6 @@ class WP_Style_Engine {
),
);

/**
* The valid elements that can be found under styles.
*
* @var string[]
*/
const ELEMENTS = array(
'link' => 'a',
'h1' => 'h1',
);

/**
* Utility method to retrieve the main instance of the class.
*
Expand Down Expand Up @@ -433,7 +423,7 @@ protected static function get_css_declarations( $style_value, $style_definition,
*
* @param array $block_styles Styles from a block's attributes object.
* @param array $options array(
* 'selector' => (string) When a selector is passed, `generate()` will return a full CSS rule `$selector { ...rules }`, otherwise a concatenated string of properties and values.
* 'selector' => (string) When a selector is passed, the style engine will return a full CSS rule `$selector { ...rules }`, otherwise a concatenated string of properties and values.
* 'convert_vars_to_classnames' => (boolean) Whether to skip converting CSS var:? values to var( --wp--preset--* ) values. Default is `false`.
* );.
*
Expand Down Expand Up @@ -497,30 +487,35 @@ public function get_block_supports_styles( $block_styles, $options ) {
return $styles_output;
}

/**
* Returns a stylesheet of CSS rules from a theme.json/global styles object.
*
* @param array $global_styles Styles object from theme.json.
* @param array $options array(
* 'selector' => (string) When a selector is passed, the style engine will return a full CSS rule `$selector { ...rules }`, otherwise a concatenated string of properties and values.
* );.
*
* @return string A stylesheet.
*/
public function generate_global_styles( $global_styles, $options ) {
if ( empty( $global_styles ) || ! is_array( $global_styles ) ) {
return null;
}

// Treat the selector value as the root selector.
$css_selector = isset( $options['selector'] ) ? $options['selector'] : 'body';

// The return stylesheet.
$global_stylesheet = '';

// Layer 0: Root.
$root_level_options_defaults = array(
'selector' => 'body',
'custom_properties' => array(
'spacing' => array(
'blockGap' => '--wp--style--block-gap',
),
'spacing' => array( 'blockGap' => '--wp--style--block-gap' ),
),
);
$root_level_options = wp_parse_args( $options, $root_level_options_defaults );
$root_level_styles = $this->get_block_supports_styles(
$global_styles,
$root_level_options,
$root_level_options
);

if ( ! empty( $root_level_styles['css'] ) ) {
Expand Down Expand Up @@ -621,7 +616,22 @@ function wp_style_engine_get_block_supports_styles( $block_styles, $options = ar
return null;
}


/**
* Global public interface method to WP_Style_Engine->generate_global_styles to generate a stylesheet styles from a single theme.json style object.
* See: https://developer.wordpress.org/block-editor/reference-guides/theme-json-reference/theme-json-living/#styles
*
* Example usage:
*
* $styles = wp_style_engine_generate_global_styles( array( 'color' => array( 'text' => '#cccccc' ) ) );
* // Returns `body { color: #cccccc }`.
*
* @access public
*
* @param array $global_styles The value of a block's attributes.style.
* @param array<string> $options An array of options to determine the output.
*
* @return string A stylesheet.
*/
function wp_style_engine_generate_global_styles( $global_styles, $options = array() ) {
if ( class_exists( 'WP_Style_Engine' ) ) {
$style_engine = WP_Style_Engine::get_instance();
Expand Down
21 changes: 0 additions & 21 deletions test/emptytheme/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,5 @@
"wideSize": "1100px"
}
},
"styles": {
"spacing": {
"margin": {
"top": "12px"
}
},
"blocks": {
"core/columns": {
"spacing": {
"blockGap": "22px"
},
"blocks": {
"core/social-links": {
"spacing": {
"blockGap": "55px"
}
}
}
}
}
},
"patterns": [ "short-text-surrounded-by-round-images", "partner-logos" ]
}

0 comments on commit b2c2734

Please sign in to comment.