Skip to content

Commit

Permalink
Rename method to refer to block_supports to differentiate from bloc…
Browse files Browse the repository at this point in the history
…k styles, which is an existing paradigm that pertains to "style variations".
  • Loading branch information
ramonjd committed Jul 5, 2022
1 parent fb6b952 commit d1532cc
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/block-supports/border.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function gutenberg_apply_border_support( $block_type, $block_attributes ) {

// Collect classes and styles.
$attributes = array();
$styles = gutenberg_style_engine_generate_block_styles( array( 'border' => $border_block_styles ) );
$styles = gutenberg_style_engine_get_block_supports_styles( array( 'border' => $border_block_styles ) );

if ( ! empty( $styles['classnames'] ) ) {
$attributes['class'] = $styles['classnames'];
Expand Down
2 changes: 1 addition & 1 deletion lib/block-supports/colors.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function gutenberg_apply_colors_support( $block_type, $block_attributes ) {
}

$attributes = array();
$styles = gutenberg_style_engine_generate_block_styles( array( 'color' => $color_block_styles ), array( 'convert_vars_to_classnames' => true ) );
$styles = gutenberg_style_engine_get_block_supports_styles( array( 'color' => $color_block_styles ), array( 'convert_vars_to_classnames' => true ) );

if ( ! empty( $styles['classnames'] ) ) {
$attributes['class'] = $styles['classnames'];
Expand Down
2 changes: 1 addition & 1 deletion lib/block-supports/elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function gutenberg_render_elements_support_styles( $pre_render, $block ) {
$link_block_styles = isset( $element_block_styles['link'] ) ? $element_block_styles['link'] : null;

if ( $link_block_styles ) {
$styles = gutenberg_style_engine_generate_block_styles(
$styles = gutenberg_style_engine_get_block_supports_styles(
$link_block_styles,
array(
'selector' => ".$class_name a",
Expand Down
2 changes: 1 addition & 1 deletion lib/block-supports/spacing.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function gutenberg_apply_spacing_support( $block_type, $block_attributes ) {
$spacing_block_styles = array();
$spacing_block_styles['padding'] = $has_padding_support && ! $skip_padding ? _wp_array_get( $block_styles, array( 'spacing', 'padding' ), null ) : null;
$spacing_block_styles['margin'] = $has_margin_support && ! $skip_margin ? _wp_array_get( $block_styles, array( 'spacing', 'margin' ), null ) : null;
$styles = gutenberg_style_engine_generate_block_styles( array( 'spacing' => $spacing_block_styles ) );
$styles = gutenberg_style_engine_get_block_supports_styles( array( 'spacing' => $spacing_block_styles ) );

if ( ! empty( $styles['css'] ) ) {
$attributes['style'] = $styles['css'];
Expand Down
2 changes: 1 addition & 1 deletion lib/block-supports/typography.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function gutenberg_apply_typography_support( $block_type, $block_attributes ) {
}

$attributes = array();
$styles = gutenberg_style_engine_generate_block_styles(
$styles = gutenberg_style_engine_get_block_supports_styles(
array( 'typography' => $typography_block_styles ),
array( 'convert_vars_to_classnames' => true )
);
Expand Down
22 changes: 10 additions & 12 deletions packages/style-engine/class-wp-style-engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,11 @@ protected static function get_css_declarations( $style_value, $style_definition,
}

/**
* Returns classname and CSS from a block styles object.
* Returns classnames and CSS based on the values in a block attributes.styles object.
* Return values are parsed based on the instructions in BLOCK_STYLE_DEFINITIONS_METADATA.
*
* @param array $block_styles An array of styles from a block's attributes.
* @param array $options array(
* @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.
* 'convert_vars_to_classnames' => (boolean) Whether to skip converting CSS var:? values to var( --wp--preset--* ) values. Default is `false`.
* );.
Expand All @@ -396,7 +396,7 @@ protected static function get_css_declarations( $style_value, $style_definition,
* 'classnames' => (string) Classnames separated by a space.
* );
*/
public function generate_block_styles( $block_styles, $options ) {
public function get_block_supports_styles( $block_styles, $options ) {
if ( empty( $block_styles ) || ! is_array( $block_styles ) ) {
return null;
}
Expand Down Expand Up @@ -496,30 +496,28 @@ protected static function get_individual_property_css_declarations( $style_value
}

/**
* Global public interface method to WP_Style_Engine->generate to generate block styles from a single block style object.
*
* Returns an array of CSS and classnames.
* CSS and classnames are compiled based on the instructions in BLOCK_STYLE_DEFINITIONS_METADATA.
* Global public interface method to WP_Style_Engine->get_block_supports_styles to generate block styles from a single block style object.
* See: https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/
*
* Example usage:
*
* $styles = wp_style_engine_generate_block_styles( array( 'color' => array( 'text' => '#cccccc' ) ) );
* $styles = wp_style_engine_get_block_supports_styles( array( 'color' => array( 'text' => '#cccccc' ) ) );
* // Returns `array( 'css' => 'color: #cccccc', 'classnames' => 'has-color' )`.
*
* @access public
*
* @param array $block_styles An array of styles from a block's attributes.
* @param array $block_styles The value of a block's attributes.style.
* @param array<string> $options An array of options to determine the output.
*
* @return array<string>|null array(
* 'styles' => (string) A CSS ruleset formatted to be placed in an HTML `style` attribute or tag.
* 'classnames' => (string) Classnames separated by a space.
* );
*/
function wp_style_engine_generate_block_styles( $block_styles, $options = array() ) {
function wp_style_engine_get_block_supports_styles( $block_styles, $options = array() ) {
if ( class_exists( 'WP_Style_Engine' ) ) {
$style_engine = WP_Style_Engine::get_instance();
return $style_engine->generate_block_styles( $block_styles, $options );
return $style_engine->get_block_supports_styles( $block_styles, $options );
}
return null;
}
8 changes: 4 additions & 4 deletions packages/style-engine/phpunit/class-wp-style-engine-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
/**
* Tests generating block styles and classnames based on various manifestations of the $block_styles argument.
*
* @dataProvider data_generate_block_styles_fixtures
* @dataProvider data_generate_block_supports_styles_fixtures
*
* @param array $block_styles The incoming block styles object.
* @param array $options Style engine options.
* @param string $expected_output The expected output.
*/
public function test_generate_block_styles( $block_styles, $options, $expected_output ) {
$generated_styles = wp_style_engine_generate_block_styles( $block_styles, $options );
public function test_generate_block_supports_styles( $block_styles, $options, $expected_output ) {
$generated_styles = wp_style_engine_get_block_supports_styles( $block_styles, $options );
$this->assertSame( $expected_output, $generated_styles );
}

Expand All @@ -32,7 +32,7 @@ public function test_generate_block_styles( $block_styles, $options, $expected_o
*
* @return array
*/
public function data_generate_block_styles_fixtures() {
public function data_generate_block_supports_styles_fixtures() {
return array(
'default_return_value' => array(
'block_styles' => array(),
Expand Down

0 comments on commit d1532cc

Please sign in to comment.