-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
minor tweaks to the style engine #43111
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,9 +34,6 @@ class WP_Style_Engine_CSS_Declarations { | |
* @param array $declarations An array of declarations (property => value pairs). | ||
*/ | ||
public function __construct( $declarations = array() ) { | ||
if ( empty( $declarations ) ) { | ||
return; | ||
} | ||
$this->add_declarations( $declarations ); | ||
} | ||
|
||
|
@@ -94,12 +91,12 @@ public function add_declarations( $declarations ) { | |
/** | ||
* Remove multiple declarations. | ||
* | ||
* @param array $declarations An array of properties. | ||
* @param array $properties An array of properties. | ||
* | ||
* @return void | ||
*/ | ||
public function remove_declarations( $declarations = array() ) { | ||
foreach ( $declarations as $property ) { | ||
public function remove_declarations( $properties = array() ) { | ||
foreach ( $properties as $property ) { | ||
Comment on lines
-97
to
+99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simply renamed |
||
$this->remove_declaration( $property ); | ||
} | ||
} | ||
|
@@ -123,10 +120,7 @@ public function get_declarations() { | |
* @return string The filtered declaration as a single string. | ||
*/ | ||
protected static function filter_declaration( $property, $value, $spacer = '' ) { | ||
if ( isset( $property ) && isset( $value ) ) { | ||
return safecss_filter_attr( "{$property}:{$spacer}{$value}" ); | ||
} | ||
return ''; | ||
return safecss_filter_attr( "{$property}:{$spacer}{$value}" ); | ||
Comment on lines
-126
to
+123
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there checks somewhere else? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes! We check the property and value when adding them to the object, so we already know they're there 😉 |
||
} | ||
|
||
/** | ||
|
@@ -143,9 +137,9 @@ public function get_declarations_string( $should_prettify = false, $indent_count | |
$indent = $should_prettify ? str_repeat( "\t", $indent_count ) : ''; | ||
$suffix = $should_prettify ? ' ' : ''; | ||
$suffix = $should_prettify && $indent_count > 0 ? "\n" : $suffix; | ||
$spacer = $should_prettify ? ' ' : ''; | ||
|
||
foreach ( $declarations_array as $property => $value ) { | ||
$spacer = $should_prettify ? ' ' : ''; | ||
Comment on lines
+140
to
-148
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved this outside the loop. The |
||
$filtered_declaration = static::filter_declaration( $property, $value, $spacer ); | ||
if ( $filtered_declaration ) { | ||
$declarations_output .= "{$indent}{$filtered_declaration};$suffix"; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,14 +51,10 @@ public function __construct( $selector = '', $declarations = array() ) { | |
* | ||
* @param string $selector The CSS selector. | ||
* | ||
* @return WP_Style_Engine_CSS_Rule|void Returns the object to allow chaining of methods. | ||
* @return WP_Style_Engine_CSS_Rule Returns the object to allow chaining of methods. | ||
*/ | ||
public function set_selector( $selector ) { | ||
if ( empty( $selector ) ) { | ||
return; | ||
} | ||
$this->selector = $selector; | ||
|
||
Comment on lines
-54
to
-61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Always return the object to avoid fatalities if chaining methods. |
||
return $this; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,7 +73,7 @@ public function add_rules( $css_rules ) { | |
public function get_css( $options = array() ) { | ||
$defaults = array( | ||
'optimize' => true, | ||
'prettify' => false, | ||
'prettify' => defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
); | ||
$options = wp_parse_args( $options, $defaults ); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -264,11 +264,7 @@ protected static function is_valid_style_value( $style_value ) { | |
return true; | ||
} | ||
|
||
if ( empty( $style_value ) ) { | ||
return false; | ||
} | ||
|
||
return true; | ||
return ! empty( $style_value ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just simplifying code a bit |
||
} | ||
|
||
/** | ||
|
@@ -512,7 +508,7 @@ public static function compile_css( $css_declarations, $css_selector ) { | |
public static function compile_stylesheet_from_css_rules( $css_rules ) { | ||
$processor = new WP_Style_Engine_Processor(); | ||
$processor->add_rules( $css_rules ); | ||
return $processor->get_css( array( 'prettify' => defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ); | ||
return $processor->get_css(); | ||
Comment on lines
-515
to
+511
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved this check to the |
||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If empty, then
add_declarations
won't add anything. This check doesn't serve any purpose.