Module: Fortitude::Rails::FortitudeRailsHelpers

Extended by:
ActiveSupport::Concern
Defined in:
lib/fortitude/rails/fortitude_rails_helpers.rb

Constant Summary collapse

EMPTY_RETURN_VALUE =
''.html_safe.freeze

Instance Method Summary collapse

Instance Method Details

#widget(target, assigns = {}, options = {}, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fortitude/rails/fortitude_rails_helpers.rb', line 10

def widget(target, assigns = {}, options = {}, &block)
  if target.kind_of?(Class) && ((target < ::Fortitude::Widget) || ::Fortitude::Erector.is_erector_widget_class?(target))
    assigns ||= { }
    target = target.new(assigns)
  end

  if target.kind_of?(::Fortitude::Widget)
    rendering_context = ::Fortitude::RenderingContext.new(:delegate_object => self)
    target.render_to(rendering_context, &block)
  elsif ::Fortitude::Erector.is_erector_widget?(target)
    target.send(:_emit,
      :parent => self,
      :helpers => self,
      :output => output_buffer)
  else
    raise TypeError, "You must pass a Fortitude or Erector widget, or widget class, to #widget; you passed: #{target.inspect}"
  end

  EMPTY_RETURN_VALUE
end