Module: TurboFlow::Helpers
- Defined in:
- lib/turboflow/helpers.rb
Instance Method Summary collapse
- #button_flow_to(name = nil, options = nil, html_options = nil, &block) ⇒ Object
- #link_flow_to(name = nil, options = nil, html_options = nil, &block) ⇒ Object
- #turboflow_body_tag(options = {}, &block) ⇒ Object
- #turboflow_config_script ⇒ Object
- #turboflow_meta_tags ⇒ Object
- #turboflow_script_tag ⇒ Object
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 (name = nil, = nil, = nil, &block) if block_given? = || {} = name name = capture(&block) else ||= {} end flow = .delete(:flow) ["data-turbo-flow"] = flow.to_s if flow (name, , ) end |
#link_flow_to(name = nil, options = nil, html_options = nil, &block) ⇒ Object
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, = nil, = nil, &block) if block_given? = || {} = name name = capture(&block) else ||= {} end flow = .delete(:flow) ["data-turbo-flow"] = flow.to_s if flow link_to(name, , ) end |
#turboflow_body_tag(options = {}, &block) ⇒ Object
17 18 19 |
# File 'lib/turboflow/helpers.rb', line 17 def turboflow_body_tag( = {}, &block) content_tag(:body, , &block) end |
#turboflow_config_script ⇒ Object
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_tags ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/turboflow/helpers.rb', line 5 def safe_join([ tag(:meta, name: "view-transition", content: "same-origin"), turboflow_config_script, turboflow_script_tag ]) end |
#turboflow_script_tag ⇒ Object
13 14 15 |
# File 'lib/turboflow/helpers.rb', line 13 def turboflow_script_tag javascript_include_tag("turboflow", "data-turbo-track": "reload") end |