Class: RailsCriticalCss::Actions::AfterRender

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/rails_critical_css/actions/after_render.rb

Instance Method Summary collapse

Methods included from Helpers

#absolute_asset_file_path, #eval_option, #eval_options, #gen_critical_css_cache_path, #group_assets_by_type

Constructor Details

#initialize(filter_options) ⇒ AfterRender



7
8
9
10
11
# File 'lib/rails_critical_css/actions/after_render.rb', line 7

def initialize(filter_options)
  @packed_options = filter_options.slice(
    :css, :cache_key, :cache_store, :cache_prefix
  )
end

Instance Method Details

#after(controller) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rails_critical_css/actions/after_render.rb', line 13

def after(controller)
  return if controller.critical_css_cache.present?

  @controller = controller
  options = eval_options(controller, @packed_options)
  cache_path = gen_critical_css_cache_path(options, options[:cache_key])

  return if cache_path == false

  RailsCriticalCss::Jobs::Extractor.perform_if_semaphore_is_released(
    html: controller.full_html_response,
    cache: {
      path: cache_path,
      store: options[:cache_store],
    },
    css: {
      assets: assets_mapped_paths,
    },
  )
end