Module: InertiaRails::Helper

Defined in:
lib/inertia_rails/helper.rb

Instance Method Summary collapse

Instance Method Details

#inertia_headersObject



9
10
11
12
13
14
# File 'lib/inertia_rails/helper.rb', line 9

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



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

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



20
21
22
# File 'lib/inertia_rails/helper.rb', line 20

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

#inertia_rendering?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/inertia_rails/helper.rb', line 16

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

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



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

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



5
6
7
# File 'lib/inertia_rails/helper.rb', line 5

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