Module: Plugins::CamaleonLazyLoader::MainHelper

Defined in:
app/helpers/plugins/camaleon_lazy_loader/main_helper.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



2
3
# File 'app/helpers/plugins/camaleon_lazy_loader/main_helper.rb', line 2

def self.included(klass)
end

Instance Method Details

#apply_lazy_loading(html) ⇒ Object



9
10
11
12
13
14
# File 'app/helpers/plugins/camaleon_lazy_loader/main_helper.rb', line 9

def apply_lazy_loading(html)
  doc = Nokogiri::HTML.parse html
  nodes = doc.css "img, iframe"
  nodes.each { |node| node["loading"] ||= "lazy" }
  doc.to_html
end

#camaleon_lazy_loader_front_after_loadObject



16
17
18
19
# File 'app/helpers/plugins/camaleon_lazy_loader/main_helper.rb', line 16

def camaleon_lazy_loader_front_after_load
  return if @_plugin_do_cache # Do not process when reading from cache.
  response.body = apply_lazy_loading response.body
end

#camaleon_lazy_loader_front_cache_writing_cache(args) ⇒ Object



21
22
23
24
# File 'app/helpers/plugins/camaleon_lazy_loader/main_helper.rb', line 21

def camaleon_lazy_loader_front_cache_writing_cache(args)
  args[:data] = apply_lazy_loading args[:data] # Save processed HTML to cache.
  response.body = apply_lazy_loading response.body
end

#clear_front_cache(_plugin) ⇒ Object



5
6
7
# File 'app/helpers/plugins/camaleon_lazy_loader/main_helper.rb', line 5

def clear_front_cache(_plugin)
  front_cache_clean
end