module Bezel::Component
A component: a class that renders a piece of HTML, given the HTML its
caller's block made (Html.empty without a block), with
HtmlBuilder#component.
class Card
include Bezel::Component
@title: String
def initialize(@title: String); end
def render(h: Bezel::HtmlBuilder, content: Bezel::Html) -> Void
h.section(class_name: "card") do
h.h2(@title)
h.append(content)
end
end
end
Bezel.html { |h| h.component(Card.new("Hi")) { h.p("body") } }.to_s
# => "<section class=\"card\"><h2>Hi</h2><p>body</p></section>"
Methods
abstract def render(h: Bezel::HtmlBuilder, content: Bezel::Html) -> Void
Writes the component to h, with content where it goes.