-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Clean up after rebase Clean up after rebase
- Loading branch information
Showing
8 changed files
with
136 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
packages/style-engine/class-wp-style-engine-css-rules-container.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
/** | ||
* WP_Style_Engine_CSS_Rules_Container | ||
* | ||
* A container for WP_Style_Engine_CSS_Rule objects. | ||
* | ||
* @package Gutenberg | ||
*/ | ||
// @TODO new file and tests | ||
// Should have same/similar interface to WP_Style_Engine_CSS_Rule or maybe even part of it? | ||
class WP_Style_Engine_CSS_Rules_Container { | ||
protected $container; | ||
protected $rules = array(); | ||
|
||
public function __construct( $container = '', $rule ) { | ||
$this->set_container( $container ); | ||
// @TODO should be able to add multiple rules. | ||
// @TODO check for instance of WP_Style_Engine_CSS_Rule | ||
$this->add_rule( $rule ); | ||
} | ||
|
||
public function set_container( $container ) { | ||
$this->container = $container; | ||
return $this; | ||
} | ||
|
||
public function get_container() { | ||
return $this->container; | ||
} | ||
|
||
public function get_rules() { | ||
return $this->rules; | ||
} | ||
|
||
public function get_rule( $selector ) { | ||
return $this->rules[ $selector ] ?? null; | ||
} | ||
|
||
public function add_rule( $rule ) { | ||
// @TODO should be able to add multiple rules. | ||
// @TODO should be able to return a rule and update its selectors | ||
// @TODO check for instance of WP_Style_Engine_CSS_Rule | ||
$selector = $rule->get_selector(); | ||
|
||
if ( isset( $this->rules[ $selector ] ) ) { | ||
$this->rules[ $selector ]->add_declarations( $rule->get_declarations() ); | ||
} else { | ||
$this->rules[ $selector ] = $rule; | ||
} | ||
return $this; | ||
} | ||
|
||
public function get_css( $should_prettify = false, $indent_count = 0 ) { | ||
$css = ''; | ||
$indent_count = $should_prettify ? $indent_count + 1 : $indent_count; | ||
$new_line = $should_prettify ? "\n" : ''; | ||
$spacer = $should_prettify ? ' ' : ''; | ||
foreach ( $this->rules as $rule ) { | ||
$css .= $rule->get_css( $should_prettify, $indent_count ); | ||
$css .= $should_prettify ? "\n" : ''; | ||
} | ||
|
||
if ( empty( $css ) ) { | ||
return ''; | ||
} | ||
|
||
return "{$this->container}{$spacer}{{$new_line}{$css}}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.