Skip to content

Commit a436112

Browse files
committed
update
1 parent f98ae6d commit a436112

File tree

3 files changed

+51
-15
lines changed

3 files changed

+51
-15
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
44

55
This projects adheres to [Semantic Versioning](https://semver.org/) and [Keep a CHANGELOG](https://keepachangelog.com/).
66

7+
## [11.0.4]
8+
9+
### Added
10+
11+
- `outputCssVariablesGlobalClean` method to the `CssVariablesTrait` helper. Not wrapped in a style tag. Used in patterns.
12+
- `outputCssVariablesGlobal` method to the `CssVariablesTrait` helper.
13+
- `outputCssVariablesInlineClean` method to the `CssVariablesTrait` helper. Not wrapped in a style tag. Used in patterns.
14+
- `outputCssVariablesInline` method to the `CssVariablesTrait` helper.
15+
716
## [11.0.3]
817

918
### Fixed
@@ -1066,6 +1075,7 @@ Init setup
10661075
- Gutenberg Blocks Registration.
10671076
- Assets Manifest data.
10681077

1078+
[11.0.4]: https://github.com/infinum/eightshift-libs/compare/11.0.3...11.0.4
10691079
[11.0.3]: https://github.com/infinum/eightshift-libs/compare/11.0.2...11.0.3
10701080
[11.0.2]: https://github.com/infinum/eightshift-libs/compare/11.0.1...11.0.2
10711081
[11.0.1]: https://github.com/infinum/eightshift-libs/compare/11.0.0...11.0.1

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
"php-di/php-di": "^7.1.1"
3333
},
3434
"require-dev": {
35-
"dealerdirect/phpcodesniffer-composer-installer": "1.1.2",
35+
"dealerdirect/phpcodesniffer-composer-installer": "1.2.0",
3636
"infinum/eightshift-coding-standards": "^3.0.0",
3737
"php-parallel-lint/php-parallel-lint": "^v1.4.0",
38-
"php-stubs/wordpress-stubs": "6.8.2",
39-
"szepeviktor/phpstan-wordpress": "2.0.2",
38+
"php-stubs/wordpress-stubs": "6.9.0",
39+
"szepeviktor/phpstan-wordpress": "2.0.3",
4040
"wp-cli/wp-cli": "2.12.0",
41-
"phpunit/phpunit": "^12.3.10",
41+
"phpunit/phpunit": "^12.5.0",
4242
"brain/monkey": "^2.6.2",
4343
"mockery/mockery": "^1.6.12"
4444
},

src/Helpers/CssVariablesTrait.php

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
trait CssVariablesTrait
1717
{
1818
/**
19-
* Get Global Manifest.json and return globalVariables as CSS variables.
19+
* Get Global Manifest.json and return globalVariables as CSS variables. Not wrapped in a style tag.
2020
*
2121
* @param array<string, mixed> $globalSettings Global settings.
2222
*
2323
* @return string
2424
*/
25-
public static function outputCssVariablesGlobal(array $globalSettings = []): string
25+
public static function outputCssVariablesGlobalClean(array $globalSettings = []): string
2626
{
2727
$output = '';
2828

@@ -38,9 +38,7 @@ public static function outputCssVariablesGlobal(array $globalSettings = []): str
3838
}
3939
}
4040

41-
$id = Helpers::getConfigOutputCssSelectorName();
42-
43-
$output = "<style id='{$id}-global'>:root {{$output}}</style>";
41+
$output = ":root {{$output}}";
4442

4543
if (Helpers::getConfigOutputCssOptimize()) {
4644
$output = \str_replace(["\n", "\r"], '', $output);
@@ -49,6 +47,21 @@ public static function outputCssVariablesGlobal(array $globalSettings = []): str
4947
return $output;
5048
}
5149

50+
/**
51+
* Get Global Manifest.json and return globalVariables as CSS variables. Wrapped in a style tag.
52+
*
53+
* @param array<string, mixed> $globalSettings Global settings.
54+
*
55+
* @return string
56+
*/
57+
public static function outputCssVariablesGlobal(array $globalSettings = []): string
58+
{
59+
$output = self::outputCssVariablesGlobalClean($globalSettings);
60+
$id = Helpers::getConfigOutputCssSelectorName() . '-global';
61+
62+
return "<style id='{$id}'>{$output}</style>";
63+
}
64+
5265
/**
5366
* Get component/block options and process them in CSS variables.
5467
*
@@ -142,13 +155,13 @@ static function ($key) use ($attributes) {
142155
}
143156

144157
/**
145-
* Output css variables as a one inline style tag. Used with wp_footer filter.
158+
* Output css variables as a one inline style tag. Used with wp_footer filter. Not wrapped in a style tag.
146159
*
147160
* @param array<string, mixed> $globalSettings Global settings.
148161
*
149162
* @return string
150163
*/
151-
public static function outputCssVariablesInline(array $globalSettings = []): string
164+
public static function outputCssVariablesInlineClean(array $globalSettings = []): string
152165
{
153166
// Load normal styles if server side render is used.
154167
$context = isset($_GET['context']) ? \sanitize_text_field(\wp_unslash($_GET['context'])) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
@@ -266,9 +279,22 @@ static function () {
266279
$additionalStyles = Helpers::getConfigOutputCssGloballyAdditionalStyles();
267280
$additionalStylesOutput = $additionalStyles ? \esc_html(\implode(";\n", $additionalStyles)) : '';
268281

282+
return "{$output} {$additionalStylesOutput}";
283+
}
284+
285+
/**
286+
* Output css variables as a one inline style tag. Used with wp_footer filter. Wrapped in a style tag.
287+
*
288+
* @param array<string, mixed> $globalSettings Global settings.
289+
*
290+
* @return string
291+
*/
292+
public static function outputCssVariablesInline(array $globalSettings = []): string
293+
{
294+
$output = self::outputCssVariablesInlineClean($globalSettings);
269295
$selector = Helpers::getConfigOutputCssSelectorName();
270296

271-
return "<style id='{$selector}'>{$output} {$additionalStylesOutput}</style>";
297+
return "<style id='{$selector}'>{$output}</style>";
272298
}
273299

274300
/**
@@ -366,9 +392,9 @@ private static function getCssVariablesTypeDefault(string $name, array $data, ar
366392

367393
// Prepare final output for testing.
368394
$fullOutput = "
369-
{$output}
370-
{$manual}
371-
";
395+
{$output}
396+
{$manual}
397+
";
372398

373399
// Check if final output is empty and and remove if it is.
374400
if (empty(\trim($fullOutput))) {

0 commit comments

Comments
 (0)