Skip to content

Commit

Permalink
Adapt core theme.json file & i18n to new shape
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Apr 8, 2021
1 parent f450ed5 commit 3c7b6e1
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 54 deletions.
6 changes: 3 additions & 3 deletions lib/class-wp-theme-json-resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,13 @@ private static function translate( $theme_json, $domain = 'default' ) {
/*
* We need to process the paths that include '*' separately.
* One example of such a path would be:
* [ 'settings', '*', 'color', 'palette' ]
* [ 'settings', 'blocks', '*', 'color', 'palette' ]
*/
$nodes_to_iterate = array_keys( $path, '*', true );
if ( ! empty( $nodes_to_iterate ) ) {
/*
* At the moment, we only need to support one '*' in the path, so take it directly.
* - base will be [ 'settings' ]
* - base will be [ 'settings', 'blocks' ]
* - data will be [ 'color', 'palette' ]
*/
$base_path = array_slice( $path, 0, $nodes_to_iterate[0] );
Expand All @@ -213,7 +213,7 @@ private static function translate( $theme_json, $domain = 'default' ) {
continue;
}

// Whole path will be [ 'settings', 'core/paragraph', 'color', 'palette' ].
// Whole path will be [ 'settings', 'blocks', 'core/paragraph', 'color', 'palette' ].
$whole_path = array_merge( $base_path, array( $node_name ), $data_path );
$translated_array = self::translate_theme_json_chunk( $array_to_translate, $key, $context, $domain );
gutenberg_experimental_set( $theme_json, $whole_path, $translated_array );
Expand Down
23 changes: 11 additions & 12 deletions lib/experimental-default-theme.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": 1,
"settings": {
"defaults": {
"color": {
"color": {
"palette": [
{
"name": "Black",
Expand Down Expand Up @@ -129,8 +129,8 @@
"custom": true,
"link": false,
"customGradient": true
},
"typography": {
},
"typography": {
"dropCap": true,
"customFontSize": true,
"customLineHeight": false,
Expand Down Expand Up @@ -165,14 +165,13 @@
"size": "42px"
}
]
},
"spacing": {
"customPadding": false,
"units": [ "px", "em", "rem", "vh", "vw" ]
},
"border": {
"customRadius": false
}
},
"spacing": {
"customPadding": false,
"units": [ "px", "em", "rem", "vh", "vw" ]
},
"border": {
"customRadius": false
}
}
}
54 changes: 50 additions & 4 deletions lib/experimental-i18n-theme.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"settings": {
"*": {
"typography": {
"typography": {
"fontSizes": [
{
"name": "Font size name"
Expand Down Expand Up @@ -32,8 +31,8 @@
"name": "Text decoration name"
}
]
},
"color": {
},
"color": {
"palette": [
{
"name": "Color name"
Expand All @@ -44,6 +43,53 @@
"name": "Gradient name"
}
]
},
"blocks": {
"*": {
"typography": {
"fontSizes": [
{
"name": "Font size name"
}
],
"fontStyles": [
{
"name": "Font style name"
}
],
"fontWeights": [
{
"name": "Font weight name"
}
],
"fontFamilies": [
{
"name": "Font family name"
}
],
"textTransforms": [
{
"name": "Text transform name"
}
],
"textDecorations": [
{
"name": "Text decoration name"
}
]
},
"color": {
"palette": [
{
"name": "Color name"
}
],
"gradients": [
{
"name": "Gradient name"
}
]
}
}
}
},
Expand Down
95 changes: 75 additions & 20 deletions phpunit/class-wp-theme-json-resolver-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,42 +45,82 @@ function test_fields_are_extracted() {

$expected = array(
array(
'path' => array( 'settings', '*', 'typography', 'fontSizes' ),
'path' => array( 'settings', 'typography', 'fontSizes' ),
'key' => 'name',
'context' => 'Font size name',
),
array(
'path' => array( 'settings', '*', 'typography', 'fontStyles' ),
'path' => array( 'settings', 'typography', 'fontStyles' ),
'key' => 'name',
'context' => 'Font style name',
),
array(
'path' => array( 'settings', '*', 'typography', 'fontWeights' ),
'path' => array( 'settings', 'typography', 'fontWeights' ),
'key' => 'name',
'context' => 'Font weight name',
),
array(
'path' => array( 'settings', '*', 'typography', 'fontFamilies' ),
'path' => array( 'settings', 'typography', 'fontFamilies' ),
'key' => 'name',
'context' => 'Font family name',
),
array(
'path' => array( 'settings', '*', 'typography', 'textTransforms' ),
'path' => array( 'settings', 'typography', 'textTransforms' ),
'key' => 'name',
'context' => 'Text transform name',
),
array(
'path' => array( 'settings', '*', 'typography', 'textDecorations' ),
'path' => array( 'settings', 'typography', 'textDecorations' ),
'key' => 'name',
'context' => 'Text decoration name',
),
array(
'path' => array( 'settings', '*', 'color', 'palette' ),
'path' => array( 'settings', 'color', 'palette' ),
'key' => 'name',
'context' => 'Color name',
),
array(
'path' => array( 'settings', '*', 'color', 'gradients' ),
'path' => array( 'settings', 'color', 'gradients' ),
'key' => 'name',
'context' => 'Gradient name',
),
array(
'path' => array( 'settings', 'blocks', '*', 'typography', 'fontSizes' ),
'key' => 'name',
'context' => 'Font size name',
),
array(
'path' => array( 'settings', 'blocks', '*', 'typography', 'fontStyles' ),
'key' => 'name',
'context' => 'Font style name',
),
array(
'path' => array( 'settings', 'blocks', '*', 'typography', 'fontWeights' ),
'key' => 'name',
'context' => 'Font weight name',
),
array(
'path' => array( 'settings', 'blocks', '*', 'typography', 'fontFamilies' ),
'key' => 'name',
'context' => 'Font family name',
),
array(
'path' => array( 'settings', 'blocks', '*', 'typography', 'textTransforms' ),
'key' => 'name',
'context' => 'Text transform name',
),
array(
'path' => array( 'settings', 'blocks', '*', 'typography', 'textDecorations' ),
'key' => 'name',
'context' => 'Text decoration name',
),
array(
'path' => array( 'settings', 'blocks', '*', 'color', 'palette' ),
'key' => 'name',
'context' => 'Color name',
),
array(
'path' => array( 'settings', 'blocks', '*', 'color', 'gradients' ),
'key' => 'name',
'context' => 'Gradient name',
),
Expand All @@ -107,22 +147,37 @@ function test_translations_are_applied() {

$this->assertSame( wp_get_theme()->get( 'TextDomain' ), 'fse' );
$this->assertSame(
$actual->get_settings()['root']['color'],
array(
'palette' => array(
array(
'slug' => 'light',
'name' => 'Jasny',
'color' => '#f5f7f9',
'color' => array(
'palette' => array(
array(
'slug' => 'light',
'name' => 'Jasny',
'color' => '#f5f7f9',
),
array(
'slug' => 'dark',
'name' => 'Ciemny',
'color' => '#000',
),
),
array(
'slug' => 'dark',
'name' => 'Ciemny',
'color' => '#000',
'custom' => false,
),
'blocks' => array(
'core/paragraph' => array(
'color' => array(
'palette' => array(
array(
'slug' => 'light',
'name' => 'Jasny',
'color' => '#f5f7f9',
),
),
),
),
),
'custom' => false,
)
),
$actual->get_settings()
);
$this->assertSame(
$actual->get_custom_templates(),
Expand Down
42 changes: 27 additions & 15 deletions phpunit/data/themedir1/fse/experimental-theme.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
{
"version": 1,
"settings": {
"root": {
"color": {
"palette": [
{
"slug": "light",
"name": "Light",
"color": "#f5f7f9"
},
{
"slug": "dark",
"name": "Dark",
"color": "#000"
}
],
"custom": false
"color": {
"palette": [
{
"slug": "light",
"name": "Light",
"color": "#f5f7f9"
},
{
"slug": "dark",
"name": "Dark",
"color": "#000"
}
],
"custom": false
},
"blocks": {
"core/paragraph": {
"color": {
"palette": [
{
"slug": "light",
"name": "Light",
"color": "#f5f7f9"
}
]
}
}
}
},
Expand Down

0 comments on commit 3c7b6e1

Please sign in to comment.