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.



28
29
30
31
# File 'app/helpers/glib/json_ui/table_builders.rb', line 28

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

Instance Method Details

#header(options = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/helpers/glib/json_ui/table_builders.rb', line 33

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

    json.colSpans options.delete(:colSpans)
  end

  raise "Invalid properties: #{options.keys}" if options.size > 0
end

#rows(options = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/helpers/glib/json_ui/table_builders.rb', line 46

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

  raise "Invalid properties: #{options.keys}" if options.size > 0
end