Class: Glib::JsonUi::TableBuilders::Section

Inherits:
AbstractBuilder show all
Defined in:
app/helpers/glib/json_ui/table_builders.rb

Instance Attribute Summary

Attributes inherited from AbstractBuilder

#json, #page

Instance Method Summary collapse

Constructor Details

#initialize(json, page, template) ⇒ Section

Returns a new instance of Section.



26
27
28
29
# File 'app/helpers/glib/json_ui/table_builders.rb', line 26

def initialize json, page, template
  super json, page
  @template = template
end

Instance Method Details

#header(options = {}) ⇒ Object



31
32
33
34
35
36
37
38
# File 'app/helpers/glib/json_ui/table_builders.rb', line 31

def header(options = {})
  json.header do
    json.backgroundColor options[:backgroundColor]
    json.cellViews do
      options[:cellViews]&.call page.view_builder
    end
  end
end

#rows(options = {}) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/helpers/glib/json_ui/table_builders.rb', line 40

def rows(options = {})
  block = options[:builder]
  json.rows do
    if (objects = options[:objects])
      objects.each_with_index do |object, index|
        block&.call @template, object, index
      end
    else
      block&.call @template
    end
  end
end