class Kadmin::Presenter
Base presenter class
Public Class Methods
@param [Object] object the object to present @param [ActiveView::Base] view the view to present in; can be provided later on
# File lib/kadmin/presenter.rb, line 6 def initialize(object, view: nil) super(object) @view = view end
Public Instance Methods
Updates the context of the presenter with the given view This is mostly to provide a consistent interface between Presentable
and Presenter
, so you don't have to check if you should present something or not. @param [ActiveView::Base] view render in a different view @return [self] returns itself, as it is already presented
# File lib/kadmin/presenter.rb, line 39 def present(view) @view = view return self end
Renders the wrapped object into the given view @param [ActiveView::Base] view optionally render in a different view @param [Hash] options additional options passed to the render method @param [Proc] block optional block to render additional stuff within the template @return [Object] rendered representation of the wrapped object, typically a string
# File lib/kadmin/presenter.rb, line 16 def render(view: nil, **options, &block) previous_view = @view rendered = nil captured = '' begin @view = view unless view.nil? raise Kadmin::Presenter::NoViewContext if @view.nil? captured = capture(&block) if block_given? rendered = generate(captured, **options) ensure @view = previous_view end return rendered end
Protected Instance Methods
Generates the representation of the wrapped object. Should be overloaded and implemented by a concrete class.
# File lib/kadmin/presenter.rb, line 48 def generate(captured, **) return "<div>#{__getobj__.inspect}#{captured}</div>".html_safe end