From cc4cf65f95a81c2b3770515623b56f70fcf144e7 Mon Sep 17 00:00:00 2001 From: Dave Olsen Date: Fri, 24 Apr 2015 10:53:54 -0400 Subject: [PATCH 01/29] updating the doc copy --- src/PatternLab/PatternEngine/Twig/TwigUtil.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PatternLab/PatternEngine/Twig/TwigUtil.php b/src/PatternLab/PatternEngine/Twig/TwigUtil.php index b761556..07af945 100644 --- a/src/PatternLab/PatternEngine/Twig/TwigUtil.php +++ b/src/PatternLab/PatternEngine/Twig/TwigUtil.php @@ -1,12 +1,12 @@ Date: Fri, 24 Apr 2015 10:54:14 -0400 Subject: [PATCH 02/29] making the "dir doesn't exist" error more descriptive --- src/PatternLab/PatternEngine/Twig/TwigUtil.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/PatternLab/PatternEngine/Twig/TwigUtil.php b/src/PatternLab/PatternEngine/Twig/TwigUtil.php index 07af945..802f010 100644 --- a/src/PatternLab/PatternEngine/Twig/TwigUtil.php +++ b/src/PatternLab/PatternEngine/Twig/TwigUtil.php @@ -21,10 +21,11 @@ class TwigUtil { /** * Write a warning if a dir doesn't exist * @param {String} the dir that doesn't exist + * @param {String} the type of dir */ - protected static function dirNotExist($dir) { + protected static function dirNotExist($dir, $type) { $dirHR = Console::getHumanReadablePath($dir); - Console::writeWarning("the path ".$dirHR." doesn't exist so filters won't be loaded..."); + Console::writeWarning("the path ".$dirHR." doesn't exist so ".$type." won't be loaded..."); } /** @@ -101,7 +102,7 @@ public static function loadFilters($instance) { } else { - self::dirNotExist($filterDir); + self::dirNotExist($filterDir,"filters"); } @@ -148,7 +149,7 @@ public static function loadFunctions($instance) { } else { - self::dirNotExist($functionDir); + self::dirNotExist($functionDir,"functions"); } @@ -190,7 +191,7 @@ public static function loadMacros($instance) { } else { - self::dirNotExist($macroDir); + self::dirNotExist($macroDir,"macros"); } @@ -235,7 +236,7 @@ public static function loadTags($instance) { } else { - self::dirNotExist($tagDir); + self::dirNotExist($tagDir,"tags"); } @@ -282,7 +283,7 @@ public static function loadTests($instance) { } else { - self::dirNotExist($testDir); + self::dirNotExist($testDir,"tests"); } From 75b392314ff347d75b4d00eb0235c26edddc0fd8 Mon Sep 17 00:00:00 2001 From: Dave Olsen Date: Fri, 24 Apr 2015 10:55:22 -0400 Subject: [PATCH 03/29] no reason to throw this message. it'll get noisy --- .../PatternEngine/Twig/TwigUtil.php | 30 ------------------- 1 file changed, 30 deletions(-) diff --git a/src/PatternLab/PatternEngine/Twig/TwigUtil.php b/src/PatternLab/PatternEngine/Twig/TwigUtil.php index 802f010..305c570 100644 --- a/src/PatternLab/PatternEngine/Twig/TwigUtil.php +++ b/src/PatternLab/PatternEngine/Twig/TwigUtil.php @@ -18,16 +18,6 @@ class TwigUtil { - /** - * Write a warning if a dir doesn't exist - * @param {String} the dir that doesn't exist - * @param {String} the type of dir - */ - protected static function dirNotExist($dir, $type) { - $dirHR = Console::getHumanReadablePath($dir); - Console::writeWarning("the path ".$dirHR." doesn't exist so ".$type." won't be loaded..."); - } - /** * Load custom date formats for Twig * @param {Instance} an instance of the twig engine @@ -100,10 +90,6 @@ public static function loadFilters($instance) { } - } else { - - self::dirNotExist($filterDir,"filters"); - } return $instance; @@ -147,10 +133,6 @@ public static function loadFunctions($instance) { } - } else { - - self::dirNotExist($functionDir,"functions"); - } return $instance; @@ -189,10 +171,6 @@ public static function loadMacros($instance) { } - } else { - - self::dirNotExist($macroDir,"macros"); - } return $instance; @@ -234,10 +212,6 @@ public static function loadTags($instance) { } - } else { - - self::dirNotExist($tagDir,"tags"); - } return $instance; @@ -281,10 +255,6 @@ public static function loadTests($instance) { } - } else { - - self::dirNotExist($testDir,"tests"); - } return $instance; From 2a4b226088044e807afca92e455099d5e2c01a34 Mon Sep 17 00:00:00 2001 From: Dave Olsen Date: Fri, 24 Apr 2015 14:37:46 -0400 Subject: [PATCH 04/29] typo fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 419123b..d670061 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ Twig provides access to two features that may help you extend your patterns, [ma Pattern includes take advantage of the [pattern partial syntax](http://patternlab.io/docs/pattern-including.html) as a shorthand for referencing patterns from across the system without needing to rely on absolute paths. The format: ``` -{% include "[patternType]-[patternName]" }} +{% include "[patternType]-[patternName]" %} ``` For example, let's say we wanted to include the following pattern in a molecule: From aaba74bd07d0cd6297f39dace9216fbb5587ec93 Mon Sep 17 00:00:00 2001 From: TxHawks Date: Thu, 30 Apr 2015 21:18:44 +0300 Subject: [PATCH 05/29] Correct filenames of Twig extensions --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 419123b..52354a6 100644 --- a/README.md +++ b/README.md @@ -148,7 +148,7 @@ The requirements for using filters with Pattern Lab: * The filter **must** set the variable `$filter` * Only one filter per file (_e.g. can only set `$filter` once per file_) -An example function called `rot13.filter.twig` in `source/_twig-components/filters`: +An example function called `rot13.filter.php` in `source/_twig-components/filters`: ```php Date: Tue, 22 Sep 2015 15:01:55 -0400 Subject: [PATCH 06/29] chanigng brack to perc --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 419123b..d670061 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ Twig provides access to two features that may help you extend your patterns, [ma Pattern includes take advantage of the [pattern partial syntax](http://patternlab.io/docs/pattern-including.html) as a shorthand for referencing patterns from across the system without needing to rely on absolute paths. The format: ``` -{% include "[patternType]-[patternName]" }} +{% include "[patternType]-[patternName]" %} ``` For example, let's say we wanted to include the following pattern in a molecule: From 49038addc4bf192111c069007856024dcf8ec4d1 Mon Sep 17 00:00:00 2001 From: Dave Olsen Date: Fri, 4 Dec 2015 10:25:11 -0500 Subject: [PATCH 07/29] updating the regex to support parens in twig partial calls --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index e41cce7..25796b3 100644 --- a/composer.json +++ b/composer.json @@ -30,9 +30,9 @@ }, "extra": { "patternlab": { - "config": { - "lineageMatch": "{%([ ]+)?include ["\\']([A-Za-z0-9-_]+)["\\'](.*)%}", - "lineageMatchKey": 2, + "config": { + "lineageMatch": "{%([ ]+)?include( |\\()["\\']([A-Za-z0-9-_]+)["\\'](\\))?(.*)%}", + "lineageMatchKey": 3, "patternExtension": "twig", "twigDebug": false, "twigDefaultDateFormat": "", @@ -45,4 +45,4 @@ } } } -} \ No newline at end of file +} From d679019270f5ec987a82d7c4a83a46ce5e65f323 Mon Sep 17 00:00:00 2001 From: Aleksi Peebles Date: Thu, 7 Jan 2016 09:52:14 +0000 Subject: [PATCH 08/29] Add source/_patterns subdirectories to $filesystemLoaderPaths --- .../Twig/Loaders/PatternLoader.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php b/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php index 5a5cdbd..97ecfab 100644 --- a/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php +++ b/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php @@ -46,7 +46,22 @@ public function __construct($options = array()) { if (is_dir($layoutsPath)) { $filesystemLoaderPaths[] = $layoutsPath; } - + + // add source/_patterns subdirectories for Drupal theme template compatibility + $patternSourceDir = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_patterns"; + $patternObjects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($patternSourceDir), \RecursiveIteratorIterator::SELF_FIRST); + $patternObjects->setFlags(\FilesystemIterator::SKIP_DOTS); + + // sort the returned objects + $patternObjects = iterator_to_array($patternObjects); + ksort($patternObjects); + + foreach ($patternObjects as $name => $object) { + if ($object->isDir()) { + $filesystemLoaderPaths[] = $object->getPathname(); + } + } + // add the paths to the filesystem loader if the paths existed if (count($filesystemLoaderPaths) > 0) { $loaders[] = new \Twig_Loader_Filesystem($filesystemLoaderPaths); From 4fcf3c18236e4ebd295c715e03330f4f6323b9ee Mon Sep 17 00:00:00 2001 From: Aleksi Peebles Date: Thu, 7 Jan 2016 10:30:20 +0000 Subject: [PATCH 09/29] Add twigAutoescape config setting --- composer.json | 3 ++- src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index dba61d9..2255a1a 100644 --- a/composer.json +++ b/composer.json @@ -35,6 +35,7 @@ "lineageMatchKey": 2, "patternExtension": "twig", "twigDebug": false, + "twigAutoescape": "html", "twigDefaultDateFormat": "", "twigDefaultIntervalFormat": "", "twigMacroExt": "macro.twig", @@ -45,4 +46,4 @@ } } } -} \ No newline at end of file +} diff --git a/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php b/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php index 5a5cdbd..3527921 100644 --- a/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php +++ b/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php @@ -28,6 +28,7 @@ public function __construct($options = array()) { // set-up default vars $twigDebug = Config::getOption("twigDebug"); + $twigAutoescape = Config::getOption("twigAutoescape"); // set-up the loader list $loaders = array(); @@ -56,7 +57,7 @@ public function __construct($options = array()) { // set-up Twig $twigLoader = new \Twig_Loader_Chain($loaders); - $this->instance = new \Twig_Environment($twigLoader, array("debug" => $twigDebug)); + $this->instance = new \Twig_Environment($twigLoader, array("debug" => $twigDebug, "autoescape" => $twigAutoescape)); // customize Twig $this->instance = TwigUtil::loadFilters($this->instance); From b5ed124547944abc7a0d5ad70be2523b60c63934 Mon Sep 17 00:00:00 2001 From: Aleksi Peebles Date: Wed, 13 Jan 2016 14:15:21 +0200 Subject: [PATCH 10/29] Include pattern specific data --- .../PatternEngine/Twig/IncludeNodeVisitor.php | 33 +++++++++++++++ .../Twig/Loaders/PatternLoader.php | 5 ++- .../Twig/PatternDataIncludeNode.php | 40 +++++++++++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 src/PatternLab/PatternEngine/Twig/IncludeNodeVisitor.php create mode 100644 src/PatternLab/PatternEngine/Twig/PatternDataIncludeNode.php diff --git a/src/PatternLab/PatternEngine/Twig/IncludeNodeVisitor.php b/src/PatternLab/PatternEngine/Twig/IncludeNodeVisitor.php new file mode 100644 index 0000000..107af0a --- /dev/null +++ b/src/PatternLab/PatternEngine/Twig/IncludeNodeVisitor.php @@ -0,0 +1,33 @@ +hasNode('expr') && $node->getNode('expr')->hasAttribute('value')) { + $patternStoreKey = $node->getNode('expr')->getAttribute('value'); + $data = Data::getPatternSpecificData($patternStoreKey); + $dataNode = new PatternDataIncludeNode($node, $data); + + return $dataNode; + } + } + + return $node; + } + + public function getPriority() + { + return 0; + } +} diff --git a/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php b/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php index 5a5cdbd..0d75cbe 100644 --- a/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php +++ b/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php @@ -14,6 +14,7 @@ namespace PatternLab\PatternEngine\Twig\Loaders; use \PatternLab\Config; +use \PatternLab\PatternEngine\Twig\IncludeNodeVisitor; use \PatternLab\PatternEngine\Twig\Loaders\Twig\PatternPartialLoader as Twig_Loader_PatternPartialLoader; use \PatternLab\PatternEngine\Twig\Loaders\Twig\PatternStringLoader as Twig_Loader_PatternStringLoader; use \PatternLab\PatternEngine\Loader; @@ -66,7 +67,9 @@ public function __construct($options = array()) { $this->instance = TwigUtil::loadDateFormats($this->instance); $this->instance = TwigUtil::loadDebug($this->instance); $this->instance = TwigUtil::loadMacros($this->instance); - + + // add node visitor + $this->instance->addNodeVisitor(new IncludeNodeVisitor()); } /** diff --git a/src/PatternLab/PatternEngine/Twig/PatternDataIncludeNode.php b/src/PatternLab/PatternEngine/Twig/PatternDataIncludeNode.php new file mode 100644 index 0000000..a79c863 --- /dev/null +++ b/src/PatternLab/PatternEngine/Twig/PatternDataIncludeNode.php @@ -0,0 +1,40 @@ +nodes, $originalNode->attributes, $originalNode->lineno, $originalNode->tag); + $this->data = $data; + } + + protected function addTemplateArguments(\Twig_Compiler $compiler) + { + if (null === $this->getNode('variables')) { + if (false === $this->getAttribute('only')) { + $compiler + ->raw('array_merge($context, ') + ->repr($this->data) + ->raw(')') + ; + } + else { + $compiler->raw('array()'); + } + } elseif (false === $this->getAttribute('only')) { + $compiler + ->raw('array_merge($context, ') + ->repr($this->data) + ->raw(', ') + ->subcompile($this->getNode('variables')) + ->raw(')') + ; + } else { + $compiler->subcompile($this->getNode('variables')); + } + } +} From f90a953d98b7a3dcc5b2b690a6be950fd644e27c Mon Sep 17 00:00:00 2001 From: Dave Olsen Date: Mon, 4 Apr 2016 13:05:31 -0400 Subject: [PATCH 11/29] making sure dev branch pulls dev core --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b7442a4..ae50911 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ }, "require": { "php": ">=5.3.6", - "pattern-lab/core": "0.*", + "pattern-lab/core": "dev-dev", "twig/twig": "1.*" }, "extra": { From 09ca50b1e1e6af22ba937151a2c465360008d3bc Mon Sep 17 00:00:00 2001 From: Jonathan Pollak Date: Mon, 18 Apr 2016 15:31:03 +0300 Subject: [PATCH 12/29] Update template inheritance documentation Indicate that all patterns can be extended, and the specific use-case of extending a pattern from `source/_layouts`. Closes #17 --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1604c3b..5c7f084 100644 --- a/README.md +++ b/README.md @@ -78,9 +78,10 @@ Would be used like this in a pattern: The requirements for using template inheritance with Pattern Lab: -* Files must go in `source/_layouts` +* Files can optionally go in `source/_layouts` in order to hide them from the list of patterns. * Files must have the extension `.twig` -* The filename will be used as the reference in the `extends` tag +* Files can be extended either by using Pattern Lab's normal shorthand syntax (e.g, `{% extends 'templates-extended-layout'%}`), + or, if they are in the `source/_layouts` directory, by using just the filename as reference (e.g., `{% extends 'extended-layout'%}`). An example of a simple layout called `base.twig` in `source/_layouts`: From 94923e90b055ed40443eeb30bf2b77f4ac5c7772 Mon Sep 17 00:00:00 2001 From: Evan Lovely Date: Mon, 18 Apr 2016 12:41:06 -0700 Subject: [PATCH 13/29] Updating Template Inheritance docs --- README.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 5c7f084..9d03ee3 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ The Twig PatternEngine comes pre-installed with the [Pattern Lab Standard Editio Pattern Lab PHP uses [Composer](https://getcomposer.org/) to manage project dependencies with Pattern Lab Editions. To add the Twig PatternEngine to the dependencies list for your Edition you can type the following in the command line at the base of your project: composer require pattern-lab/patternengine-twig - +o See Packagist for [information on the latest release](https://packagist.org/packages/pattern-lab/patternengine-twig). ## Overview @@ -76,12 +76,12 @@ Would be used like this in a pattern: ### Template inheritance -The requirements for using template inheritance with Pattern Lab: +How to use [Template Inheritance](http://twig.sensiolabs.org/doc/templates.html#template-inheritance) with Pattern Lab: -* Files can optionally go in `source/_layouts` in order to hide them from the list of patterns. -* Files must have the extension `.twig` -* Files can be extended either by using Pattern Lab's normal shorthand syntax (e.g, `{% extends 'templates-extended-layout'%}`), - or, if they are in the `source/_layouts` directory, by using just the filename as reference (e.g., `{% extends 'extended-layout'%}`). +* Files must have the extension `.twig`. +* Files can be extended either by using Pattern Lab's normal shorthand syntax (e.g, `{% extends 'templates-extended-layout'%}`). +* Files can optionally go in `source/_layouts` in order to hide them from the list of patterns and then you can just use the filename as reference (e.g., `{% extends 'extended-layout'%}`). +* Files that are in the same directory can also just use the file name without the shorthand syntax (however, it must include the extension). So if `file1.twig` and `file2.twig` were in same directory, you could place this code in `file2.twig`: `{% extends 'file1.twig' %}`. An example of a simple layout called `base.twig` in `source/_layouts`: @@ -125,6 +125,8 @@ Would be used like this in a pattern: {% endblock %} ``` +All uses of `extends` above also work with `includes`, `embed` and most likely many other Twig Tags. Let us know if you run into interesting or unexpected use cases! + ## Extending Twig Further Twig comes with a number of ways to extend the underlying template parser. You can you can add [extra tags](http://twig.sensiolabs.org/doc/advanced.html#tags), [filters](http://twig.sensiolabs.org/doc/advanced.html#filters), [tests](http://twig.sensiolabs.org/doc/advanced.html#tests), and [functions](http://twig.sensiolabs.org/doc/advanced.html#functions). The Twig PatternEngine tries to simplify these extensions by allowing you to create files in specific folders and then auto-load the extensions for you. Learn more about: From 15d09f409174f061bccafe7afd0d136af1965258 Mon Sep 17 00:00:00 2001 From: Evan Lovely Date: Mon, 18 Apr 2016 12:42:39 -0700 Subject: [PATCH 14/29] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9d03ee3..486659f 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ The Twig PatternEngine comes pre-installed with the [Pattern Lab Standard Editio Pattern Lab PHP uses [Composer](https://getcomposer.org/) to manage project dependencies with Pattern Lab Editions. To add the Twig PatternEngine to the dependencies list for your Edition you can type the following in the command line at the base of your project: composer require pattern-lab/patternengine-twig -o + See Packagist for [information on the latest release](https://packagist.org/packages/pattern-lab/patternengine-twig). ## Overview From b890a3a564f2494b3e66728af66aa5b90731ecc0 Mon Sep 17 00:00:00 2001 From: Aleksi Peebles Date: Sun, 24 Apr 2016 18:21:26 +0300 Subject: [PATCH 15/29] Fix broken Twig embed --- .../Twig/Loaders/PatternLoader.php | 4 +- .../Twig/PatternDataEmbedNode.php | 23 +++++++++++ .../Twig/PatternDataIncludeNode.php | 38 +++++-------------- .../Twig/PatternDataNodeTrait.php | 34 +++++++++++++++++ ...Visitor.php => PatternDataNodeVisitor.php} | 9 ++++- 5 files changed, 76 insertions(+), 32 deletions(-) create mode 100644 src/PatternLab/PatternEngine/Twig/PatternDataEmbedNode.php create mode 100644 src/PatternLab/PatternEngine/Twig/PatternDataNodeTrait.php rename src/PatternLab/PatternEngine/Twig/{IncludeNodeVisitor.php => PatternDataNodeVisitor.php} (69%) diff --git a/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php b/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php index 7b7aa64..ba9fb88 100644 --- a/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php +++ b/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php @@ -14,7 +14,7 @@ namespace PatternLab\PatternEngine\Twig\Loaders; use \PatternLab\Config; -use \PatternLab\PatternEngine\Twig\IncludeNodeVisitor; +use \PatternLab\PatternEngine\Twig\PatternDataNodeVisitor; use \PatternLab\PatternEngine\Twig\Loaders\Twig\PatternPartialLoader as Twig_Loader_PatternPartialLoader; use \PatternLab\PatternEngine\Twig\Loaders\Twig\PatternStringLoader as Twig_Loader_PatternStringLoader; use \PatternLab\PatternEngine\Loader; @@ -85,7 +85,7 @@ public function __construct($options = array()) { $this->instance = TwigUtil::loadMacros($this->instance); // add node visitor - $this->instance->addNodeVisitor(new IncludeNodeVisitor()); + $this->instance->addNodeVisitor(new PatternDataNodeVisitor()); } /** diff --git a/src/PatternLab/PatternEngine/Twig/PatternDataEmbedNode.php b/src/PatternLab/PatternEngine/Twig/PatternDataEmbedNode.php new file mode 100644 index 0000000..719b29b --- /dev/null +++ b/src/PatternLab/PatternEngine/Twig/PatternDataEmbedNode.php @@ -0,0 +1,23 @@ +getAttribute('filename'), + $originalNode->getAttribute('index'), + $originalNode->getNode('variables'), + $originalNode->getAttribute('only'), + $originalNode->getAttribute('ignore_missing'), + $originalNode->getLine(), + $originalNode->getNodeTag() + ); + + $this->data = $data; + } +} diff --git a/src/PatternLab/PatternEngine/Twig/PatternDataIncludeNode.php b/src/PatternLab/PatternEngine/Twig/PatternDataIncludeNode.php index a79c863..275ec04 100644 --- a/src/PatternLab/PatternEngine/Twig/PatternDataIncludeNode.php +++ b/src/PatternLab/PatternEngine/Twig/PatternDataIncludeNode.php @@ -4,37 +4,19 @@ class PatternDataIncludeNode extends \Twig_Node_Include { - protected $data; + use PatternDataNodeTrait; public function __construct(\Twig_Node_Include $originalNode, $data) { - \Twig_Node::__construct($originalNode->nodes, $originalNode->attributes, $originalNode->lineno, $originalNode->tag); - $this->data = $data; - } + parent::__construct( + $originalNode->getNode('expr'), + $originalNode->getNode('variables'), + $originalNode->getAttribute('only'), + $originalNode->getAttribute('ignore_missing'), + $originalNode->getLine(), + $originalNode->getNodeTag() + ); - protected function addTemplateArguments(\Twig_Compiler $compiler) - { - if (null === $this->getNode('variables')) { - if (false === $this->getAttribute('only')) { - $compiler - ->raw('array_merge($context, ') - ->repr($this->data) - ->raw(')') - ; - } - else { - $compiler->raw('array()'); - } - } elseif (false === $this->getAttribute('only')) { - $compiler - ->raw('array_merge($context, ') - ->repr($this->data) - ->raw(', ') - ->subcompile($this->getNode('variables')) - ->raw(')') - ; - } else { - $compiler->subcompile($this->getNode('variables')); - } + $this->data = $data; } } diff --git a/src/PatternLab/PatternEngine/Twig/PatternDataNodeTrait.php b/src/PatternLab/PatternEngine/Twig/PatternDataNodeTrait.php new file mode 100644 index 0000000..9369cfb --- /dev/null +++ b/src/PatternLab/PatternEngine/Twig/PatternDataNodeTrait.php @@ -0,0 +1,34 @@ +getNode('variables')) { + if (false === $this->getAttribute('only')) { + $compiler + ->raw('array_merge($context, ') + ->repr($this->data) + ->raw(')') + ; + } + else { + $compiler->raw('array()'); + } + } elseif (false === $this->getAttribute('only')) { + $compiler + ->raw('array_merge($context, ') + ->repr($this->data) + ->raw(', ') + ->subcompile($this->getNode('variables')) + ->raw(')') + ; + } else { + $compiler->subcompile($this->getNode('variables')); + } + } +} diff --git a/src/PatternLab/PatternEngine/Twig/IncludeNodeVisitor.php b/src/PatternLab/PatternEngine/Twig/PatternDataNodeVisitor.php similarity index 69% rename from src/PatternLab/PatternEngine/Twig/IncludeNodeVisitor.php rename to src/PatternLab/PatternEngine/Twig/PatternDataNodeVisitor.php index 107af0a..ac78b08 100644 --- a/src/PatternLab/PatternEngine/Twig/IncludeNodeVisitor.php +++ b/src/PatternLab/PatternEngine/Twig/PatternDataNodeVisitor.php @@ -4,7 +4,7 @@ use PatternLab\Data; -class IncludeNodeVisitor extends \Twig_BaseNodeVisitor +class PatternDataNodeVisitor extends \Twig_BaseNodeVisitor { protected function doEnterNode(\Twig_Node $node, \Twig_Environment $env) { @@ -17,7 +17,12 @@ protected function doLeaveNode(\Twig_Node $node, \Twig_Environment $env) if ($node->hasNode('expr') && $node->getNode('expr')->hasAttribute('value')) { $patternStoreKey = $node->getNode('expr')->getAttribute('value'); $data = Data::getPatternSpecificData($patternStoreKey); - $dataNode = new PatternDataIncludeNode($node, $data); + if ($node instanceof \Twig_Node_Embed) { + $dataNode = new PatternDataEmbedNode($node, $data); + } + else { + $dataNode = new PatternDataIncludeNode($node, $data); + } return $dataNode; } From 3888ca27d400f756776900ffa464e929e6da36cf Mon Sep 17 00:00:00 2001 From: Dave Olsen Date: Tue, 3 May 2016 21:23:40 -0400 Subject: [PATCH 16/29] fixing some space issues --- .../Twig/Loaders/PatternLoader.php | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php b/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php index ba9fb88..6a60c34 100644 --- a/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php +++ b/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php @@ -66,23 +66,23 @@ public function __construct($options = array()) { // add the paths to the filesystem loader if the paths existed if (count($filesystemLoaderPaths) > 0) { - $loaders[] = new \Twig_Loader_Filesystem($filesystemLoaderPaths); + $loaders[] = new \Twig_Loader_Filesystem($filesystemLoaderPaths); } - $loaders[] = new \Twig_Loader_String(); + $loaders[] = new \Twig_Loader_String(); // set-up Twig - $twigLoader = new \Twig_Loader_Chain($loaders); - $this->instance = new \Twig_Environment($twigLoader, array("debug" => $twigDebug, "autoescape" => $twigAutoescape)); + $twigLoader = new \Twig_Loader_Chain($loaders); + $this->instance = new \Twig_Environment($twigLoader, array("debug" => $twigDebug, "autoescape" => $twigAutoescape)); // customize Twig - $this->instance = TwigUtil::loadFilters($this->instance); - $this->instance = TwigUtil::loadFunctions($this->instance); - $this->instance = TwigUtil::loadTags($this->instance); - $this->instance = TwigUtil::loadTests($this->instance); - $this->instance = TwigUtil::loadDateFormats($this->instance); - $this->instance = TwigUtil::loadDebug($this->instance); - $this->instance = TwigUtil::loadMacros($this->instance); + $this->instance = TwigUtil::loadFilters($this->instance); + $this->instance = TwigUtil::loadFunctions($this->instance); + $this->instance = TwigUtil::loadTags($this->instance); + $this->instance = TwigUtil::loadTests($this->instance); + $this->instance = TwigUtil::loadDateFormats($this->instance); + $this->instance = TwigUtil::loadDebug($this->instance); + $this->instance = TwigUtil::loadMacros($this->instance); // add node visitor $this->instance->addNodeVisitor(new PatternDataNodeVisitor()); From 76d4440201e6cde0716dcb39f792df57d4e2bd6e Mon Sep 17 00:00:00 2001 From: Dave Olsen Date: Tue, 3 May 2016 21:39:06 -0400 Subject: [PATCH 17/29] adding addPaths support --- .../Twig/Loaders/PatternLoader.php | 3 ++- .../PatternEngine/Twig/TwigUtil.php | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php b/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php index 6a60c34..1c715c3 100644 --- a/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php +++ b/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php @@ -66,7 +66,8 @@ public function __construct($options = array()) { // add the paths to the filesystem loader if the paths existed if (count($filesystemLoaderPaths) > 0) { - $loaders[] = new \Twig_Loader_Filesystem($filesystemLoaderPaths); + $filesystemLoader = new \Twig_Loader_Filesystem($filesystemLoaderPaths); + $loaders[] = TwigUtil::addPaths($filesystemLoader, $patternSourceDir); } $loaders[] = new \Twig_Loader_String(); diff --git a/src/PatternLab/PatternEngine/Twig/TwigUtil.php b/src/PatternLab/PatternEngine/Twig/TwigUtil.php index 305c570..0293216 100644 --- a/src/PatternLab/PatternEngine/Twig/TwigUtil.php +++ b/src/PatternLab/PatternEngine/Twig/TwigUtil.php @@ -18,6 +18,26 @@ class TwigUtil { + /** + * Registering each directory under `_patterns/` as a namespace. For example, `_patterns/00-atoms/` as `@atoms` + * @param {Instance} an instance of the filesystem Loader + * @param {String} the path to the pattern directory + * + * @return {Instance} an instance of the filesystem Loader + */ + public static function addPaths($filesystemLoader, $patternSourceDir) { + + $finder = new Finder(); + $finder->directories()->depth(0)->in($patternSourceDir); + foreach ($finder as $file) { + $patternBits = explode("-",$file->getRelativePathName(),2); + $patternTypePath = (((int)$patternBits[0] != 0) || ($patternBits[0] == '00')) ? $patternBits[1] : $pattern; + $filesystemLoader->addPath($file->getPathName(), $patternTypePath); + } + + return $filesystemLoader; + + } /** * Load custom date formats for Twig * @param {Instance} an instance of the twig engine From 36242077104a0187deea0c00d18fef12861421bc Mon Sep 17 00:00:00 2001 From: Dave Olsen Date: Tue, 3 May 2016 22:13:27 -0400 Subject: [PATCH 18/29] making sure composer.json is pulling core properly --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ae50911..b7442a4 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ }, "require": { "php": ">=5.3.6", - "pattern-lab/core": "dev-dev", + "pattern-lab/core": "0.*", "twig/twig": "1.*" }, "extra": { From 0f711e828690e010db9e918dbc37244c8690406c Mon Sep 17 00:00:00 2001 From: Dave Olsen Date: Wed, 4 May 2016 16:42:24 -0400 Subject: [PATCH 19/29] adding a getter setter for an instance. Updating methods as appropriate --- .../PatternEngine/Twig/TwigUtil.php | 95 +++++++++---------- 1 file changed, 46 insertions(+), 49 deletions(-) diff --git a/src/PatternLab/PatternEngine/Twig/TwigUtil.php b/src/PatternLab/PatternEngine/Twig/TwigUtil.php index 0293216..021ad9f 100644 --- a/src/PatternLab/PatternEngine/Twig/TwigUtil.php +++ b/src/PatternLab/PatternEngine/Twig/TwigUtil.php @@ -18,6 +18,37 @@ class TwigUtil { + protected $instance = ''; + + /** + * Get an instance of the Twig environment + * + * @return {Instance} an instance of the Twig environment + */ + public static function getInstance() { + + if (empty($this->instance)) { + return false; + } + + return $this->instance; + + } + + /** + * Set an instance of the Twig environment + * @param {Instance} an instance of the Twig environment + */ + public static function setInstance($instance = "") { + + if (empty($instance) || !method_exists($instance,'addGlobal')) { + Console::writeError("please set the instance"); + } + + $this->instance = $instance; + + } + /** * Registering each directory under `_patterns/` as a namespace. For example, `_patterns/00-atoms/` as `@atoms` * @param {Instance} an instance of the filesystem Loader @@ -38,48 +69,36 @@ public static function addPaths($filesystemLoader, $patternSourceDir) { return $filesystemLoader; } + /** * Load custom date formats for Twig - * @param {Instance} an instance of the twig engine - * - * @return {Instance} an instance of the twig engine */ - public static function loadDateFormats($instance) { + public static function loadDateFormats() { $dateFormat = Config::getOption("twigDefaultDateFormat"); $intervalFormat = Config::getOption("twigDefaultIntervalFormat"); if ($dateFormat && $intervalFormat && !empty($dateFormat) && !empty($intervalFormat)) { - $instance->getExtension("core")->setDateFormat($dateFormat, $intervalFormat); + $this->instance->getExtension("core")->setDateFormat($dateFormat, $intervalFormat); } - return $instance; - } /** * Enable the debug options for Twig - * @param {Instance} an instance of the twig engine - * - * @return {Instance} an instance of the twig engine */ - public static function loadDebug($instance) { + public static function loadDebug() { if (Config::getOption("twigDebug")) { - $instance->addExtension(new \Twig_Extension_Debug()); + $this->instance->addExtension(new \Twig_Extension_Debug()); } - return $instance; - } /** * Load filters for the Twig PatternEngine - * @param {Instance} an instance of the twig engine - * - * @return {Instance} an instance of the twig engine */ - public static function loadFilters($instance) { + public static function loadFilters() { // load defaults $filterDir = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_twig-components/filters"; @@ -102,7 +121,7 @@ public static function loadFilters($instance) { // $filter should be defined in the included file if (isset($filter)) { - $instance->addFilter($filter); + $this->instance->addFilter($filter); unset($filter); } @@ -112,17 +131,12 @@ public static function loadFilters($instance) { } - return $instance; - } /** * Load functions for the Twig PatternEngine - * @param {Instance} an instance of the twig engine - * - * @return {Instance} an instance of the twig engine */ - public static function loadFunctions($instance) { + public static function loadFunctions() { // load defaults $functionDir = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_twig-components/functions"; @@ -145,7 +159,7 @@ public static function loadFunctions($instance) { // $function should be defined in the included file if (isset($function)) { - $instance->addFunction($function); + $this->instance->addFunction($function); unset($function); } @@ -155,17 +169,12 @@ public static function loadFunctions($instance) { } - return $instance; - } /** * Load macros for the Twig PatternEngine - * @param {Instance} an instance of the twig engine - * - * @return {Instance} an instance of the twig engine */ - public static function loadMacros($instance) { + public static function loadMacros() { // load defaults $macroDir = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_macros"; @@ -185,7 +194,7 @@ public static function loadMacros($instance) { if ($baseName[0] != "_") { // add the macro to the global context - $instance->addGlobal($file->getBasename(".".$macroExt), $instance->loadTemplate($baseName)); + $this->instance->addGlobal($file->getBasename(".".$macroExt), $this->instance->loadTemplate($baseName)); } @@ -193,17 +202,12 @@ public static function loadMacros($instance) { } - return $instance; - } /** * Load tags for the Twig PatternEngine - * @param {Instance} an instance of the twig engine - * - * @return {Instance} an instance of the twig engine */ - public static function loadTags($instance) { + public static function loadTags() { // load defaults $tagDir = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_twig-components/tags"; @@ -226,7 +230,7 @@ public static function loadTags($instance) { // Project_{filenameBase}_TokenParser should be defined in the include $className = "Project_".$file->getBasename(".".$tagExt)."_TokenParser"; - $instance->addTokenParser(new $className()); + $this->instance->addTokenParser(new $className()); } @@ -234,17 +238,12 @@ public static function loadTags($instance) { } - return $instance; - } /** * Load functions for the Twig PatternEngine - * @param {Instance} an instance of the twig engine - * - * @return {Instance} an instance of the twig engine */ - public static function loadTests($instance) { + public static function loadTests() { // load defaults $testDir = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_twig-components/tests"; @@ -267,7 +266,7 @@ public static function loadTests($instance) { // $test should be defined in the included file if (isset($test)) { - $instance->addTest($test); + $this->instance->addTest($test); unset($test); } @@ -277,8 +276,6 @@ public static function loadTests($instance) { } - return $instance; - } } From 8bb058500b8f5d127765bd2c8a5a52eef6f0f0df Mon Sep 17 00:00:00 2001 From: Dave Olsen Date: Wed, 4 May 2016 22:20:57 -0400 Subject: [PATCH 20/29] support for events and what not --- .../Twig/Loaders/FilesystemLoader.php | 44 +++++++++------- .../Twig/Loaders/PatternLoader.php | 51 +++++++++++-------- .../Twig/Loaders/StringLoader.php | 46 ++++++++++------- .../PatternEngine/Twig/TwigUtil.php | 32 ++++++++---- 4 files changed, 106 insertions(+), 67 deletions(-) diff --git a/src/PatternLab/PatternEngine/Twig/Loaders/FilesystemLoader.php b/src/PatternLab/PatternEngine/Twig/Loaders/FilesystemLoader.php index cbae30a..2e91411 100644 --- a/src/PatternLab/PatternEngine/Twig/Loaders/FilesystemLoader.php +++ b/src/PatternLab/PatternEngine/Twig/Loaders/FilesystemLoader.php @@ -13,6 +13,7 @@ namespace PatternLab\PatternEngine\Twig\Loaders; use \PatternLab\Config; +use \PatternLab\Dispatcher; use \PatternLab\PatternEngine\Loader; use \PatternLab\PatternEngine\Twig\TwigUtil; @@ -24,37 +25,46 @@ class FilesystemLoader extends Loader { public function __construct($options = array()) { // set-up default vars - $twigDebug = Config::getOption("twigDebug"); + $twigDebug = Config::getOption("twigDebug"); // set-up the paths to be searched for templates - $dirPaths = array(); - $dirPaths[] = $options["templatePath"]; - $dirPaths[] = $options["partialsPath"]; + $filesystemLoaderPaths = array(); + $filesystemLoaderPaths[] = $options["templatePath"]; + $filesystemLoaderPaths[] = $options["partialsPath"]; // see if source/_macros exists. if so add it to be searchable - $macrosPath = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_macros"; + $macrosPath = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_macros"; if (is_dir($macrosPath)) { - $dirPaths[] = $macrosPath; + $filesystemLoaderPaths[] = $macrosPath; } // see if source/_layouts exists. if so add it to be searchable - $layoutsPath = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_layouts"; + $layoutsPath = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_layouts"; if (is_dir($layoutsPath)) { - $dirPaths[] = $layoutsPath; + $filesystemLoaderPaths[] = $layoutsPath; } // set-up Twig - $twigLoader = new \Twig_Loader_Filesystem($dirPaths); - $this->instance = new \Twig_Environment($twigLoader, array("debug" => $twigDebug)); + $twigLoader = new \Twig_Loader_Filesystem($filesystemLoaderPaths); + $instance = new \Twig_Environment($twigLoader, array("debug" => $twigDebug)); // customize Twig - $this->instance = TwigUtil::loadFilters($this->instance); - $this->instance = TwigUtil::loadFunctions($this->instance); - $this->instance = TwigUtil::loadTags($this->instance); - $this->instance = TwigUtil::loadTests($this->instance); - $this->instance = TwigUtil::loadDateFormats($this->instance); - $this->instance = TwigUtil::loadDebug($this->instance); - $this->instance = TwigUtil::loadMacros($this->instance); + TwigUtil::setInstance($instance); + TwigUtil::loadFilters(); + TwigUtil::loadFunctions(); + TwigUtil::loadTags(); + TwigUtil::loadTests(); + TwigUtil::loadDateFormats(); + TwigUtil::loadDebug(); + TwigUtil::loadMacros(); + + // set-up the dispatcher + $dispatcherInstance = Dispatcher::getInstance(); + $dispatcherInstance->dispatch("twigLoader.customize"); + $dispatcherInstance->dispatch("twigFilesystemLoader.customize"); + + // add node visitor + $this->instance = TwigUtil::getInstance(); } diff --git a/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php b/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php index 1c715c3..ae28556 100644 --- a/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php +++ b/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php @@ -14,7 +14,7 @@ namespace PatternLab\PatternEngine\Twig\Loaders; use \PatternLab\Config; -use \PatternLab\PatternEngine\Twig\PatternDataNodeVisitor; +use \PatternLab\Dispatcher; use \PatternLab\PatternEngine\Twig\Loaders\Twig\PatternPartialLoader as Twig_Loader_PatternPartialLoader; use \PatternLab\PatternEngine\Twig\Loaders\Twig\PatternStringLoader as Twig_Loader_PatternStringLoader; use \PatternLab\PatternEngine\Loader; @@ -28,23 +28,20 @@ class PatternLoader extends Loader { public function __construct($options = array()) { // set-up default vars - $twigDebug = Config::getOption("twigDebug"); - $twigAutoescape = Config::getOption("twigAutoescape"); + $twigDebug = Config::getOption("twigDebug"); + $twigAutoescape = Config::getOption("twigAutoescape"); - // set-up the loader list - $loaders = array(); + // go through various places where things can exist $filesystemLoaderPaths = array(); - $loaders[] = new Twig_Loader_PatternPartialLoader(Config::getOption("patternSourceDir"),array("patternPaths" => $options["patternPaths"])); - // see if source/_macros exists - $macrosPath = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_macros"; + $macrosPath = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_macros"; if (is_dir($macrosPath)) { $filesystemLoaderPaths[] = $macrosPath; } // see if source/_layouts exists. if so add it to be searchable - $layoutsPath = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_layouts"; + $layoutsPath = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_layouts"; if (is_dir($layoutsPath)) { $filesystemLoaderPaths[] = $layoutsPath; } @@ -63,30 +60,42 @@ public function __construct($options = array()) { $filesystemLoaderPaths[] = $object->getPathname(); } } + + // set-up the loader list in order that they should be checked + // 1. Patterns 2. Filesystem 3. String + $loaders = array(); + $loaders[] = new Twig_Loader_PatternPartialLoader(Config::getOption("patternSourceDir"),array("patternPaths" => $options["patternPaths"])); // add the paths to the filesystem loader if the paths existed if (count($filesystemLoaderPaths) > 0) { $filesystemLoader = new \Twig_Loader_Filesystem($filesystemLoaderPaths); $loaders[] = TwigUtil::addPaths($filesystemLoader, $patternSourceDir); } - - $loaders[] = new \Twig_Loader_String(); + $loaders[] = new \Twig_Loader_String(); // set-up Twig - $twigLoader = new \Twig_Loader_Chain($loaders); - $this->instance = new \Twig_Environment($twigLoader, array("debug" => $twigDebug, "autoescape" => $twigAutoescape)); + $twigLoader = new \Twig_Loader_Chain($loaders); + $instance = new \Twig_Environment($twigLoader, array("debug" => $twigDebug, "autoescape" => $twigAutoescape)); // customize Twig - $this->instance = TwigUtil::loadFilters($this->instance); - $this->instance = TwigUtil::loadFunctions($this->instance); - $this->instance = TwigUtil::loadTags($this->instance); - $this->instance = TwigUtil::loadTests($this->instance); - $this->instance = TwigUtil::loadDateFormats($this->instance); - $this->instance = TwigUtil::loadDebug($this->instance); - $this->instance = TwigUtil::loadMacros($this->instance); + TwigUtil::setInstance($instance); + TwigUtil::loadFilters(); + TwigUtil::loadFunctions(); + TwigUtil::loadTags(); + TwigUtil::loadTests(); + TwigUtil::loadDateFormats(); + TwigUtil::loadDebug(); + TwigUtil::loadMacros(); + TwigUtil::addNodeVisitor(); + + // set-up the dispatcher + $dispatcherInstance = Dispatcher::getInstance(); + $dispatcherInstance->dispatch("twigLoader.customize"); + $dispatcherInstance->dispatch("twigPatternLoader.customize"); // add node visitor - $this->instance->addNodeVisitor(new PatternDataNodeVisitor()); + $this->instance = TwigUtil::getInstance(); + } /** diff --git a/src/PatternLab/PatternEngine/Twig/Loaders/StringLoader.php b/src/PatternLab/PatternEngine/Twig/Loaders/StringLoader.php index b22b491..955b17d 100644 --- a/src/PatternLab/PatternEngine/Twig/Loaders/StringLoader.php +++ b/src/PatternLab/PatternEngine/Twig/Loaders/StringLoader.php @@ -13,6 +13,7 @@ namespace PatternLab\PatternEngine\Twig\Loaders; use \PatternLab\Config; +use \PatternLab\Dispatcher; use \PatternLab\PatternEngine\Loader; use \PatternLab\PatternEngine\Twig\TwigUtil; @@ -24,43 +25,52 @@ class StringLoader extends Loader { public function __construct($options = array()) { // set-up the defaults - $twigDebug = Config::getOption("twigDebug"); + $twigDebug = Config::getOption("twigDebug"); - // set-up the loader list - $loaders = array(); + // go through various places where things can exist $filesystemLoaderPaths = array(); // see if source/_macros exists - $macrosPath = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_macros"; + $macrosPath = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_macros"; if (is_dir($macrosPath)) { $filesystemLoaderPaths[] = $macrosPath; } // see if source/_layouts exists. if so add it to be searchable - $layoutsPath = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_layouts"; + $layoutsPath = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_layouts"; if (is_dir($layoutsPath)) { $filesystemLoaderPaths[] = $layoutsPath; } + // set-up the loader list + $loaders = array(); // add the paths to the filesystem loader if the paths existed if (count($filesystemLoaderPaths) > 0) { - $loaders[] = new \Twig_Loader_Filesystem($filesystemLoaderPaths); + $loaders[] = new \Twig_Loader_Filesystem($filesystemLoaderPaths); } - - $loaders[] = new \Twig_Loader_String(); + $loaders[] = new \Twig_Loader_String(); // set-up Twig - $twigLoader = new \Twig_Loader_Chain($loaders); - $this->instance = new \Twig_Environment($twigLoader, array("debug" => $twigDebug)); + $twigLoader = new \Twig_Loader_Chain($loaders); + $instance = new \Twig_Environment($twigLoader, array("debug" => $twigDebug)); - // customize the loader - $this->instance = TwigUtil::loadFilters($this->instance); - $this->instance = TwigUtil::loadFunctions($this->instance); - $this->instance = TwigUtil::loadTags($this->instance); - $this->instance = TwigUtil::loadTests($this->instance); - $this->instance = TwigUtil::loadDateFormats($this->instance); - $this->instance = TwigUtil::loadDebug($this->instance); - $this->instance = TwigUtil::loadMacros($this->instance); + // customize Twig + TwigUtil::setInstance($instance); + TwigUtil::loadFilters(); + TwigUtil::loadFunctions(); + TwigUtil::loadTags(); + TwigUtil::loadTests(); + TwigUtil::loadDateFormats(); + TwigUtil::loadDebug(); + TwigUtil::loadMacros(); + + // set-up the dispatcher + $dispatcherInstance = Dispatcher::getInstance(); + $dispatcherInstance->dispatch("twigLoader.customize"); + $dispatcherInstance->dispatch("twigStringLoader.customize"); + + // add node visitor + $this->instance = TwigUtil::getInstance(); } diff --git a/src/PatternLab/PatternEngine/Twig/TwigUtil.php b/src/PatternLab/PatternEngine/Twig/TwigUtil.php index 021ad9f..98a2991 100644 --- a/src/PatternLab/PatternEngine/Twig/TwigUtil.php +++ b/src/PatternLab/PatternEngine/Twig/TwigUtil.php @@ -14,11 +14,12 @@ use \PatternLab\Config; use \PatternLab\Console; +use \PatternLab\PatternEngine\Twig\PatternDataNodeVisitor; use \Symfony\Component\Finder\Finder; class TwigUtil { - protected $instance = ''; + protected static $instance = ''; /** * Get an instance of the Twig environment @@ -27,11 +28,11 @@ class TwigUtil { */ public static function getInstance() { - if (empty($this->instance)) { + if (empty(self::$instance)) { return false; } - return $this->instance; + return self::$instance; } @@ -45,7 +46,16 @@ public static function setInstance($instance = "") { Console::writeError("please set the instance"); } - $this->instance = $instance; + self::$instance = $instance; + + } + + /** + * Adds a node visitor + */ + public static function addNodeVisitor() { + + self::$instance->addNodeVisitor(new PatternDataNodeVisitor()); } @@ -79,7 +89,7 @@ public static function loadDateFormats() { $intervalFormat = Config::getOption("twigDefaultIntervalFormat"); if ($dateFormat && $intervalFormat && !empty($dateFormat) && !empty($intervalFormat)) { - $this->instance->getExtension("core")->setDateFormat($dateFormat, $intervalFormat); + self::$instance->getExtension("core")->setDateFormat($dateFormat, $intervalFormat); } } @@ -90,7 +100,7 @@ public static function loadDateFormats() { public static function loadDebug() { if (Config::getOption("twigDebug")) { - $this->instance->addExtension(new \Twig_Extension_Debug()); + self::$instance->addExtension(new \Twig_Extension_Debug()); } } @@ -121,7 +131,7 @@ public static function loadFilters() { // $filter should be defined in the included file if (isset($filter)) { - $this->instance->addFilter($filter); + self::$instance->addFilter($filter); unset($filter); } @@ -159,7 +169,7 @@ public static function loadFunctions() { // $function should be defined in the included file if (isset($function)) { - $this->instance->addFunction($function); + self::$instance->addFunction($function); unset($function); } @@ -194,7 +204,7 @@ public static function loadMacros() { if ($baseName[0] != "_") { // add the macro to the global context - $this->instance->addGlobal($file->getBasename(".".$macroExt), $this->instance->loadTemplate($baseName)); + self::$instance->addGlobal($file->getBasename(".".$macroExt), self::$instance->loadTemplate($baseName)); } @@ -230,7 +240,7 @@ public static function loadTags() { // Project_{filenameBase}_TokenParser should be defined in the include $className = "Project_".$file->getBasename(".".$tagExt)."_TokenParser"; - $this->instance->addTokenParser(new $className()); + self::$instance->addTokenParser(new $className()); } @@ -266,7 +276,7 @@ public static function loadTests() { // $test should be defined in the included file if (isset($test)) { - $this->instance->addTest($test); + self::$instance->addTest($test); unset($test); } From 6d284c8ccefd6b6873fa92fadcce986d274a03c9 Mon Sep 17 00:00:00 2001 From: Dave Olsen Date: Thu, 5 May 2016 21:13:55 -0400 Subject: [PATCH 21/29] updating a comment --- src/PatternLab/PatternEngine/Twig/Loaders/FilesystemLoader.php | 2 +- src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php | 2 +- src/PatternLab/PatternEngine/Twig/Loaders/StringLoader.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PatternLab/PatternEngine/Twig/Loaders/FilesystemLoader.php b/src/PatternLab/PatternEngine/Twig/Loaders/FilesystemLoader.php index 2e91411..38f99bd 100644 --- a/src/PatternLab/PatternEngine/Twig/Loaders/FilesystemLoader.php +++ b/src/PatternLab/PatternEngine/Twig/Loaders/FilesystemLoader.php @@ -63,7 +63,7 @@ public function __construct($options = array()) { $dispatcherInstance->dispatch("twigLoader.customize"); $dispatcherInstance->dispatch("twigFilesystemLoader.customize"); - // add node visitor + // get the instance $this->instance = TwigUtil::getInstance(); } diff --git a/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php b/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php index ae28556..11333d0 100644 --- a/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php +++ b/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php @@ -93,7 +93,7 @@ public function __construct($options = array()) { $dispatcherInstance->dispatch("twigLoader.customize"); $dispatcherInstance->dispatch("twigPatternLoader.customize"); - // add node visitor + // get the instance $this->instance = TwigUtil::getInstance(); } diff --git a/src/PatternLab/PatternEngine/Twig/Loaders/StringLoader.php b/src/PatternLab/PatternEngine/Twig/Loaders/StringLoader.php index 955b17d..e81c9b7 100644 --- a/src/PatternLab/PatternEngine/Twig/Loaders/StringLoader.php +++ b/src/PatternLab/PatternEngine/Twig/Loaders/StringLoader.php @@ -69,7 +69,7 @@ public function __construct($options = array()) { $dispatcherInstance->dispatch("twigLoader.customize"); $dispatcherInstance->dispatch("twigStringLoader.customize"); - // add node visitor + // get the instance $this->instance = TwigUtil::getInstance(); } From a97d76ce38c50b3f0d1c6580ef7e11bec4476030 Mon Sep 17 00:00:00 2001 From: Dave Olsen Date: Thu, 5 May 2016 21:18:23 -0400 Subject: [PATCH 22/29] removing node visitor --- .../Twig/Loaders/PatternLoader.php | 1 - .../Twig/PatternDataEmbedNode.php | 23 ----------- .../Twig/PatternDataIncludeNode.php | 22 ----------- .../Twig/PatternDataNodeTrait.php | 34 ----------------- .../Twig/PatternDataNodeVisitor.php | 38 ------------------- .../PatternEngine/Twig/TwigUtil.php | 10 ----- 6 files changed, 128 deletions(-) delete mode 100644 src/PatternLab/PatternEngine/Twig/PatternDataEmbedNode.php delete mode 100644 src/PatternLab/PatternEngine/Twig/PatternDataIncludeNode.php delete mode 100644 src/PatternLab/PatternEngine/Twig/PatternDataNodeTrait.php delete mode 100644 src/PatternLab/PatternEngine/Twig/PatternDataNodeVisitor.php diff --git a/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php b/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php index 11333d0..3d01683 100644 --- a/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php +++ b/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php @@ -86,7 +86,6 @@ public function __construct($options = array()) { TwigUtil::loadDateFormats(); TwigUtil::loadDebug(); TwigUtil::loadMacros(); - TwigUtil::addNodeVisitor(); // set-up the dispatcher $dispatcherInstance = Dispatcher::getInstance(); diff --git a/src/PatternLab/PatternEngine/Twig/PatternDataEmbedNode.php b/src/PatternLab/PatternEngine/Twig/PatternDataEmbedNode.php deleted file mode 100644 index 719b29b..0000000 --- a/src/PatternLab/PatternEngine/Twig/PatternDataEmbedNode.php +++ /dev/null @@ -1,23 +0,0 @@ -getAttribute('filename'), - $originalNode->getAttribute('index'), - $originalNode->getNode('variables'), - $originalNode->getAttribute('only'), - $originalNode->getAttribute('ignore_missing'), - $originalNode->getLine(), - $originalNode->getNodeTag() - ); - - $this->data = $data; - } -} diff --git a/src/PatternLab/PatternEngine/Twig/PatternDataIncludeNode.php b/src/PatternLab/PatternEngine/Twig/PatternDataIncludeNode.php deleted file mode 100644 index 275ec04..0000000 --- a/src/PatternLab/PatternEngine/Twig/PatternDataIncludeNode.php +++ /dev/null @@ -1,22 +0,0 @@ -getNode('expr'), - $originalNode->getNode('variables'), - $originalNode->getAttribute('only'), - $originalNode->getAttribute('ignore_missing'), - $originalNode->getLine(), - $originalNode->getNodeTag() - ); - - $this->data = $data; - } -} diff --git a/src/PatternLab/PatternEngine/Twig/PatternDataNodeTrait.php b/src/PatternLab/PatternEngine/Twig/PatternDataNodeTrait.php deleted file mode 100644 index 9369cfb..0000000 --- a/src/PatternLab/PatternEngine/Twig/PatternDataNodeTrait.php +++ /dev/null @@ -1,34 +0,0 @@ -getNode('variables')) { - if (false === $this->getAttribute('only')) { - $compiler - ->raw('array_merge($context, ') - ->repr($this->data) - ->raw(')') - ; - } - else { - $compiler->raw('array()'); - } - } elseif (false === $this->getAttribute('only')) { - $compiler - ->raw('array_merge($context, ') - ->repr($this->data) - ->raw(', ') - ->subcompile($this->getNode('variables')) - ->raw(')') - ; - } else { - $compiler->subcompile($this->getNode('variables')); - } - } -} diff --git a/src/PatternLab/PatternEngine/Twig/PatternDataNodeVisitor.php b/src/PatternLab/PatternEngine/Twig/PatternDataNodeVisitor.php deleted file mode 100644 index ac78b08..0000000 --- a/src/PatternLab/PatternEngine/Twig/PatternDataNodeVisitor.php +++ /dev/null @@ -1,38 +0,0 @@ -hasNode('expr') && $node->getNode('expr')->hasAttribute('value')) { - $patternStoreKey = $node->getNode('expr')->getAttribute('value'); - $data = Data::getPatternSpecificData($patternStoreKey); - if ($node instanceof \Twig_Node_Embed) { - $dataNode = new PatternDataEmbedNode($node, $data); - } - else { - $dataNode = new PatternDataIncludeNode($node, $data); - } - - return $dataNode; - } - } - - return $node; - } - - public function getPriority() - { - return 0; - } -} diff --git a/src/PatternLab/PatternEngine/Twig/TwigUtil.php b/src/PatternLab/PatternEngine/Twig/TwigUtil.php index 98a2991..eaedd53 100644 --- a/src/PatternLab/PatternEngine/Twig/TwigUtil.php +++ b/src/PatternLab/PatternEngine/Twig/TwigUtil.php @@ -14,7 +14,6 @@ use \PatternLab\Config; use \PatternLab\Console; -use \PatternLab\PatternEngine\Twig\PatternDataNodeVisitor; use \Symfony\Component\Finder\Finder; class TwigUtil { @@ -50,15 +49,6 @@ public static function setInstance($instance = "") { } - /** - * Adds a node visitor - */ - public static function addNodeVisitor() { - - self::$instance->addNodeVisitor(new PatternDataNodeVisitor()); - - } - /** * Registering each directory under `_patterns/` as a namespace. For example, `_patterns/00-atoms/` as `@atoms` * @param {Instance} an instance of the filesystem Loader From 6d929409f5f27506ab298013fe3f252ceb25c7ac Mon Sep 17 00:00:00 2001 From: Dave Olsen Date: Wed, 18 May 2016 22:22:55 -0400 Subject: [PATCH 23/29] updating dependencies for v2.0.0 release --- composer.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index b7442a4..83e723e 100644 --- a/composer.json +++ b/composer.json @@ -24,9 +24,8 @@ } }, "require": { - "php": ">=5.3.6", - "pattern-lab/core": "0.*", - "twig/twig": "1.*" + "pattern-lab/core": "^2.0.0", + "twig/twig": "~1.*" }, "extra": { "patternlab": { From fd6d8e2fd2a98efdc0c070788a8ad9aceb5e724b Mon Sep 17 00:00:00 2001 From: Dave Olsen Date: Wed, 18 May 2016 23:02:14 -0400 Subject: [PATCH 24/29] updating dependencies --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 83e723e..2108fdc 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ }, "require": { "pattern-lab/core": "^2.0.0", - "twig/twig": "~1.*" + "twig/twig": "~1.0" }, "extra": { "patternlab": { From 7f5647b8c5843b60174b4e39996b0485c475e091 Mon Sep 17 00:00:00 2001 From: bradwade Date: Fri, 23 Sep 2016 14:27:09 -0400 Subject: [PATCH 25/29] Fixing patternTypePath when not prefixing folders with numbers and dash --- src/PatternLab/PatternEngine/Twig/TwigUtil.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/PatternLab/PatternEngine/Twig/TwigUtil.php b/src/PatternLab/PatternEngine/Twig/TwigUtil.php index eaedd53..b483cd9 100644 --- a/src/PatternLab/PatternEngine/Twig/TwigUtil.php +++ b/src/PatternLab/PatternEngine/Twig/TwigUtil.php @@ -61,7 +61,8 @@ public static function addPaths($filesystemLoader, $patternSourceDir) { $finder = new Finder(); $finder->directories()->depth(0)->in($patternSourceDir); foreach ($finder as $file) { - $patternBits = explode("-",$file->getRelativePathName(),2); + $pattern = $file->getRelativePathName(); + $patternBits = explode("-",$pattern,2); $patternTypePath = (((int)$patternBits[0] != 0) || ($patternBits[0] == '00')) ? $patternBits[1] : $pattern; $filesystemLoader->addPath($file->getPathName(), $patternTypePath); } From 6e3c57f82a0b62588867c7f4c91905dc8977d221 Mon Sep 17 00:00:00 2001 From: Evan Lovely Date: Tue, 11 Oct 2016 12:45:41 -0700 Subject: [PATCH 26/29] Adds event "twigLoaderPreInit.customize" that allows manipulation of Twig Loaders before Init of Twig Environment. --- .../Twig/Loaders/PatternLoader.php | 17 +++++-- .../PatternEngine/Twig/TwigUtil.php | 44 ++++++++++++++++++- 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php b/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php index 3d01683..92371b1 100644 --- a/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php +++ b/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php @@ -64,13 +64,26 @@ public function __construct($options = array()) { // set-up the loader list in order that they should be checked // 1. Patterns 2. Filesystem 3. String $loaders = array(); + // 1. add Patterns $loaders[] = new Twig_Loader_PatternPartialLoader(Config::getOption("patternSourceDir"),array("patternPaths" => $options["patternPaths"])); - // add the paths to the filesystem loader if the paths existed + // 2. add the paths to the filesystem loader if the paths existed if (count($filesystemLoaderPaths) > 0) { $filesystemLoader = new \Twig_Loader_Filesystem($filesystemLoaderPaths); $loaders[] = TwigUtil::addPaths($filesystemLoader, $patternSourceDir); } + + // Setting loaders and giving plugins a chance to manipulate them + TwigUtil::setLoaders($loaders); + // set-up the dispatcher + $dispatcherInstance = Dispatcher::getInstance(); + $dispatcherInstance->dispatch("twigLoaderPreInit.customize"); + // getting the loaders back + $loaders = TwigUtil::getLoaders(); + + // 3. add String loader + // This *must* go last or no loaders after will work ~ https://github.com/symfony/symfony/issues/10865 + // @todo Remove `Twig_Loader_String` - if a Twig include path is wrong, this outputs the string anyway with no error ~ https://github.com/symfony/symfony/issues/10865 $loaders[] = new \Twig_Loader_String(); // set-up Twig @@ -87,8 +100,6 @@ public function __construct($options = array()) { TwigUtil::loadDebug(); TwigUtil::loadMacros(); - // set-up the dispatcher - $dispatcherInstance = Dispatcher::getInstance(); $dispatcherInstance->dispatch("twigLoader.customize"); $dispatcherInstance->dispatch("twigPatternLoader.customize"); diff --git a/src/PatternLab/PatternEngine/Twig/TwigUtil.php b/src/PatternLab/PatternEngine/Twig/TwigUtil.php index b483cd9..64f97da 100644 --- a/src/PatternLab/PatternEngine/Twig/TwigUtil.php +++ b/src/PatternLab/PatternEngine/Twig/TwigUtil.php @@ -19,7 +19,8 @@ class TwigUtil { protected static $instance = ''; - + protected static $loaders = array(); + /** * Get an instance of the Twig environment * @@ -46,7 +47,46 @@ public static function setInstance($instance = "") { } self::$instance = $instance; - + + } + + /** + * Get an instance of the Twig loaders + * + * @return {Array} List of Twig Loaders + */ + public static function getLoaders() { + + if (empty(self::$loaders)) { + return false; + } + + return self::$loaders; + + } + + /** + * Set an instance of the Twig loaders + * @param {Array} List of Twig Loaders + */ + public static function setLoaders($loaders = array()) { + + if (empty($loaders)) { + Console::writeError("please set the loaders"); + } + + self::$loaders = $loaders; + + } + + /** + * Add a loader to the Twig Loaders array + * @param {Loader} A Twig Loader + */ + public static function addLoader($loader) { + + self::$loaders[] = $loader; + } /** From 6e16b3deca4e94016bfe6209504fb3e5db7b586e Mon Sep 17 00:00:00 2001 From: Evan Lovely Date: Wed, 12 Oct 2016 14:26:47 -0700 Subject: [PATCH 27/29] Throwing error on uncompiled templates --- .../PatternEngine/Twig/Loaders/PatternLoader.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php b/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php index 92371b1..8d0ae3a 100644 --- a/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php +++ b/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php @@ -116,7 +116,16 @@ public function __construct($options = array()) { */ public function render($options = array()) { - return $this->instance->render($options["pattern"], $options["data"]); + $result = $this->instance->render($options["pattern"], $options["data"]); + // This error handler catches files that didn't render using any of the loaders. + // The most common scenario is when a file's contents get passed to and through `Twig_Loader_String` and + // outputs the raw Twig file contents like `@atoms/buttons/button.twig`. + // @todo Remove this once `Twig_Loader_String` is removed. + if (strpos($result, "@") === 0) { + throw new \Twig_Error_Loader("Twig file not found: " . $result . "\n"); + } else { + return $result; + } } From 65324c72d2fb3a10cb25bbd65ce08a89fefc5896 Mon Sep 17 00:00:00 2001 From: Evan Lovely Date: Wed, 12 Oct 2016 14:51:54 -0700 Subject: [PATCH 28/29] Improving signal to noise ratio on error --- src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php b/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php index 8d0ae3a..fa2ce2f 100644 --- a/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php +++ b/src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php @@ -122,7 +122,8 @@ public function render($options = array()) { // outputs the raw Twig file contents like `@atoms/buttons/button.twig`. // @todo Remove this once `Twig_Loader_String` is removed. if (strpos($result, "@") === 0) { - throw new \Twig_Error_Loader("Twig file not found: " . $result . "\n"); + echo "Twig file not found: " . $result . "\n"; + exit(1); } else { return $result; } From f402a2f3e9aff0ead34fa9e8d0c3119d74e51997 Mon Sep 17 00:00:00 2001 From: Evan Lovely Date: Mon, 9 Oct 2017 10:51:14 -0700 Subject: [PATCH 29/29] Fixing lineage config line (#45) * Fixing lineage config line Mega PR: Merging Drupal Pattern Lab's Twig Pattern Engine Fork Back Into the Main Pattern Lab PHP Twig Pattern Engine Repo (#44) * updating dev-dev dependencies * fixing failing constraint * Testing regex updates meant for composer.json-based consumption. Not nearly as easy as copying over from the config.yml file... * Adding original for testing comparison * Testing updated and simplified regex which also fixes lineages when using D8 friendly Twig paths * Updating registered namespace to Drupal Pattern Lab * Revert "Updating registered namespace to Drupal Pattern Lab" This reverts commit ba07a6e714dc84ef6fdae59d3315d4f72aaa9c7a. * updating info * Remove reference to Drupal Pattern Lab fork --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2108fdc..08b3a46 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "extra": { "patternlab": { "config": { - "lineageMatch": "{%([ ]+)?include( |\\()["\\']([A-Za-z0-9-_]+)["\\'](\\))?(.*)%}", + "lineageMatch": "{%([ ]+)?(?:include|extends|embed)( |\\()["\\']([\\/.@A-Za-z0-9-_]+)["\\']([\\s\\S+]*?)%}", "lineageMatchKey": 3, "patternExtension": "twig", "twigDebug": false,