Module: HamlCoffeeAssets::ActionView::Patches::InstanceMethods

Defined in:
lib/haml_coffee_assets/action_view/patches.rb

Instance Method Summary collapse

Instance Method Details

#handle_render_error_with_patch(view, e) ⇒ Object

Patch, it’s almost exaclty the same with a small tweak



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/haml_coffee_assets/action_view/patches.rb', line 12

def handle_render_error_with_patch(view, e) #:nodoc:
  if e.is_a?(::ActionView::Template::Error)
    e.sub_template_of(self)
    raise e
  else
    assigns  = view.respond_to?(:assigns) ? view.assigns : {}
    template = self

    # Here's the patch: if the javascript runtime throws an error
    # during compilation, we get to this handler but our view 
    # doesn't have a lookup_context - thus throwing a very hard
    # to debug error in Template#refresh. To circumvent, ensure the
    # view responds to lookup_context before refreshing.
    if view.respond_to?(:lookup_context) and template.source.nil?
      template = refresh(view)
      template.encode! if template.respond_to?(:encode!)
    end

    if ::Rails::VERSION::STRING < "4"
      raise ::ActionView::Template::Error.new(template, assigns, e)
    elsif ::Rails::VERSION::STRING < "5.1"
      raise ::ActionView::Template::Error.new(template, e)
    else
      raise ::ActionView::Template::Error.new(template)
    end
  end
end