Module: StepRender::ViewHelper

Defined in:
lib/step_render/view_helper.rb

Instance Method Summary collapse

Instance Method Details

#import_step_renderObject



15
16
17
# File 'lib/step_render/view_helper.rb', line 15

def import_step_render
  '<script src="https://cdnjs.cloudflare.com/ajax/libs/lazysizes/3.0.0/lazysizes.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/lazysizes/3.0.0/plugins/include/ls.include.min.js"></script>'.html_safe
end

#step_render(*options) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/step_render/view_helper.rb', line 4

def step_render(*options)
  if Rails.cache.is_a?(ActiveSupport::Cache::NullStore)
    render *options
  else
    key = "lazy-partial-#{SecureRandom.hex(12)}"
    cookies.signed[key] = { value: Marshal.dump(ActiveJob::Arguments.serialize(options)), expires: 2.hour.from_now }
    # if use cache store
    # Rails.cache.fetch(key, skip_digest: true, expires_in: 10.minute) { ActiveJob::Arguments.serialize(options) }
    %(<div class= "related-articles lazyload" data-include="#{step_render_path(key)}">loading</div>).html_safe
  end
end