ProductCardBlueprint

InfoGenerateCreated ByPackages

The given code defines a Ruby class `ProductCardComponent` which inherits from `ApplicationComponent`. This class is used to generate the HTML structure for a product card component in a web application. The `initialize` method takes four parameters: `name`, `image_url`, `description`, and `product_url` which are used to set the instance variables `@name`, `@image_url`, `@description`, and `@product_url`. The `template` method generates the HTML for the product card, which includes a div container with a specific CSS class, an image, a title, a description, and a link to view the product. The generated HTML consists of a card with the product's image, name, description, and a

# 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