Module: Fortitude::Rails::RenderingMethods

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

Defined Under Namespace

Modules: ActionControllerOverrides, Overrides

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

._fortitude_register_renderer!Object


63
64
65
66
67
# File 'lib/fortitude/rails/rendering_methods.rb', line 63

def self._fortitude_register_renderer!
  ::ActionController.add_renderer(:_fortitude_widget) do |widget, options|
    ::Fortitude::Rails::RenderingMethods._fortitude_render_widget(self, widget, options)
  end
end

._fortitude_render_widget(controller, widget, options) ⇒ Object


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/fortitude/rails/rendering_methods.rb', line 27

def self._fortitude_render_widget(controller, widget, options)
  if ::Fortitude::Erector.is_erector_widget_class?(widget) || ::Fortitude::Erector.is_erector_widget_class?(widget.class)
    return ::Erector::Rails.render(widget, controller.view_context, { }, false, options)
  end

  view_context = controller.view_context

  if widget.kind_of?(Class)
    if widget < ::Fortitude::Widget
      widget = widget.new(widget.extract_needed_assigns_from(view_context.assigns))
    else
      raise "You tried to render something using 'render :widget' that is a class, but not a subclass of Fortitude::Widget: #{widget.inspect}"
    end
  end

  if (! widget.kind_of?(::Fortitude::Widget))
    raise "You tried to render something using 'render :widget' that is neither an instance of a subclass of Fortitude::Widget, nor a class that inherits from Fortitude::Widget: #{widget.inspect}"
  end

  rendering_context = controller.create_fortitude_rendering_context(
    :helpers_object => view_context, :output_buffer_holder => view_context)

  output_buffer = view_context.with_output_buffer do
    widget.render_to(rendering_context)
  end

  passed_options = options.dup
  passed_options.delete(:widget)

  output_key = if ::Rails.version =~ /^(3\.)|(4\.0\.)/ then :text else :html end
  passed_options[output_key] = output_buffer.to_s
  passed_options[:layout] = true unless passed_options.has_key?(:layout)

  return controller.render_to_string(passed_options)
end

.include_into!(target) ⇒ Object


10
11
12
13
14
# File 'lib/fortitude/rails/rendering_methods.rb', line 10

def include_into!(target)
  target.send(:include, self)
  ::Fortitude::MethodOverriding.override_methods(
    target, ::Fortitude::Rails::RenderingMethods::Overrides, :fortitude, [ :render ])
end

Instance Method Details

#create_fortitude_rendering_context(options) ⇒ Object


23
24
25
# File 'lib/fortitude/rails/rendering_methods.rb', line 23

def create_fortitude_rendering_context(options)
  ::Fortitude::RenderingContext.new(options)
end

#fortitude_rendering_context_for(delegate_object, yield_block) ⇒ Object


17
18
19
20
21
# File 'lib/fortitude/rails/rendering_methods.rb', line 17

def fortitude_rendering_context_for(delegate_object, yield_block)
  @_fortitude_rendering_contexts ||= { }
  @_fortitude_rendering_contexts[delegate_object.object_id] ||= create_fortitude_rendering_context(
    :delegate_object => delegate_object, :yield_block => yield_block)
end