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

Make it compatible with Ruby's BasicObject #21

Closed
wants to merge 2 commits into from

Conversation

jodosha
Copy link

@jodosha jodosha commented Aug 1, 2017

Hi, I'm the author of Hanami, the web framework for Ruby.

Our gem hanami-view uses tilt to render templates. During the rendering process, the view passes to the Tilt::Template a scope which inherits from Ruby's BasicObject.

This decision was taken to avoid conflicts with methods defined by Ruby's Object, which had the result of shadowing methods in the scope. This is one example of the clash: hanami/view#28


There are two devs who reported a bug both in your repo and in ours as well, because our gems aren't compatible.

This PR aims to fix these problems, by making tilt-jbuilder compatible with BasicObject, and by consequence with Hanami.

Please consider to merge this, I believe that tilt-jbuilder can benefit from this, regardless the Hanami compatibility. Again, see hanami/view#28 for a concrete example.

Thanks in advance for your time.


Fix: #20

@coveralls
Copy link

coveralls commented Aug 1, 2017

Coverage Status

Coverage increased (+0.02%) to 99.0% when pulling 9fea07b on jodosha:fix/basic-object-compat into 9fcc2a8 on anthonator:master.

scope.instance_exec(binding) {
@_jbuilder_view_path = view_path
@_jbuilder_locals = locals
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of this change? Is this for BasicObject compatibility or an unrelated changed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's related because BasicObject doesn't respond to #send.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semi-related: I removed the line that was setting data because it wasn't clear to me where data was previously instantiated, and because the tests were still passing without it.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless you feel like you have a good reason not to would you mind adding data back in? Removing it seems unrelated to this PR and I'd rather not risk introducing a bug.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anthonator I see your concern and totally agree with it.

But if add that data back as third line, it raises a NoMethodError. Which leads us to the initial issue: I don't understand where is defined. 😉

@anthonator
Copy link
Owner

@jodosha thanks for submitting this! Do you know if the other Tilt templates use BasicObject in this manner as well?

@jodosha
Copy link
Author

jodosha commented Aug 2, 2017

@anthonator My pleasure to make gems to work together. 😉

I don't know if other Tilt templates use BasicObject, but we use it in Hanami since three years now with ERb/HAML/Slim and it works just great.

The suggestion to use BasicObject came from one of the Tilt maintainers: hanami/view#28 (comment)

@anthonator
Copy link
Owner

Other than an issue I brought up above I think this looks good.

Would you mind adding some information to the README on how to use tilt-jbuilder with Hanami?

@jodosha
Copy link
Author

jodosha commented Aug 11, 2017

@anthonator sure thing. 😄

@coveralls
Copy link

coveralls commented Aug 11, 2017

Coverage Status

Coverage decreased (-0.04%) to 98.942% when pulling 4baf13f on jodosha:fix/basic-object-compat into 9fcc2a8 on anthonator:master.

@jodosha jodosha closed this Dec 8, 2022
@jodosha jodosha deleted the fix/basic-object-compat branch December 8, 2022 12:34
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.

Runtime error with latest Hanami
3 participants