-
-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
I am really enjoying Pug to Twig, but it doesn't want to create dynamic class names. For instance, if I write
html(lang=site.language)
It will output
<html lang="{{ site.language | e }}">
Which I can then process with twig. However, if I write this:
html(class=site.language)
I'll get this:
<?php $pugModule = [
'Phug\\Formatter\\Format\\TwigHtmlFormat::class_attribute_assignment' => function (&$attributes, $value) use (&$pugModule) {
$split = function ($input) {
return preg_split('/(?<![\[\{\<\=\%])\s+(?![\]\}\>\=\%])/', strval($input));
};
$classes = isset($attributes['class']) ? array_filter($split($attributes['class'])) : [];
foreach ((array) $value as $key => $input) {
if (!is_string($input) && is_string($key)) {
if (!$input) {
continue;
}
$input = $key;
}
foreach ($split($input) as $class) {
if (!in_array($class, $classes, true)) {
$classes[] = $class;
}
}
}
return implode(' ', $classes);
},
'Phug\\Formatter\\Format\\TwigHtmlFormat::stand_alone_class_attribute_assignment' => function ($value) use (&$pugModule) {
$classAttributeAssignment = $pugModule['Phug\\Formatter\\Format\\TwigHtmlFormat::class_attribute_assignment'];
$attributes = [];
return $classAttributeAssignment($attributes, $value);
},
]; ?><!DOCTYPE html><html class="<?= $pugModule['Phug\\Formatter\\Format\\TwigHtmlFormat::stand_alone_class_attribute_assignment'](site.language) | e ?>">
It will always put this PHP at the top of the page, and inline where the class value should be. If I write html(class='home')
it works fine, but if the class value is a variable, it goes haywire.
Metadata
Metadata
Assignees
Labels
No labels