class TableRowComponent

TableRowComponent represents an HTML table row generated from an Enumerable collection.

Attributes in an TableRowComponent are separated into multiple groups since there are multiple kinds of tags. These groups are:

For example, to have a row with 20px padding and the class of “table-cell” given to each cell, you could write: “` TableRowComponent.new(data, attributes:

{row: {style: "padding: 20px"}, cell: {class: "list-item"}})

“` which is equivalent to “` <tr style=“padding: 20px”>

<td class="list-item">...</td>
<td class="list-item">...</td>
...

</tr> “`

Public Class Methods

new(data, attributes: {}, &block) click to toggle source

Creates a new instance of TableRowComponent from the values of data.

If a block is given, each item in data is passed to it to render the row cells. If no block is given, data are used directly.

# File lib/html-native/collections.rb, line 219
def initialize(data, attributes: {}, &block)
  @data = data
  @row_attributes = attributes[:row] || {}
  @cell_attributes = attributes[:cell] || {}
  @block = block
end

Public Instance Methods

render() click to toggle source

Converts the TableRowComponent 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 231
def render
  tr(@row_attributes) do
    @data.component_map do |c|
      td(@cell_attributes) {@block ? @block.call(c) : c}
    end
  end
end