ProductCardBlueprint
InfoGenerateCreated ByPackages
This Ruby class, `ProductCardComponent`, extends the `ApplicationComponent` and is designed to represent a product card in a web application. The class initializes with four attributes: `product_name`, `image_url`, `description`, and `product_url`. These attributes are used to render a structured HTML representation of a product card which includes the product image, name, description, and a link to view the product. The rendered card is styled using specific CSS classes to ensure a consistent and visually appealing layout. The class makes use of HTML tags and attributes within the template method to generate the final HTML output.
# frozen_string_literal: true
class ProductCardComponent < ApplicationComponent
def initialize(product_name:, image_url:, description:, product_url:)
@product_name = product_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: @product_name) }
div(class: "card-body") do
h2(class: "card-title") { @product_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"