drupal-pattern-lab / patternengine-php-twig

Twig-based PatternEngine for Pattern Lab.
http://patternlab.io/
MIT License
2 stars 1 forks source link

Fix Pattern Lab Twig Lineages When Using D8-friendly Twig Paths (Part 1 of 2) #1

Closed sghoweri closed 7 years ago

sghoweri commented 7 years ago

First half of the fix required in order to get pattern lineages working in Pattern Lab again when using Twig templates and/or use virtually any character in your template that the original regex can't account for.

Note: this shouldn't appear to change any current lineage behavior just yet if just testing this one part. Once the other LineageHelper.php fix is in place this should be fully up and running.

Adds and expands Pattern Lab lineage support (on the regex side) when using Twig templates:

  1. That call include, embed OR extend now (previously only worked with includes)
  2. That include any special characters in the path including the @ sign, dots, etc. (previously only worked with a-z, A-Z, numbers, dashes and hyphens).
  3. That include the .twig file extension in the path (previously failed)
  4. That include one or multiple parameters via the Twig with syntax including commas (previously failed)
  5. That include parameters with values using special characters like parentheses, hashes, percent signs, greater than / less than signs, etc. (previously failed on all parameters)
  6. That still continue to use the shorthand path syntax (still works)
  7. That span across one or multiple lines, including line breaks (previously failed)

Testing notes:

  1. PL still compiles properly without any errors if using the updated regex logic but still using the originl unpatched LineageHelper.php file.

  2. Same is also true (no errors) if using the updated LineageHelper.php logic but the _config.yml is using the old Twig regex

  3. Using the updated regex + updated LineageHelper.php logic also compiles successfully without any errors, however it also appears to fully fix the broken Pattern Lab lineage functionality that's been broken for quite some time, at least based on out in the wild

  4. Furthermore, tested requiring this json-friendly version in via composer which properly adds the yaml-friendly / converted version to config.yml:

ex. config.yml should look something like this when updated.

lineageMatch: '{%([ ]+)?(?:include|extends|embed)( |\()["\']([\/.@A-Za-z0-9-_]+)["\']([\s\S+]*?)%}'
sghoweri commented 7 years ago

@EvanLovely - can definitely throw in a placeholder issue into our fork of PL Core

I THINK Part 2 is almost ready for a PR -- this week's just been crazy busy so I haven't gotten to it yet (BUT SOON!) =P