jferris / effigy

Ruby views without a templating language
http://rdoc.info/projects/jferris/effigy
MIT License
206 stars 6 forks source link

A closure passed to Effigy::View#template is evaluated in the context it was defined #13

Closed ghost closed 14 years ago

ghost commented 14 years ago

A closure is evaluated in the context it was defined in when passed onto Effigy::View#render which means Effigy::View isn't in context and you can't instance methods found on that class.

I made a patch: http://github.com/robgleeson/effigy/commit/86522c281f21b969f4a5726f4385009e2947fc22 and reported it to the network effigy is in but no replies.

ghost commented 14 years ago

Sorry I made a mistake in the topic name - it should be Effigy::View#render .. oops, very tried :-)

jferris commented 14 years ago

Thanks for the patch. However, if the block passed to #render is evaluated in the context of the view instance, it means there's no way to reference methods on the calling object from within the block. The way things are implemented now, you can access all public view methods by calling them on the view object. Anything that requires use of private methods can be handled using a subclass. In almost every case, a subclass is favorable anyway.

ghost commented 14 years ago

Yeah, of course, I didn't even think of that! :-)