Mercurial > hg > cmmr2012-drupal-site
diff vendor/chi-teck/drupal-code-generator/src/Twig/TwigEnvironment.php @ 4:a9cd425dd02b
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:11:55 +0000 |
parents | c75dbcec494b |
children |
line wrap: on
line diff
--- a/vendor/chi-teck/drupal-code-generator/src/Twig/TwigEnvironment.php Thu Feb 28 11:14:44 2019 +0000 +++ b/vendor/chi-teck/drupal-code-generator/src/Twig/TwigEnvironment.php Thu Feb 28 13:11:55 2019 +0000 @@ -21,18 +21,9 @@ public function __construct(Twig_LoaderInterface $loader) { parent::__construct($loader); - $this->addFilter(new Twig_SimpleFilter('plural', function ($string) { - switch (substr($string, -1)) { - case 'y': - return substr($string, 0, -1) . 'ies'; + $this->addFilter(new Twig_SimpleFilter('plural', [Utils::class, 'pluralize']), ['deprecated' => TRUE]); - case 's': - return $string . 'es'; - - default: - return $string . 's'; - } - })); + $this->addFilter(new Twig_SimpleFilter('pluralize', [Utils::class, 'pluralize'])); $this->addFilter(new Twig_SimpleFilter('article', function ($string) { $article = in_array(strtolower($string[0]), ['a', 'e', 'i', 'o', 'u']) ? 'an' : 'a'; @@ -66,4 +57,22 @@ $this->addTokenParser(new TwigSortTokenParser()); } + /** + * {@inheritdoc} + */ + public function tokenize($source, $name = NULL) { + if (!$source instanceof \Twig_Source) { + $source = new \Twig_Source($source, $name); + } + // Remove leading whitespaces to preserve indentation. + // @see https://github.com/twigphp/Twig/issues/1423 + $code = $source->getCode(); + if (strpos($code, '{% verbatim %}') === FALSE) { + $code = preg_replace("/\n +\{%/", "\n{%", $source->getCode()); + } + // Twig source has no setters. + $source = new \Twig_Source($code, $source->getName(), $source->getPath()); + return parent::tokenize($source, $name); + } + }