hanami / view

Views, templates and presenters for Ruby web applications
http://hanamirb.org
MIT License
173 stars 80 forks source link

Ensure proper access to full `locals` hash in templates #208

Closed timriley closed 2 years ago

timriley commented 2 years ago

This should already have worked, thanks to the method_missing-based #locals method that we expose in Hanami::View::Scope.

However, locals in in fact a local variable in the template rendering context, since that's the name of the one and only parameter for the method that Tilt compiles each template into. This means we can't access the #locals on our Scope instance without explicitly calling self.locals.

To fix this, we pass our scope._locals additionally into Tilt's render method, which will allow bare locals references to work inside templates.

Since this behavior evaded detection for so many years, we now have a dedicated test to make sure it remains working like we expect in the future.