abstract class Components::Elements::HTMLElement

Overview

Abstract base class for all HTML elements

Direct Known Subclasses

Defined in:

components/elements/base/html_element.cr

Constructors

Instance Method Summary

Constructor Detail

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

[View source]

Instance Method Detail

def [](name : String) : String | Nil #

Get an attribute value


[View source]
def add_class(class_names : String) : self #

Add CSS classes


[View source]
def add_style(styles : String) : self #

Add inline styles


[View source]
def attributes : Hash(String, String) #

[View source]
def can_have_children? : Bool #

Check if this element can contain children


[View source]
def children : Array(HTMLElement | String | RawHTML) #

[View source]
def has_class?(class_name : String) : Bool #

Check if element has a specific class


[View source]
def remove_attribute(name : String) : self #

Remove an attribute


[View source]
def remove_class(class_names : String) : self #

Remove CSS classes


[View source]
abstract def render : String #

Abstract render method to be implemented by subclasses


[View source]
def set_attribute(name : String, value : String | Nil) : self #

Set an attribute with validation


[View source]
def set_safe_style(style : SafeStyleValue) : self #

Sets the style attribute from a validated SafeStyleValue (the output of SafeStyle#build). There is no overload that accepts a bare String for this — that is the "raw style attribute" ban from docs/SAFE_HTML_V1.md.


[View source]
def set_safe_url_attribute(name : String, url : SafeURL) : self #

Sets a URL-bearing attribute (href, src, action, formaction, poster, cite, ping, xlink:href, meta-refresh content, ...) from a validated SafeURL. Scheme validation happened when the SafeURL was constructed (SafeURL.parse!); the value still passes through the normal attribute-escaping path when rendered.


[View source]
def tag_name : String #

[View source]
def to_s(io : IO) : Nil #

Convert to string (alias for render)


[View source]
def void_element? : Bool #

Check if this is a void element


[View source]