Ruby method signatures enforce required data and sets defaults
class TailwindNav < Phlex::HTML
def initialize(title: "Main Menu")
@title = title
end
def view_template(&content)
h2(class: "font-bold") { @title }
nav(class: "flex flex-row gap-4", &content)
end
def item(url, &content)
a(href: url, class: "text-underline", &content)
end
end
render TailwindNav.new title: "Site Menu" do |it|
it.item("/") { "Home" }
it.item("/about") { "About" }
it.item("/contact") { "Contact" }
end