Class: Eskimo::HTML::Component
- Inherits:
-
Object
- Object
- Eskimo::HTML::Component
- Defined in:
- gems/eskimo-html/lib/eskimo/html/component.rb
Overview
Base HTMLElement component which takes a #tag_name, a set of #attributes, and optionally a set of #children and turns them into a beautiful – believe it or not – HTML tag:
<x-foo <!-- attributes -->>
<!-- children -->
</x-foo>
See ASCII::Component for how this works under the hood since it's similar.
Direct Known Subclasses
A, Abbr, Address, Area, Article, Aside, Audio, B, Base, Bdi, Bdo, Blockquote, Body, Br, Button, Canvas, Caption, Cite, Code, Col, Colgroup, Data, Datalist, Dd, Del, Details, Dfn, Dialog, Div, Dl, Dt, Em, Embed, Fieldset, Figcaption, Figure, Footer, Form, H1, H2, H3, H4, H5, H6, Head, Header, Hgroup, Hr, Html, I, Iframe, Img, Input, Ins, Kbd, Keygen, Label, Legend, Li, Link, Main, Map, Mark, Math, Menu, Menuitem, Meta, Meter, Nav, Noscript, Object, Ol, Optgroup, Option, Output, P, Param, Picture, Pre, Progress, Q, Rb, Rp, Rt, Rtc, Ruby, S, Samp, Script, Section, Select, Slot, Small, Source, Span, Strong, Style, Sub, Summary, Sup, Svg, Table, Tbody, Td, Template, Textarea, Tfoot, Th, Thead, Time, Title, Tr, Track, U, Ul, Var, Video, Wbr
Constant Summary collapse
- ATTRIBUTE_REWRITES =
Mapping of Ruby attribute name to HTML attribute name; some words like “class” are reserved and are problematic when passed as attributes so this hash supports a method to rewrite those.
{ 'className' => 'class' }
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#tag_name ⇒ Object
readonly
Returns the value of attribute tag_name.
Instance Method Summary collapse
-
#initialize(attributes = {}, &children) ⇒ Component
constructor
A new instance of Component.
- #render(render:) ⇒ Object
Constructor Details
#initialize(attributes = {}, &children) ⇒ Component
Returns a new instance of Component
25 26 27 28 |
# File 'gems/eskimo-html/lib/eskimo/html/component.rb', line 25 def initialize(attributes = {}, &children) @attributes = attributes @children = children end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes
21 22 23 |
# File 'gems/eskimo-html/lib/eskimo/html/component.rb', line 21 def attributes @attributes end |
#children ⇒ Object (readonly)
Returns the value of attribute children
22 23 24 |
# File 'gems/eskimo-html/lib/eskimo/html/component.rb', line 22 def children @children end |
#tag_name ⇒ Object (readonly)
Returns the value of attribute tag_name
23 24 25 |
# File 'gems/eskimo-html/lib/eskimo/html/component.rb', line 23 def tag_name @tag_name end |
Instance Method Details
#render(render:) ⇒ Object
30 31 32 33 34 |
# File 'gems/eskimo-html/lib/eskimo/html/component.rb', line 30 def render(render:, **) tag_with_attributes = "#{tag_name} #{serialize_attributes}" "<#{tag_with_attributes.strip}>#{render[@children]}</#{tag_name}>" end |