module Oprah::ControllerHelpers
Helpers that will be mixed into `ActionController::Base` and `ActionMailer::Base` by the {Oprah::Railtie}.
Public Instance Methods
The view context automatically passed to objects presented from this controller.
You can override this method pass a custom view context to all presented objects from the controller scope.
@see oprah_view_context=
@return [ActionView::Base]
# File lib/oprah/controller_helpers.rb, line 71 def oprah_view_context @oprah_view_context || view_context end
Assigns the view context returned from {#oprah_view_context}.
You can override this method pass a custom view context to all presented objects from the controller scope.
@since 0.1.3 @see oprah_view_context
@param [ActionView::Base] view_context
The view context to assign @return [ActionView::Base]
# File lib/oprah/controller_helpers.rb, line 84 def oprah_view_context=(view_context) @oprah_view_context = view_context end
Presents a single object.
Will pass the view context returned from {#oprah_view_context} to the presenter by default. This can be overridden.
@see Presenter.present
# File lib/oprah/controller_helpers.rb, line 41 def present(*args, **kwargs, &block) kwargs = { view_context: oprah_view_context_proxy }.merge(kwargs) Presenter.present(*args, **kwargs, &block) end
Presents a collection of objects.
Will pass the view context returned from {#oprah_view_context} to the presenter by default. This can be overridden.
# File lib/oprah/controller_helpers.rb, line 55 def present_many(*args, **kwargs, &block) kwargs = { view_context: oprah_view_context_proxy }.merge(kwargs) Presenter.present_many(*args, **kwargs, &block) end
Returns an instance of a view class and sets the current view context returned by {#oprah_view_context}.
If you override this method in your controller ensure you keep Oprah's view context updated using {#oprah_view_context=}.
@since 0.1.3 @see api.rubyonrails.org/classes/ActionView/Rendering.html#method-i-view_context
Rails API Documentation
@return [ActionView::Base]
# File lib/oprah/controller_helpers.rb, line 98 def view_context self.oprah_view_context = super end
Private Instance Methods
@since 0.1.3
# File lib/oprah/controller_helpers.rb, line 105 def oprah_view_context_proxy @oprah_view_context_proxy ||= ViewContextProxy.new(self) end