Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0840074
Enqueuing block support styles version 1.
ramonjd Jul 15, 2022
6a42821
Linter, this one's for you.
ramonjd Jul 15, 2022
1f2b4a8
Post trunk merge cleanup and update tests.
ramonjd Jul 15, 2022
5a51073
Removed spacing around curly braces in CSS rules. Updated tests.
ramonjd Jul 18, 2022
55576b9
Splitting `wp_style_engine_enqueue_block_supports_styles` and `wp_sty…
ramonjd Jul 19, 2022
acc6209
Integrate the processor class
ramonjd Jul 24, 2022
7a22c5b
Migrate layout styles to style engine store.
ramonjd Jul 25, 2022
7a6aa60
Update packages/style-engine/class-wp-style-engine.php
ramonjd Jul 27, 2022
49b1433
Tweaks for #42452 (#42691)
aristath Jul 27, 2022
d7893a6
Adding check for the context argument.
ramonjd Jul 28, 2022
bc6e39a
Updating the processor so that it's ignorant of stores. Why? So that …
ramonjd Jul 29, 2022
e8a621d
dump var_dump()
ramonjd Jul 29, 2022
9ba5232
Improve the processor
aristath Jul 29, 2022
b41af7d
remove trailing commas - compatibility with PHP < 7.2
aristath Jul 29, 2022
4ccf650
rename css_declarations to declarations
aristath Jul 29, 2022
e30e4fb
remove unused variable
aristath Jul 29, 2022
062b920
Switch parse_block_styles from public to protected static
ramonjd Aug 1, 2022
5e4164a
Now that all methods are static, there's no need to call `get_instanc…
ramonjd Aug 1, 2022
fcebf93
Revert get_instance() in wp_style_engine_add_to_store because we want…
ramonjd Aug 1, 2022
d0d5fe5
Adding a test for the 'enqueue' flag.
ramonjd Aug 1, 2022
e59eb10
Update lib/block-supports/layout.php
ramonjd Aug 1, 2022
5d7b827
Adding a test for the 'enqueue' flag.
ramonjd Aug 1, 2022
4d9f6c8
Merge branch 'try/style-engine-enqueue-block-supports-styles' of gith…
ramonjd Aug 1, 2022
8d021ee
Add named stores to the processor
aristath Aug 1, 2022
5f60026
avoid setting var for something that only gets used once
aristath Aug 1, 2022
a63f9cb
Only use "else" if absolutely necessary
aristath Aug 1, 2022
0eaef08
Add a set_name method
aristath Aug 1, 2022
e4c791b
combine & simplify conditions
aristath Aug 1, 2022
787f793
use empty() instead of isset() checks here
aristath Aug 1, 2022
7dd5773
shorten it
aristath Aug 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove unused variable
Removing unused function wp_style_engine_get_stylesheet_from_store
Updating tests to check for merging and deduping
  • Loading branch information
