Skip to content

Commit

Permalink
Grammar, formatting, removing class_exists checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonjd committed Sep 9, 2022
1 parent 26cd739 commit bb87fe4
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 91 deletions.
22 changes: 6 additions & 16 deletions src/wp-includes/style-engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,12 @@
* }
*
* @return array {
* @type string $css A CSS ruleset or declarations block formatted to be placed in an HTML `style` attribute or tag.
* @type array<string, string> $declarations An array of property/value pairs representing parsed CSS declarations.
* @type string $classnames Classnames separated by a space.
* @type string $css A CSS ruleset or declarations block formatted to be placed in an HTML `style` attribute or tag.
* @type string[] $declarations An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ).
* @type string $classnames Classnames separated by a space.
* }
*/
function wp_style_engine_get_styles( $block_styles, $options = array() ) {
if ( ! class_exists( 'WP_Style_Engine' ) ) {
return array();
}

$options = wp_parse_args(
$options,
array(
Expand Down Expand Up @@ -85,15 +81,14 @@ function wp_style_engine_get_styles( $block_styles, $options = array() ) {
* $css = wp_style_engine_get_stylesheet_from_css_rules( $css_rules );
* // Returns `.elephant-are-cool{color:gray;width:3em}`.
*
* @access public
* @since 6.1.0
*
* @param array $css_rules {
* Required. A collection of CSS rules.
*
* @type array ...$0 {
* @type string $selector A CSS selector.
* @type array<string, string> $declarations An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ).
* @type string $selector A CSS selector.
* @type string[] $declarations An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ).
* }
* }
* @param array $options {
Expand All @@ -108,7 +103,7 @@ function wp_style_engine_get_styles( $block_styles, $options = array() ) {
* @return string A compiled CSS string.
*/
function wp_style_engine_get_stylesheet_from_css_rules( $css_rules, $options = array() ) {
if ( ! class_exists( 'WP_Style_Engine' ) || empty( $css_rules ) ) {
if ( empty( $css_rules ) ) {
return '';
}

Expand Down Expand Up @@ -142,7 +137,6 @@ function wp_style_engine_get_stylesheet_from_css_rules( $css_rules, $options = a
/**
* Returns compiled CSS from a store, if found.
*
* @access public
* @since 6.1.0
*
* @param string $context A valid context name, corresponding to an existing store key.
Expand All @@ -156,9 +150,5 @@ function wp_style_engine_get_stylesheet_from_css_rules( $css_rules, $options = a
* @return string A compiled CSS string.
*/
function wp_style_engine_get_stylesheet_from_context( $context, $options = array() ) {
if ( ! class_exists( 'WP_Style_Engine' ) || empty( $context ) ) {
return '';
}

return WP_Style_Engine::compile_stylesheet_from_css_rules( WP_Style_Engine::get_store( $context )->get_all_rules(), $options );
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct( $declarations = array() ) {
}

/**
* Add a single declaration.
* Adds a single declaration.
*
* @since 6.1.0
*
Expand All @@ -53,7 +53,6 @@ public function __construct( $declarations = array() ) {
* @return WP_Style_Engine_CSS_Declarations Returns the object to allow chaining methods.
*/
public function add_declaration( $property, $value ) {

// Sanitize the property.
$property = $this->sanitize_property( $property );
// Bail early if the property is empty.
Expand Down Expand Up @@ -88,7 +87,7 @@ public function remove_declaration( $property ) {
}

/**
* Add multiple declarations.
* Adds multiple declarations.
*
* @since 6.1.0
*
Expand Down Expand Up @@ -139,7 +138,7 @@ public function get_declarations() {
* @param string $value The value to be filtered.
* @param string $spacer The spacer between the colon and the value. Defaults to an empty string.
*
* @return string The filtered declaration as a single string.
* @return string The filtered declaration or an empty string.
*/
protected static function filter_declaration( $property, $value, $spacer = '' ) {
$filtered_value = wp_strip_all_tags( $value, true );
Expand Down Expand Up @@ -177,7 +176,7 @@ public function get_declarations_string( $should_prettify = false, $indent_count
}

/**
* Sanitize property names.
* Sanitizes property names.
*
* @since 6.1.0
*
Expand Down
16 changes: 8 additions & 8 deletions src/wp-includes/style-engine/class-wp-style-engine-css-rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function set_selector( $selector ) {
}

/**
* Set the declarations.
* Sets the declarations.
*
* @since 6.1.0
*
Expand All @@ -92,18 +92,18 @@ public function add_declarations( $declarations ) {
}

/**
* Get the declarations object.
* Gets the declarations object.
*
* @since 6.1.0
*
* @return WP_Style_Engine_CSS_Declarations
* @return WP_Style_Engine_CSS_Declarations The declarations object.
*/
public function get_declarations() {
return $this->declarations;
}

/**
* Get the full selector.
* Gets the full selector.
*
* @since 6.1.0
*
Expand All @@ -114,7 +114,7 @@ public function get_selector() {
}

/**
* Get the CSS.
* Gets the CSS.
*
* @since 6.1.0
*
Expand All @@ -126,15 +126,15 @@ public function get_selector() {
public function get_css( $should_prettify = false, $indent_count = 0 ) {
$rule_indent = $should_prettify ? str_repeat( "\t", $indent_count ) : '';
$declarations_indent = $should_prettify ? $indent_count + 1 : 0;
$new_line = $should_prettify ? "\n" : '';
$space = $should_prettify ? ' ' : '';
$suffix = $should_prettify ? "\n" : '';
$spacer = $should_prettify ? ' ' : '';
$selector = $should_prettify ? str_replace( ',', ",\n", $this->get_selector() ) : $this->get_selector();
$css_declarations = $this->declarations->get_declarations_string( $should_prettify, $declarations_indent );

if ( empty( $css_declarations ) ) {
return '';
}

return "{$rule_indent}{$selector}{$space}{{$new_line}{$css_declarations}{$new_line}{$rule_indent}}";
return "{$rule_indent}{$selector}{$spacer}{{$suffix}{$css_declarations}{$suffix}{$rule_indent}}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class WP_Style_Engine_CSS_Rules_Store {
protected $rules = array();

/**
* Get an instance of the store.
* Gets an instance of the store.
*
* @since 6.1.0
*
Expand All @@ -67,7 +67,7 @@ public static function get_store( $store_name = 'default' ) {
}

/**
* Get an array of all available stores.
* Gets an array of all available stores.
*
* @since 6.1.0
*
Expand All @@ -89,7 +89,7 @@ public static function remove_all_stores() {
}

/**
* Set the store name.
* Sets the store name.
*
* @since 6.1.0
*
Expand All @@ -102,7 +102,7 @@ public function set_name( $name ) {
}

/**
* Get the store name.
* Gets the store name.
*
* @since 6.1.0
*
Expand All @@ -113,7 +113,7 @@ public function get_name() {
}

/**
* Get an array of all rules.
* Gets an array of all rules.
*
* @since 6.1.0
*
Expand All @@ -124,7 +124,7 @@ public function get_all_rules() {
}

/**
* Get a WP_Style_Engine_CSS_Rule object by its selector.
* Gets a WP_Style_Engine_CSS_Rule object by its selector.
* If the rule does not exist, it will be created.
*
* @since 6.1.0
Expand All @@ -150,7 +150,7 @@ public function add_rule( $selector ) {
}

/**
* Remove a selector from the store.
* Removes a selector from the store.
*
* @since 6.1.0
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function add_store( $store ) {
/**
* Adds rules to be processed.
*
* @since 6.1.0 a store to t
* @since 6.1.0
*
* @param WP_Style_Engine_CSS_Rule|WP_Style_Engine_CSS_Rule[] $css_rules A single, or an array of, WP_Style_Engine_CSS_Rule objects from a store or otherwise.
*
Expand Down
Loading

0 comments on commit bb87fe4

Please sign in to comment.