Module: Hypernova::ControllerHelpers

Includes:
PluginHelper
Defined in:
lib/hypernova/controller_helpers.rb

Overview

Mixin. Implements the high-level rails helper interface. Currently untested.

Instance Method Summary collapse

Methods included from PluginHelper

#after_response, #get_view_data, #on_error, #on_success, #prepare_request, #send_request?, #will_send_request

Instance Method Details

#hypernova_batch_render(job) ⇒ Object

enqueue a render into the current request’s hypernova batch



22
23
24
25
26
27
28
29
30
31
# File 'lib/hypernova/controller_helpers.rb', line 22

def hypernova_batch_render(job)
  if @hypernova_batch.nil?
    raise NilBatchError.new('called hypernova_batch_render without calling '\
      'hypernova_batch_before. Check your around_filter for :hypernova_render_support')
  end
  batch_token = @hypernova_batch.render(job)
  template_safe_token = Hypernova.render_token(batch_token)
  @hypernova_batch_mapping[template_safe_token] = batch_token
  template_safe_token
end

#hypernova_render_supportObject

a Rails around_filter to support hypernova batch rendering.



14
15
16
17
18
# File 'lib/hypernova/controller_helpers.rb', line 14

def hypernova_render_support
  hypernova_batch_before
  yield
  hypernova_batch_after
end

#hypernova_serviceObject

Retrieve a handle to a hypernova service OVERRIDE IN YOUR IMPLEMENTATION CLASS TO GET A DIFFERENT SERVICE



56
57
58
# File 'lib/hypernova/controller_helpers.rb', line 56

def hypernova_service
  @_hypernova_service ||= Hypernova::RequestService.new
end

#render_react_component(component, data = {}) ⇒ Object

shortcut method to render a react component :^)k|8 <– this is a chill peep riding a skateboard

Parameters:

  • name (String)

    the hypernova bundle name, like ‘packages/p3/foo.bundle.js’ (for now)

  • props (Hash)

    the props to be passed to the component



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/hypernova/controller_helpers.rb', line 38

def render_react_component(component, data = {})
  begin
    new_data = get_view_data(component, data)
  rescue StandardError => e
    on_error(e)
    new_data = data
  end
  job = {
    :data => new_data,
    :name => component,
  }

  hypernova_batch_render(job)
end