Class: Katalyst::Kpop::Turbo::TagBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/katalyst/kpop/turbo.rb

Instance Method Summary collapse

Constructor Details

#initialize(builder) ⇒ TagBuilder

Returns a new instance of TagBuilder.



9
10
11
# File 'lib/katalyst/kpop/turbo.rb', line 9

def initialize(builder)
  @builder = builder
end

Instance Method Details

#dismiss(id: "kpop") ⇒ Object

Render a turbo stream action that will dismiss any open kpop modal.



29
30
31
# File 'lib/katalyst/kpop/turbo.rb', line 29

def dismiss(id: "kpop")
  turbo_stream_action_tag(:kpop_dismiss, target: id)
end

#open(content = nil, id: "kpop") ⇒ Object

Open a modal in the kpop frame identified by id either the content passed in or a rendering result determined by the rendering keyword arguments, the content in the block, or the rendering of the content as a record. Examples:

<%= turbo_stream.kpop.open modal %>
<%= turbo_stream.kpop.open partial: "modals/modal", locals: { record: } %>
<%= turbo_stream.kpop.open do %>
  <%= render Kpop::ModalComponent.new(title: "Example") do %>
    ...
  <% end %>
<% end %>


24
25
26
# File 'lib/katalyst/kpop/turbo.rb', line 24

def open(content = nil, id: "kpop", **, &)
  action(:kpop_open, id, content, **, &)
end

#redirect_to(href, id: "kpop", action: "replace", target: nil) ⇒ Object

Renders a kpop redirect controller response that will escape the frame and navigate to the given URL. Note: turbo does not currently snapshot page history accurately when using “advance” (Oct 23).



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/katalyst/kpop/turbo.rb', line 35

def redirect_to(href, id: "kpop", action: "replace", target: nil)
  turbo_stream_action_tag(
    :kpop_redirect_to,
    target: id,
    href:,
    data:   {
      turbo_action: action,
      turbo_frame:  target,
    },
  )
end