Module: Spark::Component::Integration

Defined in:
lib/spark/component/integration/action_view_component.rb

Defined Under Namespace

Modules: ClassMethods, Element

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.base_classObject



6
7
8
# File 'lib/spark/component/integration/action_view_component.rb', line 6

def self.base_class
  ActionView::Component::Base
end

.included(base) ⇒ Object



10
11
12
# File 'lib/spark/component/integration/action_view_component.rb', line 10

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#render_in(view_context, &block) ⇒ Object

Override ActionView::Components::Base ‘render_in` This is only necessary in order to pass `self` as a block parameter



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/spark/component/integration/action_view_component.rb', line 16

def render_in(view_context, &block)
  self.class.compile
  @view_context = view_context
  @view_renderer ||= view_context.view_renderer
  @lookup_context ||= view_context.lookup_context
  @view_flow ||= view_context.view_flow
  @virtual_path ||= virtual_path
  @variant = @lookup_context.variants.first
  old_current_template = @current_template
  @current_template = self

  # Pass self as a block parameter
  @content = render_block(view_context, &block) if block_given?
  validate!

  send(self.class.call_method_name(@variant))
ensure
  @current_template = old_current_template
end

#render_selfObject



36
37
38
39
40
41
42
# File 'lib/spark/component/integration/action_view_component.rb', line 36

def render_self
  # Guard with `rendered?` boolean in case render_block returns `nil`
  return @render_self if rendered?

  @rendered = true
  @render_self = render_in(@view_context, &@_block)
end