Module: TurboFlow::Helpers

Defined in:
lib/turboflow/helpers.rb

Instance Method Summary collapse

Instance Method Details

#button_flow_to(name = nil, options = nil, html_options = nil, &block) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/turboflow/helpers.rb', line 61

def button_flow_to(name = nil, options = nil, html_options = nil, &block)
  if block_given?
    html_options = options || {}
    options = name
    name = capture(&block)
  else
    html_options ||= {}
  end

  flow = html_options.delete(:flow)
  html_options["data-turbo-flow"] = flow.to_s if flow

  button_to(name, options, html_options)
end


46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/turboflow/helpers.rb', line 46

def link_flow_to(name = nil, options = nil, html_options = nil, &block)
  if block_given?
    html_options = options || {}
    options = name
    name = capture(&block)
  else
    html_options ||= {}
  end

  flow = html_options.delete(:flow)
  html_options["data-turbo-flow"] = flow.to_s if flow

  link_to(name, options, html_options)
end

#turboflow_body_tag(options = {}, &block) ⇒ Object



17
18
19
# File 'lib/turboflow/helpers.rb', line 17

def turboflow_body_tag(options = {}, &block)
  (:body, options, &block)
end

#turboflow_config_scriptObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/turboflow/helpers.rb', line 21

def turboflow_config_script
  config = TurboFlow.configuration

  javascript_tag do
    "      window.TurboFlowConfig = {\n        defaultTransition: '\#{config.default_transition}',\n        duration: \#{config.duration},\n        easing: '\#{config.easing}',\n        debug: \#{config.debug}\n      };\n\n      if (window.TurboFlow) {\n        window.TurboFlow.configure(window.TurboFlowConfig);\n      } else {\n        document.addEventListener('DOMContentLoaded', function() {\n          if (window.TurboFlow) {\n            window.TurboFlow.configure(window.TurboFlowConfig);\n          }\n        });\n      }\n    JS\n  end\nend\n".html_safe

#turboflow_meta_tagsObject



5
6
7
8
9
10
11
# File 'lib/turboflow/helpers.rb', line 5

def turboflow_meta_tags
  safe_join([
    tag(:meta, name: "view-transition", content: "same-origin"),
    turboflow_config_script,
    turboflow_script_tag
  ])
end

#turboflow_script_tagObject



13
14
15
# File 'lib/turboflow/helpers.rb', line 13

def turboflow_script_tag
  javascript_include_tag("turboflow", "data-turbo-track": "reload")
end