abstract class Components::Elements::ContainerElement

Overview

Base class for container HTML elements that can have children

Direct Known Subclasses

Defined in:

components/elements/base/container_element.cr

Constructors

Instance Method Summary

Instance methods inherited from class Components::Elements::HTMLElement

[](name : String) : String | Nil [], add_class(class_names : String) : self add_class, add_style(styles : String) : self add_style, attributes : Hash(String, String) attributes, can_have_children? : Bool can_have_children?, children : Array(HTMLElement | String | RawHTML) children, has_class?(class_name : String) : Bool has_class?, remove_attribute(name : String) : self remove_attribute, remove_class(class_names : String) : self remove_class, render : String render, set_attribute(name : String, value : String | Nil) : self set_attribute, set_safe_style(style : SafeStyleValue) : self set_safe_style, set_safe_url_attribute(name : String, url : SafeURL) : self set_safe_url_attribute, tag_name : String tag_name, to_s(io : IO) : Nil to_s, void_element? : Bool void_element?

Constructor methods inherited from class Components::Elements::HTMLElement

new(tag_name : String, **attrs) new

Constructor Detail

def self.new(tag_name : String, **attrs) #

[View source]

Instance Method Detail

def <<(child : ContainerElement) : ContainerElement #

Add a container element child and return the child for chaining This enables patterns like: parent << Child.new << "text" where "text" becomes a child of Child, not parent


[View source]
def <<(child : VoidElement | String | RawHTML) : self #

Add text content, void elements, or raw HTML and return self for chaining This enables patterns like: element << "One" << "Two" << "Three"


[View source]
def add_child(child : HTMLElement | String | RawHTML) : self #

Add a child element or text content


[View source]
def add_children(*children : HTMLElement | String | RawHTML) : self #

Add multiple children at once


[View source]
def add_raw_html(html : String) : self #

Add raw HTML content (not escaped)


[View source]
def build(&block : self -> Nil) : self #

Build content using a block


[View source]
def children_count : Int32 #

Get the number of children


[View source]
def clear : self #

Clear all children


[View source]
def empty? : Bool #

Check if element has children


[View source]
def render : String #

Render the complete element with opening tag, children, and closing tag


[View source]