Class: PhlexUI::Table::Builder
- Includes:
- Phlex::DeferredRender
- Defined in:
- lib/phlex_ui/table/builder.rb
Defined Under Namespace
Classes: Column
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #body ⇒ Object
- #caption ⇒ Object
- #column(header, footer = nil, header_attrs: {}, footer_attrs: {}, &block) ⇒ Object
- #footer ⇒ Object
- #header ⇒ Object
-
#initialize(records = [], caption: nil, **attrs) ⇒ Builder
constructor
A new instance of Builder.
- #view_template(&block) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(records = [], caption: nil, **attrs) ⇒ Builder
Returns a new instance of Builder.
9 10 11 12 13 14 |
# File 'lib/phlex_ui/table/builder.rb', line 9 def initialize(records = [], caption: nil, **attrs) @records = records @columns = [] @caption = super(**attrs) end |
Instance Method Details
#body ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/phlex_ui/table/builder.rb', line 47 def body render PhlexUI::Table::Body.new do @records.each do |record| render PhlexUI::Table::Row.new do @columns.each do |column| render PhlexUI::Table::Cell.new do column.block.call(record) end end end end end end |
#caption ⇒ Object
73 74 75 |
# File 'lib/phlex_ui/table/builder.rb', line 73 def render PhlexUI::Table::Caption.new { @caption } end |
#column(header, footer = nil, header_attrs: {}, footer_attrs: {}, &block) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/phlex_ui/table/builder.rb', line 25 def column(header, = nil, header_attrs: {}, footer_attrs: {}, &block) @columns << Column.new( header: header, header_attrs: header_attrs, footer: , footer_attrs: , block: block ) end |
#footer ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/phlex_ui/table/builder.rb', line 61 def render PhlexUI::Table::Footer.new do render PhlexUI::Table::Row.new do @columns.each do |column| render PhlexUI::Table::Head.new(**column.) do column. end end end end end |