StarWarsChatComponentTemplate

InfoGeneratePackages

The code snippet defines a class named `ChatWithHeaderAndFooterComponent` that inherits from `ApplicationComponent`. This class is likely part of a web application framework, possibly Ruby on Rails or a similar Ruby-based framework. The class contains a `template` method that generates the HTML structure for two chat messages, each enclosed in div elements with class "chat chat-start". Each message comprises three parts: a header displaying "Obi-Wan Kenobi" and a timestamp ("2 hours ago" for the first message and "2 hour ago" for the second, which seems to be a typo), a chat bubble containing the message content ("You were the Chosen One!" for the first message and "I loved you." for the second), and a footer indicating the message status ("Seen" for the first message and "Delivered" for the second). The method uses a domain-specific language (DSL) or a templating system to construct the UI components, characterized by keywords like `div`, `plain`, and `time`, and CSS class names for styling.

# frozen_string_literal: true

class ChatWithHeaderAndFooterComponent < ApplicationComponent
  def template
    div(class: "chat chat-start") do
      div(class: "chat-header") do
        plain "Obi-Wan Kenobi"
        time(class: "text-xs opacity-50") { "2 hours ago" }
      end
      div(class: "chat-bubble") { "You were the Chosen One!" }
      div(class: "chat-footer opacity-50") { "Seen" }
    end
    div(class: "chat chat-start") do
      div(class: "chat-header") do
        plain "Obi-Wan Kenobi"
        time(class: "text-xs opacity-50") { "2 hour ago" }
      end
      div(class: "chat-bubble") { "I loved you." }
      div(class: "chat-footer opacity-50") { "Delivered" }
    end
  end
end