Class: Komponent::ComponentRenderer

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::CaptureHelper
Defined in:
lib/komponent/component_renderer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller) ⇒ ComponentRenderer

Returns a new instance of ComponentRenderer.



10
11
12
13
14
# File 'lib/komponent/component_renderer.rb', line 10

def initialize(controller)
  @context = controller.view_context.dup
  @view_renderer = @context.view_renderer = @context.view_renderer.dup
  @lookup_context = @view_renderer.lookup_context = @view_renderer.lookup_context.dup
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



8
9
10
# File 'lib/komponent/component_renderer.rb', line 8

def context
  @context
end

#output_bufferObject

Returns the value of attribute output_buffer.



7
8
9
# File 'lib/komponent/component_renderer.rb', line 7

def output_buffer
  @output_buffer
end

Instance Method Details

#render(component, locals = {}, options = {}, &block) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/komponent/component_renderer.rb', line 16

def render(component, locals = {}, options = {}, &block)
  cached = options.delete(:cached)
  if cached

    cached_block = block ? block.call : nil
    key = [component, locals, options, cached_block].to_s
    cache_key = Digest::SHA1.hexdigest(key)

    Rails.cache.fetch(cache_key) do
      _render(component, locals, options, &block)
    end
  else
    _render(component, locals, options, &block)
  end
end