Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
3d51183
Initial commit: add typography to style engine
ramonjd Apr 6, 2022
24e9f57
Adding whitespace to inline output
ramonjd Apr 7, 2022
f257752
Introduce spacing to inline styles
ramonjd Apr 7, 2022
70f32de
Removing generating styles based on an options path since we're not u…
ramonjd Apr 7, 2022
9b7b31a
Perform kebab case normalization in the style engine.
ramonjd Apr 13, 2022
75ce88b
Remove unused arg $options
ramonjd Apr 13, 2022
b9d9ba4
Refactor style engine so that `generate()` will return an array of cs…
ramonjd Apr 14, 2022
c4ae1d3
Remove 'inline' as an option until we need something different
ramonjd Apr 14, 2022
510f6bb
Only add the required classnames if there's a valid style value or cl…
ramonjd Apr 14, 2022
86b8880
Removed options arg until we need it. Thanks, linter.
ramonjd Apr 14, 2022
e7affed
Refactor generate to accept string CSS preset property values (for no…
ramonjd Apr 19, 2022
c3d314e
Updated color and typography to use the preset value for the style en…
ramonjd Apr 19, 2022
44ddde4
No short ternaries says the linter. Booooh!
ramonjd Apr 19, 2022
df6077f
Cleaning up. Reinstating deprecated function so we don't forget to de…
ramonjd Apr 20, 2022
e3f4b11
Wherefore art thou, vile linter!
ramonjd Apr 20, 2022
4f9502f
Updating inline docs
ramonjd Apr 22, 2022
65cf61c
Created public interface method gutenberg_style_engine_generate
ramonjd Apr 26, 2022
d328e64
Linter, thy foul stench offends me!
ramonjd Apr 26, 2022
951ea74
Using the correct preset property keys for colors and gradients ensur…
ramonjd Apr 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Only add the required classnames if there's a valid style value or cl…
…assname slug.
  • Loading branch information
ramonjd committed Apr 26, 2022
commit 510f6bb50b3506bf069581ccd1fd9043bec332c7
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 @@ -144,31 +144,29 @@ protected static function get_classnames( $style, $style_definition ) {
return $classnames;
}

// Remove falsy values.
$filtered_style = array_filter(
$style,
function( $value ) {
return ! empty( $value );
}
);
$required_classnames = array();

if ( ! empty( $style_definition['classnames'] ) ) {
foreach ( $style_definition['classnames'] as $classname => $property ) {
// Only add the required classname if there's a valid style value or classname slug.
if ( true === $property && ! empty( $filtered_style ) ) {
$classnames[] = $classname;
if ( true === $property ) {
$required_classnames[] = $classname;
}

if ( isset( $filtered_style[ $property ] ) ) {
if ( isset( $style[ $property ] ) ) {
// Right now we expect a classname pattern to be stored in BLOCK_STYLE_DEFINITIONS_METADATA.
// One day, if there are no stored schemata, we could allow custom patterns or
// generate classnames based on other properties
// such as a path or a value or a prefix passed in options.
$classnames[] = sprintf( $classname, _wp_to_kebab_case( $filtered_style[ $property ] ) );
$classnames[] = sprintf( $classname, _wp_to_kebab_case( $style[ $property ] ) );
}
}
}

// Only add the required classnames if there's a valid style value or classname slug.
if ( ! empty( $required_classnames ) && ( $style['value'] || ! empty( $classnames ) ) ) {
$classnames = array_merge( $required_classnames, $classnames );
}

return $classnames;
}

Expand Down
14 changes: 14 additions & 0 deletions packages/style-engine/phpunit/class-wp-style-engine-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,20 @@ public function data_generate_styles_fixtures() {
'classnames' => 'has-text-color',
),
),
'invalid_classnames_slug_key' => array(
'block_styles' => array(
'color' => array(
'text' => array(
'cheese' => 'pizza',
),
'background' => array(
'tomato' => 'sauce',
),
),
),
'options' => array(),
'expected_output' => array(),
),
'invalid_classnames_options' => array(
'block_styles' => array(
'typography' => array(
Expand Down