Phlex::HTML
The main class for building HTML views in Phlex. Inherits from Phlex::SGML and provides HTML-specific functionality including void elements, standard elements, and doctype support.Inheritance
Usage
Create a component by subclassingPhlex::HTML and defining a view_template method:
Instance Methods
#doctype
Output an HTML5 doctype declaration.
This outputs the HTML5 doctype:
<!doctype html>#svg(**attributes, &block)
Output an <svg> tag. When given a block, automatically renders the content as an SVG context.
HTML attributes for the svg element
SVG content to render inside the svg element
#tag(name, **attributes, &block)
Output an HTML tag dynamically by name.
Tag name as a symbol (underscores converted to hyphens)
HTML attributes for the element
Content to render inside the element (not allowed for void elements)
#content_type
Returns the MIME type for HTML content.
"text/html"
#filename
Override to provide a filename when serving the HTML file.
nil
HTML Elements
Phlex::HTML includes all standard HTML elements as methods. Elements are automatically generated and can be called with attributes and content:Standard Elements
Elements that can have content:a, abbr, address, article, aside, audio, b, bdi, bdo, blockquote, body, button, canvas, caption, cite, code, colgroup, data, datalist, dd, del, details, dfn, dialog, div, dl, dt, em, fieldset, figcaption, figure, footer, form, h1, h2, h3, h4, h5, h6, head, header, hgroup, html, i, iframe, ins, kbd, label, legend, li, main, map, mark, menu, meter, nav, noscript, object, ol, optgroup, option, output, p, picture, pre, progress, q, rp, rt, ruby, s, samp, script, search, section, select, slot, small, span, strong, style, sub, summary, sup, table, tbody, td, template, textarea, tfoot, th, thead, time, title, tr, u, ul, var, video
Void Elements
Elements that cannot have content (self-closing):area, br, col, embed, hr, img, input, link, meta, source, track, wbr
Common Patterns
Complete HTML Page
Form with Input Elements
Embedding SVG
Dynamic Tags
See Also
- Phlex::SGML - Base class with core rendering functionality
- Phlex::SVG - SVG-specific component class
- Phlex::CSV - CSV generation class