Class: Kadmin::Presenter
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Kadmin::Presenter
- Defined in:
- lib/kadmin/presenter.rb,
lib/kadmin/presenter/test_case.rb
Overview
Base presenter class
Direct Known Subclasses
Finder::Presenter, Navbar::Link::Presenter, Navbar::Section::Presenter, Kadmin::Pager::Presenter
Defined Under Namespace
Classes: NoViewContext, TestCase
Instance Method Summary collapse
-
#initialize(object, view: nil) ⇒ Presenter
constructor
A new instance of Presenter.
-
#present(view) ⇒ self
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.
-
#render(view: nil, **options, &block) ⇒ Object
Renders the wrapped object into the given view.
Constructor Details
#initialize(object, view: nil) ⇒ Presenter
Returns a new instance of Presenter.
6 7 8 9 |
# File 'lib/kadmin/presenter.rb', line 6 def initialize(object, view: nil) super(object) @view = view end |
Instance Method Details
#present(view) ⇒ self
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.
39 40 41 42 |
# File 'lib/kadmin/presenter.rb', line 39 def present(view) @view = view return self end |
#render(view: nil, **options, &block) ⇒ Object
Renders the wrapped object into the given view
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/kadmin/presenter.rb', line 16 def render(view: nil, **, &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, **) ensure @view = previous_view end return rendered end |