Class: Glib::JsonUi::PageHelper::Page

Inherits:
Object
  • Object
show all
Defined in:
app/helpers/glib/json_ui/page_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json, context) ⇒ Page

Returns a new instance of Page.



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/helpers/glib/json_ui/page_helper.rb', line 26

def initialize json, context
  @json = json
  @context = context

  @view_builder = ViewBuilder.new(json, self, true)
  @action_builder = ActionBuilder.new(json, self)
  @menu_builder = MenuBuilder.new(json, self)

  @list_section_builder = ListBuilders::Section.new(json, self, ListBuilders::Template.new(json, self))
  @drawer_content_builder = ListBuilders::Section.new(json, self, @menu_builder)
  @table_section_builder = TableBuilders::Section.new(json, self, TableBuilders::Template.new(json, self))
  @split_content_builder = SplitBuilders::Content.new(json, self, @view_builder)
end

Instance Attribute Details

#action_builderObject (readonly)

Returns the value of attribute action_builder.



20
21
22
# File 'app/helpers/glib/json_ui/page_helper.rb', line 20

def action_builder
  @action_builder
end

#contextObject (readonly)

Returns the value of attribute context.



20
21
22
# File 'app/helpers/glib/json_ui/page_helper.rb', line 20

def context
  @context
end

#current_formObject

See Panels::Form



24
25
26
# File 'app/helpers/glib/json_ui/page_helper.rb', line 24

def current_form
  @current_form
end

#drawer_content_builderObject (readonly)

Returns the value of attribute drawer_content_builder.



21
22
23
# File 'app/helpers/glib/json_ui/page_helper.rb', line 21

def drawer_content_builder
  @drawer_content_builder
end

#jsonObject (readonly)

Returns the value of attribute json.



20
21
22
# File 'app/helpers/glib/json_ui/page_helper.rb', line 20

def json
  @json
end

#list_section_builderObject (readonly)

Returns the value of attribute list_section_builder.



21
22
23
# File 'app/helpers/glib/json_ui/page_helper.rb', line 21

def list_section_builder
  @list_section_builder
end

Returns the value of attribute menu_builder.



20
21
22
# File 'app/helpers/glib/json_ui/page_helper.rb', line 20

def menu_builder
  @menu_builder
end

#split_content_builderObject (readonly)

Returns the value of attribute split_content_builder.



21
22
23
# File 'app/helpers/glib/json_ui/page_helper.rb', line 21

def split_content_builder
  @split_content_builder
end

#table_section_builderObject (readonly)

Returns the value of attribute table_section_builder.



21
22
23
# File 'app/helpers/glib/json_ui/page_helper.rb', line 21

def table_section_builder
  @table_section_builder
end

#view_builderObject (readonly)

Returns the value of attribute view_builder.



20
21
22
# File 'app/helpers/glib/json_ui/page_helper.rb', line 20

def view_builder
  @view_builder
end

Instance Method Details

#body(options = {}) ⇒ Object



83
84
85
86
87
# File 'app/helpers/glib/json_ui/page_helper.rb', line 83

def body(options = {})
  json.body do
    vertical_content(options)
  end
end

#data(options = {}) ⇒ Object



119
120
121
# File 'app/helpers/glib/json_ui/page_helper.rb', line 119

def data(options = {})
  options[:content].call(ViewBuilder.new(json, self, false))
end


77
78
79
80
81
# File 'app/helpers/glib/json_ui/page_helper.rb', line 77

def footer(options = {})
  json.footer do
    vertical_content(options)
  end
end

#form(options = {}) ⇒ Object



113
114
115
116
117
# File 'app/helpers/glib/json_ui/page_helper.rb', line 113

def form(options = {})
  scroll childViews: ->(scroll) do
    @view_builder.add_view('panels_form', options.reverse_merge(width: 'matchParent'))
  end
end

#header(options = {}) ⇒ Object



71
72
73
74
75
# File 'app/helpers/glib/json_ui/page_helper.rb', line 71

def header(options = {})
  json.header do
    vertical_content(options)
  end
end

#leftDrawer(options = {}) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/helpers/glib/json_ui/page_helper.rb', line 50

def leftDrawer(options = {})
  # json.leftDrawer do
  #   json.title options[:title]
  #   json.items do
  #     yield @menu_builder
  #   end
  # end

  json.leftDrawer do
    options[:content]&.call drawer_content_builder
  end
end

#list(options = {}) ⇒ Object



89
90
91
92
93
94
95
# File 'app/helpers/glib/json_ui/page_helper.rb', line 89

def list(options = {})
  json.body do
    json.childViews do
      @view_builder.add_view('panels_list', options.reverse_merge(width: 'matchParent'))
    end
  end
end


63
64
65
66
67
68
69
# File 'app/helpers/glib/json_ui/page_helper.rb', line 63

def navBar(options = {})
  json.navBar do
    json.rightItems do
      options[:rightItems]&.call @menu_builder
    end
  end
end

#rightNavButtonsObject



40
41
42
43
44
# File 'app/helpers/glib/json_ui/page_helper.rb', line 40

def rightNavButtons
  json.rightNavButtons do
    yield @menu_builder
  end
end

#scroll(options = {}) ⇒ Object



105
106
107
108
109
110
111
# File 'app/helpers/glib/json_ui/page_helper.rb', line 105

def scroll(options = {})
  json.body do
    json.childViews do
      @view_builder.add_view('panels_scroll', options.reverse_merge(width: 'matchParent'))
    end
  end
end

#table(options = {}) ⇒ Object



97
98
99
100
101
102
103
# File 'app/helpers/glib/json_ui/page_helper.rb', line 97

def table(options = {})
  json.body do
    json.childViews do
      @view_builder.add_view('panels_table', options.reverse_merge(width: 'matchParent'))
    end
  end
end

#template(template) ⇒ Object



46
47
48
# File 'app/helpers/glib/json_ui/page_helper.rb', line 46

def template(template)
  json.template template
end

#vertical_content(options) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'app/helpers/glib/json_ui/page_helper.rb', line 123

def vertical_content(options)
  options = options.reverse_merge(width: 'matchParent')

  [:padding, :backgroundColor, :width, :height, :align].each do |name|
    if (value = options.delete(name))
      json.set! name, value
    end
  end
  json.childViews do
    if (childViews = options.delete(:childViews))
      childViews.call @view_builder
    end
  end

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