Module: Koi::HeaderHelper

Included in:
HeaderComponent
Defined in:
app/helpers/koi/header_helper.rb

Instance Method Summary collapse

Instance Method Details

#actions_list {|Block| ... } ⇒ String?

This helper generates an accessible actions navigation structure with proper ARIA attributes for screen readers. The action items should be provided as content within the block.

Examples:

Basic usage with CRUD and contextual actions

<%= actions_list do %>
  <li><%= link_to "Edit", edit_article_path(article) %></li>
  <li><%= link_to_archive_or_delete(article) %></li>
  <li><%= link_to "Config", articles_config_path(article) %></li>
<% end %>

Parameters:

  • **

    Additional HTML attributes to merge with the default actions attributes

Yields:

  • (Block)

    The block should contain the action items (typically ‘<li>` elements)

Returns:

  • (String, nil)

    Returns the HTML ‘<nav>` element with actions if content is present, nil otherwise

See Also:



44
45
46
47
48
49
50
# File 'app/helpers/koi/header_helper.rb', line 44

def actions_list(**, &)
  return if (content = capture(&)).blank?

  tag.nav(**_koi_actions_attributes(**)) do
    tag.ul(content, class: "actions-list", role: "list")
  end
end

This helper generates an accessible breadcrumb navigation structure with proper ARIA attributes for screen readers. The breadcrumb items should be provided as content within the block.

Examples:

Basic usage with list items

<%= breadcrumb_list do %>
  <li><%= link_to "Home", root_path %></li>
  <li><%= link_to "Products", products_path %></li>
<% end %>

Parameters:

  • **

    Additional HTML attributes to merge with the default breadcrumb attributes

Yields:

  • (Block)

    The block should contain the breadcrumb items (typically ‘<li>` elements)

Returns:

  • (String, nil)

    Returns the HTML ‘<nav>` element with breadcrumbs if content is present, nil otherwise

See Also:



20
21
22
23
24
25
26
# File 'app/helpers/koi/header_helper.rb', line 20

def breadcrumb_list(**, &)
  return if (content = capture(&)).blank?

  tag.nav(**_koi_breadcrumbs_attributes(**)) do
    tag.ol(content, class: "breadcrumbs-list", role: "list")
  end
end

Conditionally creates an archive or delete link based on the record’s status.

Examples:

Basic usage

<%= link_to_archive_or_delete(user) %>

Parameters:

  • model (ActiveRecord::Base)

    The record to create an archive/delete link for

  • archive_text (String) (defaults to: "Archive")

    Text to display for archive link (default: “Archive”)

  • delete_text (String) (defaults to: "Delete")

    Text to display for delete link (default: “Delete”)

  • confirm (String) (defaults to: "Are you sure?")

    Confirmation message for delete action (default: “Are you sure?”)

  • url (String) (defaults to: polymorphic_path([:admin, model]))

    Target url for delete actions (defaults to admin_<record>_path)

  • **

    Additional HTML attributes to pass to the link

Returns:

  • (String, nil)

    Returns the HTML link element, or nil if record is not persisted

Raises:

  • (ArgumentError)

See Also:



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/helpers/koi/header_helper.rb', line 87

def link_to_archive_or_delete(model,
                              archive_text: "Archive",
                              delete_text: "Delete",
                              confirm: "Are you sure?",
                              url: polymorphic_path([:admin, model]),
                              **)
  raise ArgumentError unless model.respond_to?(:archived?)

  return unless model.persisted?

  if model.archived?
    link_to(delete_text, url, data: { turbo_method: :delete, turbo_confirm: confirm }, **)
  else
    link_to(archive_text, url, data: { turbo_method: :delete }, **)
  end
end

Creates a delete link with confirmation.

Examples:

Basic usage

<%= link_to_delete(user) %>

Parameters:

  • model (ActiveRecord::Base)

    The record to create a delete link for

  • text (String) (defaults to: "Delete")

    Text to display for delete link (default: “Delete”)

  • confirm (String) (defaults to: "Are you sure?")

    Confirmation message for delete action (default: “Are you sure?”)

  • url (String) (defaults to: polymorphic_path([:admin, model]))

    Target url for delete actions (defaults to admin_<record>_path)

  • **

    Additional HTML attributes to pass to the link

Returns:

  • (String, nil)

    Returns the HTML link element, or nil if record is not persisted



63
64
65
66
67
68
69
70
71
# File 'app/helpers/koi/header_helper.rb', line 63

def link_to_delete(model,
                   text = "Delete",
                   confirm: "Are you sure?",
                   url: polymorphic_path([:admin, model]),
                   **)
  return unless model.persisted?

  link_to(text, url, data: { turbo_method: :delete, turbo_confirm: confirm }, **)
end