class OrderedListComponent
OrderedListComponent
represents an HTML ordered list based on an Enumerable
collection.
Attributes in an OrderedListComponent
are separated into multiple groups since there are multiple kinds of tags. These groups are:
-
list - The attributes associated with the <ol> 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: “` OrderedListComponent.new
(data, attributes:
{list: {style: "padding: 20px"}, item: {class: "list-item"}})
“` which is equivalent to “` <ol style=“padding: 20px”>
<li class="list-item">...</li> <li class="list-item">...</li> ...
</ol> “`
Public Class Methods
Creates a new instance of OrderedListComponent
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 67 def initialize(data, attributes: {}, &block) @list_data = data @list_attributes = attributes[:list] || {} @item_attributes = attributes[:item] || {} @block = block end
Public Instance Methods
Converts the OrderedListComponent
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 79 def render ol(@list_attributes) do @list_data.component_map do |l| li(@item_attributes) do @block ? @block.call(l) : l end end end end