Module: Fortitude::Rails::RenderingMethods::Overrides

Defined in:
lib/fortitude/rails/rendering_methods.rb

Instance Method Summary collapse

Instance Method Details

#render_uniwith_fortitude(original_method, *args, &block) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/fortitude/rails/rendering_methods.rb', line 70

def render_uniwith_fortitude(original_method, *args, &block)
  if (options = args[0]).kind_of?(Hash) && (widget_block = options[:inline]) && (options[:type] == :fortitude)
    options.delete(:inline)

    rendering_context = fortitude_rendering_context_for(self, nil)
    widget_class = Class.new(Fortitude::Widgets::Html5)
    widget_class.use_instance_variables_for_assigns(true)
    widget_class.extra_assigns(:use)
    widget_class.send(:define_method, :content, &widget_block)

    assigns = { }
    instance_variables.each do |ivar_name|
      value = instance_variable_get(ivar_name)
      assigns[$1.to_sym] = value if ivar_name =~ /^@([^_].*)$/
    end
    assigns = assigns.merge(options[:locals] || { })

    widget = widget_class.new(assigns)
    new_args = [ options.merge(:widget => widget) ] + args[1..-1]
    return original_method.call(*new_args, &block)
  end

  return original_method.call(*args, &block)
end