PluginProbe
Tableberg – Simple Gutenberg Table Block / 1.1.5
Tableberg – Simple Gutenberg Table Block v1.1.5
1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.5 1.0.4 1.0.3 1.0.2 1.0.1 trunk 0.0.2 0.2.1 0.3.2 0.3.3 0.4.1 0.5.0 0.5.1 0.5.2 0.5.3 0.5.4 0.5.5 0.5.6 0.5.7 All 42 releases
← All changes | renderer/Text/TextRenderer.php +30 -1 1.0.31.1.5 View file →
@@ -9,10 +9,19 @@
9 9 */
10 10 public function render($attributes) {
11 11 $attrs = TextAttrs::from_array($attributes);
12 12
13 - $styleValues = ['margin:0'];
13 + $marginShorthand = $this->sides_shorthand($attrs->styles->margin);
14 + $paddingShorthand = $this->sides_shorthand($attrs->styles->padding);
14 15
16 + $styleValues = [];
17 + $styleValues[] = 'margin:' . ($marginShorthand !== '' ? $marginShorthand : '0');
18 + if ($paddingShorthand !== '') {
19 + $styleValues[] = 'padding:' . $paddingShorthand;
20 + }
21 +
22 + $styleValues[] = 'text-align:' . $attrs->align->asAttr();
23 +
15 24 if ($attrs->styles->textColor->isNotEmpty()) {
16 25 $styleValues[] = 'color:' . $attrs->styles->textColor->asAttr();
17 26 }
18 27
@@ -33,6 +42,26 @@
33 42 return
34 43 "<p class='tableberg-text-element' style='{$styleAttr}'>
35 44 {$attrs->content->asHtml()}
36 45 </p>";
46 + }
47 +
48 + /**
49 + * Build a CSS shorthand from a 4-side value; returns '' when all sides
50 + * are empty so the property can be skipped.
51 + *
52 + * @param Sides $sides
53 + * @return string
54 + */
55 + private function sides_shorthand($sides) {
56 + $top = $sides->top->isNotEmpty() ? $sides->top->asAttr() : '0';
57 + $right = $sides->right->isNotEmpty() ? $sides->right->asAttr() : '0';
58 + $bottom = $sides->bottom->isNotEmpty() ? $sides->bottom->asAttr() : '0';
59 + $left = $sides->left->isNotEmpty() ? $sides->left->asAttr() : '0';
60 +
61 + if ($top === '0' && $right === '0' && $bottom === '0' && $left === '0') {
62 + return '';
63 + }
64 +
65 + return "{$top} {$right} {$bottom} {$left}";
37 66 }
38 67 }