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

Rendering an Erector widget from inside Fortitude #16

Closed
ajb opened this issue Nov 22, 2014 · 3 comments
Closed

Rendering an Erector widget from inside Fortitude #16

ajb opened this issue Nov 22, 2014 · 3 comments

Comments

@ajb
Copy link

ajb commented Nov 22, 2014

Kinda a weird use case, I'll admit, but as we're converting over our applications from Erector -> Fortitude, they still have dependencies that include Erector widgets. I thought it would be as easy as:

class FortitudeWidget < Views::Base

  def content
    rawtext ErectorWidget.new.to_html
  end

end

But the problem is that the ErectorWidget doesn't have access to the helpers object, so if it tries to reference e.g. current_user, it fails.

Any advice on how to pass in either parent or helpers? Here a link to some related lines in the Erector codebase.

@ageweke
Copy link
Owner

ageweke commented Nov 22, 2014

Thanks for letting me know! I just pushed a fix for this to master. It actually works both ways, allowing you to invoke a Fortitude widget from Erector, and an Erector widget from Fortitude, using just the normal #widget method.

If you can take a look at the monkeypatch I’m applying to Erector and let me know if it seems correct, that’d be awesome.

(There’s really only one corner case I’m uncertain about, which is whether the :delegate_object should be :parent or not. Because we’re also passing :output_buffer_holder and :helpers_object, the only thing the :delegate_object would be used for is grabbing instance variables from the controller, which, in turn, only happens if you turn on implicit_shared_variable_access in Fortitude (IMHO, a really bad idea) or access them via the shared_variables Hash-like object (also probably a bad idea), so it’s not something I would really expect almost anybody to run into. But still thought it was worth asking about.)

@ageweke
Copy link
Owner

ageweke commented Nov 22, 2014

Oh, and I should mention: because Erector (last I saw) wrapped its output buffers and seemed to manipulate them independently of Rails, I’m virtually certain that more complex cases — like passing a block from Fortitude to Erector, or vice-versa — will have issues in them. Unless you see both a compelling need to fix this and a clear path to doing it reliably, I’m not inclined to fix it, as I think the output-buffer models involved are just too dissimilar. But the more simple cases should work just fine, including passing parameters, which are probably the most important anyway.

@ajb
Copy link
Author

ajb commented Nov 23, 2014

Thanks! This works great, and re: corner cases, this is already leagues beyond what I would say Fortitude should be responsible for.

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

No branches or pull requests

2 participants