class UnorderedListComponent
UnorderedListComponent
represents an HTML unordered list generated from an Enumerable
collection.
Attributes in an UnorderedListComponent
are separated into multiple groups since there are multiple kinds of tags. These groups are:
-
list - The attributes associated with the <ul> element
-
item - The attributes associated with <li> elements
For example, to have a list with 20px padding and the class of “list-item” given to each item, you could write: “` UnorderedListComponent.new
(data, attributes:
{list: {style: "padding: 20px"}, item: {class: "list-item"}})
“` which is equivalent to “` <ul style=“padding: 20px”>
<li class="list-item">...</li> <li class="list-item">...</li> ...
</ul> “`
Public Class Methods
Creates a new instance of UnorderedListComponent
from the values of data.
If a block is given, each item in data is passed to it to render the list items. If no block is given, data are used directly.
# File lib/html-native/collections.rb, line 120 def initialize(data, attributes: {}, &block) @list_data = data @list_attributes = attributes[:list] || {} @item_attributes = attributes[:item] || {} @block = block end
Public Instance Methods
Converts the UnorderedListComponent
instance to the equivalent HTML.
render can be called directly, but that usually isn't necessary. HTMLComponent::Builder
handles this automatically, so it only needs to be done if there is no prior instance of one.
# File lib/html-native/collections.rb, line 132 def render ul(@list_attributes) do @list_data.component_map do |l| li(@item_attributes) do @block ? @block.call(l) : l end end end end