Module: InertiaRails::Helper

Defined in:
lib/inertia_rails/helper.rb

Instance Method Summary collapse

Instance Method Details

#inertia_headersObject



11
12
13
14
15
16
# File 'lib/inertia_rails/helper.rb', line 11

def inertia_headers
  InertiaRails.deprecator.warn(
    '`inertia_headers` is deprecated and will be removed in InertiaRails 4.0, use `inertia_ssr_head` instead.'
  )
  inertia_ssr_head
end

#inertia_meta_tagsObject



26
27
28
29
30
31
32
33
34
# File 'lib/inertia_rails/helper.rb', line 26

def inertia_meta_tags
  meta_tag_data = (inertia_page || {}).dig(:props, :_inertia_meta) || []

  meta_tags = meta_tag_data.map do |inertia_meta_tag|
    inertia_meta_tag.to_tag(tag)
  end

  safe_join(meta_tags, "\n")
end

#inertia_pageObject



22
23
24
# File 'lib/inertia_rails/helper.rb', line 22

def inertia_page
  controller.instance_variable_get('@_inertia_page')
end

#inertia_rendering?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/inertia_rails/helper.rb', line 18

def inertia_rendering?
  controller.instance_variable_get('@_inertia_rendering')
end

#inertia_root(id: nil, page: inertia_page) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/inertia_rails/helper.rb', line 36

def inertia_root(id: nil, page: inertia_page)
  config = controller.send(:inertia_configuration)
  id ||= config.root_dom_id

  if config.use_script_element_for_initial_page
    safe_join([
                tag.script(page.to_json.html_safe, 'data-page': id, type: 'application/json'),
                tag.div(id: id)
              ], "\n")
  else
    tag.div(id: id, 'data-page': page.to_json)
  end
end

#inertia_ssr_headObject



7
8
9
# File 'lib/inertia_rails/helper.rb', line 7

def inertia_ssr_head
  controller.instance_variable_get('@_inertia_ssr_head')
end