aristath authored and ramonjd committed Aug 1, 2022
commit e30e4fb316a7d709688e137956b52fca300d89bc
2 changes: 1 addition & 1 deletion packages/style-engine/class-wp-style-engine-processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function get_css() {
private function combine_rules_selectors() {
// Build an array of selectors along with the JSON-ified styles to make comparisons easier.
$selectors_json = array();
foreach ( $this->css_rules as $index => $rule ) {
foreach ( $this->css_rules as $rule ) {

$rule_selector = $rule->get_selector();
$declarations = $rule->get_declarations()->get_declarations();
Expand Down
19 changes: 0 additions & 19 deletions packages/style-engine/class-wp-style-engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -738,22 +738,3 @@ function wp_style_engine_get_stylesheet_from_css_rules( $css_rules = array() ) {

return $style_engine::compile_stylesheet_from_css_rules( $css_rule_objects );
}

/**
* Returns a compiled stylesheet from stored CSS rules.
*
* @access public
*
* @param string $store_key A valid store key.
*
* @return string A compiled stylesheet from stored CSS rules.
*/
function wp_style_engine_get_stylesheet_from_store( $store_key ) {
if ( empty( $store_key ) || ! class_exists( 'WP_Style_Engine' ) ) {
return '';
}

$style_engine = WP_Style_Engine::get_instance();
$store = $style_engine::get_store( $store_key );
return WP_Style_Engine::compile_stylesheet_from_css_rules( $store->get_all_rules() );
}
52 changes: 35 additions & 17 deletions packages/style-engine/phpunit/class-wp-style-engine-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,20 @@ public function data_generate_block_supports_styles_fixtures() {
* Tests adding rules to a store and retrieving a generated stylesheet.
*/
public function test_add_to_store() {
$store = wp_style_engine_add_to_store( 'test-store', array() );

// wp_style_engine_add_to_store returns a store object.
$this->assertInstanceOf( 'WP_Style_Engine_CSS_Rules_Store', $store );

// Check that the style engine knows about the store.
$stored_store = WP_Style_Engine::get_instance()::get_store( 'test-store' );
$this->assertInstanceOf( 'WP_Style_Engine_CSS_Rules_Store', $stored_store );
}

/**
* Tests retrieving a generated stylesheet from any rules.
*/
public function test_get_stylesheet_from_css_rules() {
$css_rules = array(
array(
'selector' => '.saruman',
Expand Down Expand Up @@ -541,48 +555,52 @@ public function test_add_to_store() {
),
),
);
$store = wp_style_engine_add_to_store( 'test-store', $css_rules );
$this->assertInstanceOf( 'WP_Style_Engine_CSS_Rules_Store', $store );

$compiled_stylesheet = wp_style_engine_get_stylesheet_from_store( 'test-store' );
$compiled_stylesheet = wp_style_engine_get_stylesheet_from_css_rules( $css_rules );
$this->assertSame( '.saruman {color: white; height: 100px; border-style: solid; align-self: unset;}.gandalf {color: grey; height: 90px; border-style: dotted; align-self: safe center;}.radagast {color: brown; height: 60px; border-style: dashed; align-self: stretch;}', $compiled_stylesheet );
}

/**
* Tests retrieving a generated stylesheet from any rules.
* Tests that incoming styles are deduped and merged.
*/
public function test_get_stylesheet_from_css_rules() {
public function test_get_deduped_and_merged_stylesheet() {
$css_rules = array(
array(
'selector' => '.saruman',
'selector' => '.gandalf',
'declarations' => array(
'color' => 'white',
'height' => '100px',
'border-style' => 'solid',
'align-self' => 'unset',
'color' => 'grey',
'height' => '90px',
'border-style' => 'dotted',
),
),
array(
'selector' => '.gandalf',
'declarations' => array(
'color' => 'white',
'height' => '190px',
'padding' => '10px',
'margin-bottom' => '100px',
),
),
array(
'selector' => '.dumbledore',
'declarations' => array(
'color' => 'grey',
'height' => '90px',
'border-style' => 'dotted',
'align-self' => 'safe center',
),
),
array(
'selector' => '.radagast',
'selector' => '.rincewind',
'declarations' => array(
'color' => 'brown',
'height' => '60px',
'border-style' => 'dashed',
'align-self' => 'stretch',
'color' => 'grey',
'height' => '90px',
'border-style' => 'dotted',
),
),
);

$compiled_stylesheet = wp_style_engine_get_stylesheet_from_css_rules( $css_rules );
$this->assertSame( '.saruman {color: white; height: 100px; border-style: solid; align-self: unset;}.gandalf {color: grey; height: 90px; border-style: dotted; align-self: safe center;}.radagast {color: brown; height: 60px; border-style: dashed; align-self: stretch;}', $compiled_stylesheet );
$this->assertSame( '.gandalf {color: white; height: 190px; border-style: dotted; padding: 10px; margin-bottom: 100px;}.dumbledore,.rincewind {color: grey; height: 90px; border-style: dotted;}', $compiled_stylesheet );
}
}