ProductCardComponentBlueprint
InfoGenerateCreated ByPackages
This Ruby class, `ProductCardComponent`, inherits from `ApplicationComponent` and is designed to generate HTML for a product card. The card displays a product's name, image, description, and a link to view the product. The component's constructor takes four keyword arguments: `name`, `image_url`, `description`, and `product_url`, which are used to set instance variables. The `template` method constructs a structured HTML representation of the product card, including an image, title, description, and a button linking to the product URL. Noteworthy details include the use of CSS classes for styling and the `frozen_string_literal: true` magic comment at the top of the file, which potentially optimizes string usage in the code.
# frozen_string_literal: true
class ProductCardComponent < ApplicationComponent
def initialize(name:, image_url:, description:, product_url:)
@name = name
@image_url = image_url
@description = description
@product_url = product_url
end
def template
div(class: "card card-compact w-96 bg-base-100 shadow-xl") do
figure { img(src: @image_url, alt: @name) }
div(class: "card-body") do
h2(class: "card-title") { @name }
p { @description }
div(class: "card-actions justify-end") do
a(href: @product_url, class: "btn btn-primary") { "View Product" }
end
end
end
end
end
Try a prompt
Original Prompt:
"a card for my product resource that has a name, an image url, and a description that links to the product page"