MtHaml icon indicating copy to clipboard operation
MtHaml copied to clipboard

Update twig loader to support Twig 2.x

Open TechWilk opened this issue 7 years ago • 6 comments

getSource() was deprecated in twig 1.27 https://twig.symfony.com/doc/1.x/deprecated.html#loaders

TechWilk avatar Jan 18 '18 21:01 TechWilk

Fixes #100 Surpasses #102

TechWilk avatar Jan 18 '18 21:01 TechWilk

why is this one better?

vendethiel avatar Jan 18 '18 21:01 vendethiel

getSource() was deprecated in twig 1.27 and has been removed in twig 2.x, preventing the twig loader from working.

#102 doesn't currently perform any haml rendering in the getSourceContext() method, it simply adds an alias method for the underlying Twig_LoaderInterface so haml doesn't get rendered. The haml rendering needs to be performed in getSourceContext() for twig 2.x.

I've tested with twig 2.0, though it looks like I may have broken backwards compatibility with twig 1.0 which is why the tests failed (they seem to only run for twig 1.x). I'll take a look and update the PR.

TechWilk avatar Jan 18 '18 21:01 TechWilk

@vendethiel I've refactored the haml generation to keep support for both twig 1.x as well as making twig 2.x work, however I'm struggling to get the tests to pass across all versions.

It seems you can't mock a method if it doesn't exist, therefore:

  • mocking the underlying loader's getSource() fails on twig 2.x
  • mocking the underlying loader's getSourceContext() fails on twig 1.x

How do you want to proceed?

TechWilk avatar Jan 18 '18 21:01 TechWilk

@TechWilk if (method_exists(...

jkufner avatar Jan 18 '18 21:01 jkufner

@jkufner yep, totally didn't think of that! I'll do some more work on it tomorrow.

TechWilk avatar Jan 18 '18 22:01 TechWilk