Sha256: 213180f80524f5beaa63c7250daeaab08dfd465c3858315da89af48aea9a0a17

Contents?: true

Size: 1.99 KB

Versions: 11

Compression:

Stored size: 1.99 KB

Contents

module Turbo::FramesHelper
  # Returns a frame tag that can either be used simply to encapsulate frame content or as a lazy-loading container that starts empty but
  # fetches the URL supplied in the +src+ attribute.
  #
  # ==== Examples
  #
  #   <%= turbo_frame_tag "tray", src: tray_path(tray) %>
  #   # => <turbo-frame id="tray" src="http://example.com/trays/1"></turbo-frame>
  #
  #   <%= turbo_frame_tag tray, src: tray_path(tray) %>
  #   # => <turbo-frame id="tray_1" src="http://example.com/trays/1"></turbo-frame>
  #
  #   <%= turbo_frame_tag "tray", src: tray_path(tray), target: "_top" %>
  #   # => <turbo-frame id="tray" target="_top" src="http://example.com/trays/1"></turbo-frame>
  #
  #   <%= turbo_frame_tag "tray", target: "other_tray" %>
  #   # => <turbo-frame id="tray" target="other_tray"></turbo-frame>
  #
  #   <%= turbo_frame_tag "tray", src: tray_path(tray), loading: "lazy" %>
  #   # => <turbo-frame id="tray" src="http://example.com/trays/1" loading="lazy"></turbo-frame>
  #
  #   <%= turbo_frame_tag "tray" do %>
  #     <div>My tray frame!</div>
  #   <% end %>
  #   # => <turbo-frame id="tray"><div>My tray frame!</div></turbo-frame>
  #
  #   <%= turbo_frame_tag [user_id, "tray"], src: tray_path(tray) %>
  #   # => <turbo-frame id="1_tray" src="http://example.com/trays/1"></turbo-frame>
  #
  # The +turbo_frame_tag+ helper will convert the arguments it receives to their
  # +dom_id+ if applicable to easily generate unique ids for Turbo Frames:
  #
  #   <%= turbo_frame_tag(Article.find(1)) %>
  #   # => <turbo-frame id="article_1"></turbo-frame>
  #
  #   <%= turbo_frame_tag(Article.find(1), "comments") %>
  #   # => <turbo-frame id="comments_article_1"></turbo-frame>
  def turbo_frame_tag(*ids, src: nil, target: nil, **attributes, &block)
    id = ids.first.respond_to?(:to_key) ? ActionView::RecordIdentifier.dom_id(*ids) : ids.join('_')
    src = url_for(src) if src.present?

    tag.turbo_frame(**attributes.merge(id: id, src: src, target: target).compact, &block)
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
turbo-rails-2.0.11 app/helpers/turbo/frames_helper.rb
turbo-rails-2.0.10 app/helpers/turbo/frames_helper.rb
turbo-rails-2.0.9 app/helpers/turbo/frames_helper.rb
turbo-rails-2.0.8 app/helpers/turbo/frames_helper.rb
turbo-rails-2.0.7 app/helpers/turbo/frames_helper.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/turbo-rails-2.0.5/app/helpers/turbo/frames_helper.rb
turbo-rails-2.0.6 app/helpers/turbo/frames_helper.rb
turbo-rails-2.0.5 app/helpers/turbo/frames_helper.rb
turbo-rails-2.0.4 app/helpers/turbo/frames_helper.rb
turbo-rails-2.0.3 app/helpers/turbo/frames_helper.rb
turbo-rails-2.0.2 app/helpers/turbo/frames_helper.rb