Module: Coupdoeil::Popover::LazyLoading

Extended by:
ActiveSupport::Concern
Included in:
Coupdoeil::Popover
Defined in:
app/models/coupdoeil/popover/lazy_loading.rb

Instance Method Summary collapse

Instance Method Details

#lazy_loading!Object



30
# File 'app/models/coupdoeil/popover/lazy_loading.rb', line 30

def lazy_loading! = @lazy_loading = true

#lazy_loading?true, false

Returns:

  • (true, false)


29
# File 'app/models/coupdoeil/popover/lazy_loading.rb', line 29

def lazy_loading? = @lazy_loading || false

#loader_templateActionView::Template?

Returns the loader variant for the current action if it exists.

Returns:

  • (ActionView::Template, nil)


34
35
36
37
38
39
40
# File 'app/models/coupdoeil/popover/lazy_loading.rb', line 34

def loader_template
  return @loader_template if defined?(@loader_template)

  paths = ["#{self.class.popover_resource_name}_popover"]
  found_template = lookup_context.find(action_name, paths, false, [], { variants: :loader })
  @loader_template = found_template.variant == "loader" ? found_template : nil
end

#process(method_name) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/models/coupdoeil/popover/lazy_loading.rb', line 42

def process(method_name, ...)
  return super unless lazy_loading?

  self.action_name = method_name

  instrument_render(method_name) do
    if loader_template
      render template: loader_template
    else
      render html: "", layout: true
    end
  end
end