Class: RailsReactViews::Prerenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_react_views/prerenderer.rb

Class Method Summary collapse

Class Method Details

.build_context(props: {}, view:, path:) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/rails_react_views/prerenderer.rb', line 18

def build_context(props: {}, view:, path:)
  {
    props: props,
    view: view,
    path: base_path(path)
  }
end

.prerender(view: '', path: '', props: {}, context: nil, context_json: nil, cache: true) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/rails_react_views/prerenderer.rb', line 4

def prerender(view: '', path: '', props: {}, context: nil, context_json: nil, cache: true)
  context_json ||= (context || build_context(props: props, view: view, path: path)).to_json

  if cache && Rails.configuration.action_controller.perform_caching
    context_digest = Digest::MD5.hexdigest(context_json)

    Rails.cache.fetch([RailsReactViews::digest, :rails_react_views, :prerenderer, :prerender, context_digest]) do
      process_prerender(context_json)
    end
  else
    process_prerender(context_json)
  end
end