Class: EasyAdmin::Turbo::ResponseComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/easy_admin/turbo/response_component.rb

Instance Method Summary collapse

Methods inherited from BaseComponent

#easy_admin_url_helpers, #helpers, #rails_url_helpers

Methods included from Permissions::Component

#current_user_can?, #current_user_has_role?, #if_can, #if_has_role, #permission_attrs, #permission_button, #permission_case, #permission_classes, #permission_field, #permission_link, #unless_can, #unless_has_role

Methods included from FieldsHelper

#field_component, #render_field

Methods included from DashboardsHelper

#delta_badge_classes, #metric_value_classes, #render_card, #sparkline_color, #sparkline_points, #trend_direction, #trend_icon, #trend_indicator_classes

Constructor Details

#initialize(&block) ⇒ ResponseComponent

Returns a new instance of ResponseComponent.



4
5
6
# File 'app/components/easy_admin/turbo/response_component.rb', line 4

def initialize(&block)
  @builder = block
end

Instance Method Details

#append(target, **attrs, &block) ⇒ Object



18
19
20
# File 'app/components/easy_admin/turbo/response_component.rb', line 18

def append(target, **attrs, &block)
  render StreamComponent.new(action: "append", target: target, **attrs, &block)
end

#prepend(target, **attrs, &block) ⇒ Object



22
23
24
# File 'app/components/easy_admin/turbo/response_component.rb', line 22

def prepend(target, **attrs, &block)
  render StreamComponent.new(action: "prepend", target: target, **attrs, &block)
end

#redirect_to(url) ⇒ Object

Custom action: requires Turbo.StreamActions.redirect in JS



35
36
37
# File 'app/components/easy_admin/turbo/response_component.rb', line 35

def redirect_to(url)
  render StreamComponent.new(action: "redirect", url: url)
end

#remove(target, **attrs) ⇒ Object



26
27
28
# File 'app/components/easy_admin/turbo/response_component.rb', line 26

def remove(target, **attrs)
  render StreamComponent.new(action: "remove", target: target, **attrs)
end

#replace(target, **attrs, &block) ⇒ Object

— Actions API (return component instances, not html_safe strings) —



14
15
16
# File 'app/components/easy_admin/turbo/response_component.rb', line 14

def replace(target, **attrs, &block)
  render StreamComponent.new(action: "replace", target: target, **attrs, &block)
end

#update(target, **attrs, &block) ⇒ Object



30
31
32
# File 'app/components/easy_admin/turbo/response_component.rb', line 30

def update(target, **attrs, &block)
  render StreamComponent.new(action: "update", target: target, **attrs, &block)
end

#view_templateObject



8
9
10
11
# File 'app/components/easy_admin/turbo/response_component.rb', line 8

def view_template
  # The builder receives a small DSL via `yield self`
  @builder&.call(self)
end