Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update twig loader to support Twig 2.x #105

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

TechWilk
Copy link

@TechWilk TechWilk commented Jan 18, 2018

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

@TechWilk
Copy link
Author

Fixes #100
Surpasses #102

@vendethiel
Copy link
Contributor

why is this one better?

@TechWilk
Copy link
Author

TechWilk commented Jan 18, 2018

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
Copy link
Author

TechWilk commented Jan 18, 2018

@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?

@jkufner
Copy link

jkufner commented Jan 18, 2018

@TechWilk if (method_exists(...

@TechWilk TechWilk changed the title Update twig loader to remove deprecated methods Update twig loader to support Twig 2.x Jan 18, 2018
@TechWilk
Copy link
Author

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

getSource() was deprecated in twig 1.27
getSourceContext() replaced it, which returns a Twig_Source object, rather than just the code
https://twig.symfony.com/doc/1.x/deprecated.html#loaders
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants