Module: Trestle::CardHelper

Defined in:
app/helpers/trestle/card_helper.rb

Instance Method Summary collapse

Instance Method Details

#card(header: nil, footer: nil, **attributes, &block) ⇒ Object

Renders a card container element (sometimes also known as a panel or well), based on Bootstrap’s card element (getbootstrap.com/docs/5.3/components/card/).

header - Optional header to add within a .card-header footer - Optional footer to add within a .card-footer attributes - Additional HTML attributes to add to the container <div> tag

Examples

<%= card do %>

<p>Card content here...</p>

<% end %>

<%= card header: “Header”, footer: “Footer”, class: “text-bg-primary” do %>…

Returns a HTML-safe String.



19
20
21
22
23
24
25
26
27
# File 'app/helpers/trestle/card_helper.rb', line 19

def card(header: nil, footer: nil, **attributes, &block)
  tag.div(**attributes.merge(class: ["card", attributes[:class]])) do
    safe_join([
      (tag.header(header, class: "card-header") if header),
      tag.div(class: "card-body", &block),
      (tag.footer(footer, class: "card-footer") if footer)
    ].compact)
  end
end

#panel(**attributes, &block) ⇒ Object

DEPRECATED

Alias for card



30
31
32
33
# File 'app/helpers/trestle/card_helper.rb', line 30

def panel(**attributes, &block)
  Trestle.deprecator.warn("The panel helper is deprecated and will be removed in future versions of Trestle. Please use the card helper instead.")
  card(**attributes.merge(header: attributes[:title]), &block)
end

#well(**attributes, &block) ⇒ Object

DEPRECATED

Alias for card



36
37
38
39
# File 'app/helpers/trestle/card_helper.rb', line 36

def well(**attributes, &block)
  Trestle.deprecator.warn("The well helper is deprecated and will be removed in future versions of Trestle. Please use the card helper instead.")
  card(**attributes, &block)
end