mirror of
https://github.com/okdana/twigc.git
synced 2024-05-19 22:06:35 +02:00
Add json escape strategy
This commit is contained in:
parent
dfcf0349ca
commit
281b50438a
|
@ -260,6 +260,9 @@ class DefaultCommand extends Command {
|
||||||
case 'js':
|
case 'js':
|
||||||
$escape = 'js';
|
$escape = 'js';
|
||||||
break;
|
break;
|
||||||
|
case 'json':
|
||||||
|
$escape = 'json';
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
$escape = false;
|
$escape = false;
|
||||||
break;
|
break;
|
||||||
|
@ -409,6 +412,16 @@ class DefaultCommand extends Command {
|
||||||
'autoescape' => $escape,
|
'autoescape' => $escape,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$twig->getExtension('core')->setEscaper(
|
||||||
|
'json',
|
||||||
|
function($twigEnv, $string, $charset) {
|
||||||
|
return json_encode(
|
||||||
|
$string,
|
||||||
|
\JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
$output->writeln(
|
$output->writeln(
|
||||||
rtrim($twig->render(basename($template), $inputData), "\r\n")
|
rtrim($twig->render(basename($template), $inputData), "\r\n")
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue