ProductCardComponent
This code defines a Ruby class `ProductCardComponent` which inherits from `ApplicationComponent`. The purpose of this class is to render a product card component for a web application. The product card displays the product's image, name, description, and a link to view the product. The class initializes with four attributes: `name`, `image_url`, `description`, and `product_url`, which are used to populate the card. The layout of the card is defined in the `template` method, using HTML tags and classes for styling. Noteworthy details include the use of CSS classes for styling the card (`card`, `card-compact`, `w-96`, `bg-base-100`, `shadow-xl`, `card-body`, `card-title`, `card-actions`, `btn`, and `btn-primary`) and the use of Ruby's ERB syntax for embedding Ruby code within HTML.
# 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