Skip to content

Commit 92b3cc5

Browse files
authored
Merge pull request #32 from tronsha/feature/trim
Add trim support
2 parents b90d0e5 + b280ba8 commit 92b3cc5

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/Compiler.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,9 @@ private function handleAttributeBinding(DOMElement $node)
391391

392392
protected function handleTextNode(DOMText $node)
393393
{
394+
if (!empty(trim($node->textContent))) {
395+
$node->textContent = $this->builder->refactorTextNode($node->textContent);
396+
}
394397
return $node;
395398
}
396399

src/Utils/TwigBuilder.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ public function refactorCondition(string $condition): string
170170
$condition = str_replace('||', 'or', $condition);
171171
$condition = preg_replace('/!([^=])/', 'not $1', $condition);
172172
$condition = str_replace('.length', '|length', $condition);
173+
$condition = str_replace('.trim', '|trim', $condition);
173174

174175
foreach (Replacements::getConstants() as $constant => $value) {
175176
$condition = str_replace($value, Replacements::getSanitizedConstant($constant), $condition);
@@ -178,6 +179,14 @@ public function refactorCondition(string $condition): string
178179
return $condition;
179180
}
180181

182+
public function refactorTextNode(string $content): string
183+
{
184+
$content = str_replace('.length', '|length', $content);
185+
$content = str_replace('.trim', '|trim', $content);
186+
187+
return $content;
188+
}
189+
181190
public function createVariableOutput($varName, ?string $fallbackVariableName = null): string
182191
{
183192
if ($fallbackVariableName) {

0 commit comments

Comments
 (0)