Skip to content

Commit

Permalink
Udpate names of types
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Oct 22, 2021
1 parent e39441a commit c73e850
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
14 changes: 7 additions & 7 deletions lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -1262,29 +1262,29 @@ private static function get_setting_nodes( $theme_json, $selectors = array() ) {
* the theme.json structure this object represents.
*
* @param array $types Types of styles to load. Will load all by default. It accepts:
* 'css_variables': only CSS variables (presets & custom).
* 'block_classes': only block classes.
* 'preset_classes': only classes for presets.
* 'variables': only the CSS Custom Properties for presets & custom ones.
* 'styles': only the styles section in theme.json.
* 'presets': only the classes for the presets.
* @param array $origins A list of origins to include. By default it includes 'core', 'theme', and 'user'.
*
* @return string Stylesheet.
*/
public function get_stylesheet( $types = array( 'css_variables', 'block_classes', 'preset_classes' ), $origins = self::VALID_ORIGINS ) {
public function get_stylesheet( $types = array( 'variables', 'styles', 'presets' ), $origins = self::VALID_ORIGINS ) {
$blocks_metadata = self::get_blocks_metadata();
$style_nodes = self::get_style_nodes( $this->theme_json, $blocks_metadata );
$setting_nodes = self::get_setting_nodes( $this->theme_json, $blocks_metadata );

$stylesheet = '';

if ( in_array( 'css_variables', $types, true ) ) {
if ( in_array( 'variables', $types, true ) ) {
$stylesheet .= $this->get_css_variables( $setting_nodes, $origins );
}

if ( in_array( 'block_classes', $types, true ) ) {
if ( in_array( 'styles', $types, true ) ) {
$stylesheet .= $this->get_block_classes( $style_nodes );
}

if ( in_array( 'preset_classes', $types, true ) ) {
if ( in_array( 'presets', $types, true ) ) {
$stylesheet .= $this->get_preset_classes( $setting_nodes, $origins );
}

Expand Down
8 changes: 4 additions & 4 deletions lib/compat/wordpress-5.9/get-global-styles-and-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ function gutenberg_get_global_styles( $path = array(), $block_name = '', $origin
* Returns the stylesheet resulting of merging core, theme, and user data.
*
* @param array $types Types of styles to load. Optional.
* It accepts 'css_variables', 'block_classes', 'preset_classes' as values.
* It accepts 'variables', 'styles', 'presets' as values.
* If empty, it'll load all for themes with theme.json support
* and only [ 'css_variables', 'preset_classes' ] for themes without theme.json support.
* and only [ 'variables', 'presets' ] for themes without theme.json support.
*
* @return string Stylesheet.
*/
Expand All @@ -96,9 +96,9 @@ function gutenberg_get_global_stylesheet( $types = array() ) {
$supports_theme_json = WP_Theme_JSON_Resolver_Gutenberg::theme_has_support();
$supports_link_color = get_theme_support( 'experimental-link-color' );
if ( empty( $types ) && ! $supports_theme_json ) {
$types = array( 'css_variables', 'preset_classes' );
$types = array( 'variables', 'presets' );
} elseif ( empty( $types ) ) {
$types = array( 'css_variables', 'block_classes', 'preset_classes' );
$types = array( 'variables', 'styles', 'presets' );
}

$origins = array( 'core', 'theme', 'user' );
Expand Down
10 changes: 5 additions & 5 deletions lib/global-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
* the corresponding stylesheet.
*
* @param WP_Theme_JSON_Gutenberg $tree Input tree.
* @param array $types Which styles to load. It accepts 'css_variables', 'block_classes', 'preset_classes'. By default, it'll load all.
* @param array $types Which styles to load. It accepts 'variables', 'styles', 'presets'. By default, it'll load all.
*
* @return string Stylesheet.
*/
function gutenberg_experimental_global_styles_get_stylesheet( $tree, $types = array( 'css_variables', 'block_classes', 'preset_classes' ) ) {
function gutenberg_experimental_global_styles_get_stylesheet( $tree, $types = array( 'variables', 'styles', 'presets' ) ) {
$origins = array( 'core', 'theme', 'user' );
$supports_theme_json = WP_Theme_JSON_Resolver_Gutenberg::theme_has_support();
$supports_link_color = get_theme_support( 'experimental-link-color' );
Expand Down Expand Up @@ -111,12 +111,12 @@ function_exists( 'gutenberg_is_edit_site_page' ) &&
$new_global_styles = array();
$new_presets = array(
array(
'css' => 'css_variables',
'css' => 'variables',
'__unstableType' => 'presets',
'__experimentalNoWrapper' => true,
),
array(
'css' => 'preset_classes',
'css' => 'presets',
'__unstableType' => 'presets',
),
);
Expand All @@ -129,7 +129,7 @@ function_exists( 'gutenberg_is_edit_site_page' ) &&
}

$new_block_classes = array(
'css' => 'block_classes',
'css' => 'styles',
'__unstableType' => 'theme',
);
if ( WP_Theme_JSON_Resolver_Gutenberg::theme_has_support() ) {
Expand Down
4 changes: 2 additions & 2 deletions phpunit/class-wp-theme-json-schema-v0-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -476,11 +476,11 @@ function test_get_stylesheet() {
);
$this->assertEquals(
'body{color: var(--wp--preset--color--grey);}body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }a{color: #111;}h1{font-size: 1em;}h2{font-size: 2em;}.wp-block-group{padding-top: 12px;padding-bottom: 24px;}.wp-block-group a{color: #333;}h1 a,h2 a,h3 a,h4 a,h5 a,h6 a{color: #222;}.wp-block-post-title{font-size: 5em;}.wp-block-post-title a{color: #555;}.wp-block-query-title{font-size: 5em;}.wp-block-query-title a{color: #555;}.has-grey-color{color: var(--wp--preset--color--grey) !important;}.has-grey-background-color{background-color: var(--wp--preset--color--grey) !important;}.has-grey-border-color{border-color: var(--wp--preset--color--grey) !important;}.has-small-font-family{font-family: var(--wp--preset--font-family--small) !important;}.has-big-font-family{font-family: var(--wp--preset--font-family--big) !important;}',
$theme_json->get_stylesheet( array( 'block_classes', 'preset_classes' ) )
$theme_json->get_stylesheet( array( 'styles', 'presets' ) )
);
$this->assertEquals(
'body{--wp--preset--color--grey: grey;--wp--preset--font-family--small: 14px;--wp--preset--font-family--big: 41px;}.wp-block-group{--wp--custom--base-font: 16;--wp--custom--line-height--small: 1.2;--wp--custom--line-height--medium: 1.4;--wp--custom--line-height--large: 1.8;}',
$theme_json->get_stylesheet( array( 'css_variables' ) )
$theme_json->get_stylesheet( array( 'variables' ) )
);
}

Expand Down
18 changes: 9 additions & 9 deletions phpunit/class-wp-theme-json-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ function test_get_stylesheet_support_for_shorthand_and_longhand_values() {
);
$this->assertEquals(
'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-block-group{border-radius: 10px;margin: 1em;padding: 24px;}.wp-block-image{border-top-left-radius: 10px;border-bottom-right-radius: 1em;margin-bottom: 30px;padding-top: 15px;}',
$theme_json->get_stylesheet( array( 'block_classes', 'preset_classes' ) )
$theme_json->get_stylesheet( array( 'styles', 'presets' ) )
);
}

Expand Down Expand Up @@ -260,7 +260,7 @@ function test_get_stylesheet_skips_disabled_protected_properties() {

$expected = 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }';
$this->assertEquals( $expected, $theme_json->get_stylesheet() );
$this->assertEquals( $expected, $theme_json->get_stylesheet( array( 'block_classes', 'preset_classes' ) ) );
$this->assertEquals( $expected, $theme_json->get_stylesheet( array( 'styles', 'presets' ) ) );
}

function test_get_stylesheet_renders_enabled_protected_properties() {
Expand Down Expand Up @@ -289,7 +289,7 @@ function test_get_stylesheet_renders_enabled_protected_properties() {

$expected = 'body{--wp--style--block-gap: 1em;}body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-site-blocks > * { margin-top: 0; margin-bottom: 0; }.wp-site-blocks > * + * { margin-top: var( --wp--style--block-gap ); }.wp-block-columns{--wp--style--block-gap: 24px;}';
$this->assertEquals( $expected, $theme_json->get_stylesheet() );
$this->assertEquals( $expected, $theme_json->get_stylesheet( array( 'block_classes', 'preset_classes' ) ) );
$this->assertEquals( $expected, $theme_json->get_stylesheet( array( 'styles', 'presets' ) ) );
}

function test_get_stylesheet() {
Expand Down Expand Up @@ -418,11 +418,11 @@ function test_get_stylesheet() {
);
$this->assertEquals(
'body{color: var(--wp--preset--color--grey);}body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-site-blocks > * { margin-top: 0; margin-bottom: 0; }.wp-site-blocks > * + * { margin-top: var( --wp--style--block-gap ); }a{background-color: #333;color: #111;}.wp-block-group{border-radius: 10px;padding: 24px;}.wp-block-group a{color: #111;}h1,h2,h3,h4,h5,h6{color: #123456;}h1 a,h2 a,h3 a,h4 a,h5 a,h6 a{background-color: #333;color: #111;font-size: 60px;}.wp-block-post-date{color: #123456;}.wp-block-post-date a{background-color: #777;color: #555;}.wp-block-image{border-top-left-radius: 10px;border-bottom-right-radius: 1em;margin-bottom: 30px;}.has-grey-color{color: var(--wp--preset--color--grey) !important;}.has-grey-background-color{background-color: var(--wp--preset--color--grey) !important;}.has-grey-border-color{border-color: var(--wp--preset--color--grey) !important;}.has-small-font-family{font-family: var(--wp--preset--font-family--small) !important;}.has-big-font-family{font-family: var(--wp--preset--font-family--big) !important;}',
$theme_json->get_stylesheet( array( 'block_classes', 'preset_classes' ) )
$theme_json->get_stylesheet( array( 'styles', 'presets' ) )
);
$this->assertEquals(
'body{--wp--preset--color--grey: grey;--wp--preset--font-family--small: 14px;--wp--preset--font-family--big: 41px;}.wp-block-group{--wp--custom--base-font: 16;--wp--custom--line-height--small: 1.2;--wp--custom--line-height--medium: 1.4;--wp--custom--line-height--large: 1.8;}',
$theme_json->get_stylesheet( array( 'css_variables' ) )
$theme_json->get_stylesheet( array( 'variables' ) )
);
}

Expand All @@ -449,7 +449,7 @@ function test_get_stylesheet_preset_classes_work_with_compounded_selectors() {

$this->assertEquals(
'h1.has-white-color,h2.has-white-color,h3.has-white-color,h4.has-white-color,h5.has-white-color,h6.has-white-color{color: var(--wp--preset--color--white) !important;}h1.has-white-background-color,h2.has-white-background-color,h3.has-white-background-color,h4.has-white-background-color,h5.has-white-background-color,h6.has-white-background-color{background-color: var(--wp--preset--color--white) !important;}h1.has-white-border-color,h2.has-white-border-color,h3.has-white-border-color,h4.has-white-border-color,h5.has-white-border-color,h6.has-white-border-color{border-color: var(--wp--preset--color--white) !important;}',
$theme_json->get_stylesheet( array( 'block_classes', 'preset_classes' ) )
$theme_json->get_stylesheet( array( 'styles', 'presets' ) )
);
}

Expand Down Expand Up @@ -489,7 +489,7 @@ function test_get_stylesheet_preset_rules_come_after_block_rules() {
);
$this->assertEquals(
'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-block-group{color: red;}.wp-block-group.has-grey-color{color: var(--wp--preset--color--grey) !important;}.wp-block-group.has-grey-background-color{background-color: var(--wp--preset--color--grey) !important;}.wp-block-group.has-grey-border-color{border-color: var(--wp--preset--color--grey) !important;}',
$theme_json->get_stylesheet( array( 'block_classes', 'preset_classes' ) )
$theme_json->get_stylesheet( array( 'styles', 'presets' ) )
);
}

Expand Down Expand Up @@ -524,11 +524,11 @@ function test_get_stylesheet_generates_proper_classes_from_slugs() {

$this->assertEquals(
'.has-grey-color{color: var(--wp--preset--color--grey) !important;}.has-dark-grey-color{color: var(--wp--preset--color--dark-grey) !important;}.has-light-grey-color{color: var(--wp--preset--color--light-grey) !important;}.has-white-2-black-color{color: var(--wp--preset--color--white-2-black) !important;}.has-grey-background-color{background-color: var(--wp--preset--color--grey) !important;}.has-dark-grey-background-color{background-color: var(--wp--preset--color--dark-grey) !important;}.has-light-grey-background-color{background-color: var(--wp--preset--color--light-grey) !important;}.has-white-2-black-background-color{background-color: var(--wp--preset--color--white-2-black) !important;}.has-grey-border-color{border-color: var(--wp--preset--color--grey) !important;}.has-dark-grey-border-color{border-color: var(--wp--preset--color--dark-grey) !important;}.has-light-grey-border-color{border-color: var(--wp--preset--color--light-grey) !important;}.has-white-2-black-border-color{border-color: var(--wp--preset--color--white-2-black) !important;}',
$theme_json->get_stylesheet( array( 'block_classes', 'preset_classes' ) )
$theme_json->get_stylesheet( array( 'styles', 'presets' ) )
);
$this->assertEquals(
'body{--wp--preset--color--grey: grey;--wp--preset--color--dark-grey: grey;--wp--preset--color--light-grey: grey;--wp--preset--color--white-2-black: grey;}',
$theme_json->get_stylesheet( array( 'css_variables' ) )
$theme_json->get_stylesheet( array( 'variables' ) )
);

}
Expand Down

0 comments on commit c73e850

Please sign in to comment.