Skip to content

Commit

Permalink
Resolver: add different rules
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Feb 18, 2020
1 parent 67c3079 commit 0563fcb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
10 changes: 6 additions & 4 deletions experimental-default-global-styles.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"color": {
"primary": "#52accc",
"background": "white",
"text": "black"
"core": {
"color": {
"primary": "#52accc",
"background": "white",
"text": "black"
}
}
}
32 changes: 20 additions & 12 deletions lib/global-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,22 +171,30 @@ function gutenberg_experimental_global_styles_get_theme() {
* @return string CSS rule.
*/
function gutenberg_experimental_global_styles_resolver( $global_styles ) {
$css_rule = '';
$css_rules = '';

$token = '--';
$prefix = '--wp' . $token;
$css_vars = gutenberg_experimental_global_styles_get_css_vars( $global_styles, $prefix, $token );
if ( empty( $css_vars ) ) {
return $css_rule;
}
// This is only for demo purposes, it should be pluggable
// so new selectors can be register (3rd party blocks, etc).
$selectors = array(
'core' => ':root',
'core/paragraph' => '.entry-content p',
);
foreach ( $global_styles as $blockname => $subtree ) {
$token = '--';
$prefix = '--wp' . $token;
$css_vars = gutenberg_experimental_global_styles_get_css_vars( $subtree, $prefix, $token );
if ( empty( $css_vars ) ) {
return $css_rules;
}

$css_rule = ":root {\n";
foreach ( $css_vars as $var => $value ) {
$css_rule .= "\t" . $var . ': ' . $value . ";\n";
$css_rules .= $selectors[ $blockname ] . " {\n";
foreach ( $css_vars as $var => $value ) {
$css_rules .= "\t" . $var . ': ' . $value . ";\n";
}
$css_rules .= "}\n";
}
$css_rule .= '}';

return $css_rule;
return $css_rules;
}

/**
Expand Down

0 comments on commit 0563fcb

Please sign in to comment.