module Turbo::DriveHelper
def turbo_exempts_page_from_cache
Pages that are more likely than not to be a cache miss can skip turbo cache to avoid visual jitter.
def turbo_exempts_page_from_cache provide :head, turbo_exempts_page_from_cache_tag end
def turbo_exempts_page_from_cache_tag
def turbo_exempts_page_from_cache_tag tag.meta(name: "turbo-cache-control", content: "no-cache") end
def turbo_exempts_page_from_preview
Specify that a cached version of the page should not be shown as a preview during an application visit.
def turbo_exempts_page_from_preview provide :head, turbo_exempts_page_from_preview_tag end
def turbo_exempts_page_from_preview_tag
def turbo_exempts_page_from_preview_tag tag.meta(name: "turbo-cache-control", content: "no-preview") end
def turbo_page_requires_reload
def turbo_page_requires_reload provide :head, turbo_page_requires_reload_tag end
def turbo_page_requires_reload_tag
def turbo_page_requires_reload_tag tag.meta(name: "turbo-visit-control", content: "reload") end
def turbo_refresh_method_tag(method = :replace)
def turbo_refresh_method_tag(method = :replace) raise ArgumentError, "Invalid refresh option '#{method}'" unless method.in?(%i[ replace morph ]) tag.meta(name: "turbo-refresh-method", content: method) end
def turbo_refresh_scroll_tag(scroll = :reset)
def turbo_refresh_scroll_tag(scroll = :reset) raise ArgumentError, "Invalid scroll option '#{scroll}'" unless scroll.in?(%i[ reset preserve ]) tag.meta(name: "turbo-refresh-scroll", content: scroll) end
def turbo_refreshes_with(method: :replace, scroll: :reset)
==== Example Usage:
* +preserve:+: Keeps the scroll.
* +reset:+: Resets scroll to the top, left corner. This is the default.
can be one of:
* scroll - Controls the scroll behavior when a page refresh happens. It
* +morph:+: Morphs the existing ++ into the new one.
default behavior.
* +replace:+: Replaces the existing ++ with the new one. This is the
during a page refresh. It can be one of:
* method - Method to update the ++ of the page
==== Parameters:
Turbo loads the current page again with a *replace* visit:
Configure how to handle page refreshes. A page refresh happens when
def turbo_refreshes_with(method: :replace, scroll: :reset) provide :head, turbo_refresh_method_tag(method) provide :head, turbo_refresh_scroll_tag(scroll) end