app/helpers/trestle/card_helper.rb in trestle-0.10.0 vs app/helpers/trestle/card_helper.rb in trestle-0.10.1

- old
+ new

@@ -1,23 +1,41 @@ module Trestle module CardHelper - def card(options={}, &block) - content_tag(:div, options.slice(:id, :data).merge(class: ["card", options[:class]].compact)) do + # Renders a card container element (sometimes also known as a panel or well), based on + # Bootstrap's card element (https://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. + def card(header: nil, footer: nil, **attributes, &block) + tag.div(**attributes.merge(class: ["card", attributes[:class]])) do safe_join([ - (content_tag(:div, options[:header], class: "card-header") if options[:header]), - content_tag(:div, class: "card-body", &block), - (content_tag(:div, options[:footer], class: "card-footer") if options[:footer]) + (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 - def panel(options={}, &block) + # [DEPRECATED] Alias for card + 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(options.merge(header: options[:title]), &block) + card(**attributes.merge(header: attributes[:title]), &block) end - def well(options={}, &block) + # [DEPRECATED] Alias for card + 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(options, &block) + card(**attributes, &block) end end end