Class: Voom::Presenters::WebClient::ComponentRenderer

Inherits:
Object
  • Object
show all
Extended by:
Pluggable
Defined in:
lib/voom/presenters/web_client/component_renderer.rb

Overview

This class renders a given component. First it looks for plugins that override default behavior If they don’t exist then it renders the base components

Instance Method Summary collapse

Methods included from Pluggable

include_plugins, plugin, plugin_module

Constructor Details

#initialize(comp, render:, components:, index:, scope: nil) ⇒ ComponentRenderer

Returns a new instance of ComponentRenderer.



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/voom/presenters/web_client/component_renderer.rb', line 13

def initialize(comp,
               render:,
               components:,
               index:,
               scope: nil)
  @comp = comp
  @index = index
  @components = components
  @scope = scope
  @render = render
  initialize_plugins
end

Instance Method Details

#renderObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/voom/presenters/web_client/component_renderer.rb', line 26

def render
  comp = ComponentDecoratorFactory.build(@comp)
  components = @components.map { |c| ComponentDecoratorFactory.build(c) }

  return public_send(:"render_#{@scope ? "_#{@scope}_" : nil}#{@comp.type}",
              comp,
              components: components,
              index: @index,
              render: @render) if respond_to?(:"render_#{@comp.type}")

  @render.call :erb, :"components#{@scope ? "/#{@scope}" : nil}/#{@comp.type}",
               :locals => {comp: comp,
                           components: components, index: @index}
end