glib-web 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3f1f2c691c60bbb4eaa96f531d11385e007d59a6
4
- data.tar.gz: c86e3560a6c66421d717dd3b4527a041ad6e8109
3
+ metadata.gz: 3fd40c51d30eb80d809c785033ed7ae244c56fa8
4
+ data.tar.gz: 5577321d92ee52eccd81fc97de0f8552a7a2d2de
5
5
  SHA512:
6
- metadata.gz: d1e4c57ee97b85249b859605919eb50ada249aea3cd59618c59e2d6e9799e5f08cb5557c80513ac031b591177f6a57a481754e2f660af74bc4797c99e8b66e00
7
- data.tar.gz: 1245782f81ef3925b007b27384d6e8928a3ef68dffeb6f174e92371486078badb4d477b91057f588cdddcfc8d4db38ea091f9aaf4e2146a0d12b108190207631
6
+ metadata.gz: 5c9485ad5172ba38aa1eb01f22b2955f1c0716e5b71da5988370ef726a525cc78e46c4b481e954c1dbee163e2560e6ec90af9670830ccbf3a33260cce5919b00
7
+ data.tar.gz: 7da06f64e20890dc823d5d0ebf39fad5f1594bdb1a6c4544a16cc0588cfdd69a85d15a03ddadab3ea8c77d18b4a3530ae2be3ec4dce06dfb3c6a9f2567d91f69
@@ -44,6 +44,8 @@ module Glib
44
44
  send(k, v)
45
45
  end
46
46
  end
47
+
48
+ created
47
49
  end
48
50
 
49
51
  private
@@ -103,6 +105,11 @@ module Glib
103
105
  json.set! propName, value
104
106
  end
105
107
  end
108
+
109
+ def created
110
+ # To be overridden
111
+ end
112
+
106
113
  end
107
114
  end
108
115
  end
@@ -17,7 +17,7 @@ module Glib
17
17
  def json_body_with_list(json, header = nil, footer = nil, options = {})
18
18
  json.header header
19
19
  json.content do
20
- json.subviews [1] do
20
+ json.childViews [1] do
21
21
  json.view 'panels/list-v1'
22
22
  json.width 'matchParent'
23
23
  json.nextPage options[:nextPage]
@@ -34,7 +34,7 @@ module Glib
34
34
 
35
35
  json.header header
36
36
  json.content do
37
- json.subviews [1] do
37
+ json.childViews [1] do
38
38
  json.view 'panels/scroll-v1'
39
39
  json.width 'matchParent'
40
40
 
@@ -67,7 +67,7 @@ module Glib
67
67
 
68
68
  json.padding options[:padding]
69
69
  json.local options[:local]
70
- json.subviews do
70
+ json.childViews do
71
71
  json.child! do
72
72
  json.view 'fields/hidden-v1'
73
73
  json.name 'authenticity_token'
@@ -26,7 +26,7 @@ module Glib
26
26
  def header(options = {})
27
27
  json.header do
28
28
  json.padding options[:padding]
29
- json.subviews do
29
+ json.childViews do
30
30
  yield page.view_builder
31
31
  end
32
32
  end
@@ -10,6 +10,9 @@ module Glib
10
10
  attr_reader :list_section_builder, :list_template_builder
11
11
  attr_reader :table_section_builder, :table_template_builder
12
12
 
13
+ # See Panels::Form
14
+ attr_accessor :current_form
15
+
13
16
  def initialize json, context
14
17
  @json = json
15
18
  @context = context
@@ -33,7 +36,7 @@ module Glib
33
36
  json.header do
34
37
  json.padding options[:padding]
35
38
  json.backgroundColor options[:backgroundColor]
36
- json.subviews do
39
+ json.childViews do
37
40
  options[:childViews]&.call @view_builder
38
41
  end
39
42
  end
@@ -41,7 +44,7 @@ module Glib
41
44
 
42
45
  def list(options = {})
43
46
  json.content do
44
- json.subviews do
47
+ json.childViews do
45
48
  @view_builder.add_view('panels_list', options.reverse_merge(width: 'matchParent'))
46
49
  end
47
50
  end
@@ -49,7 +52,7 @@ module Glib
49
52
 
50
53
  def table(options = {})
51
54
  json.content do
52
- json.subviews do
55
+ json.childViews do
53
56
  @view_builder.add_view('panels_table', options.reverse_merge(width: 'matchParent'))
54
57
  end
55
58
  end
@@ -57,14 +60,14 @@ module Glib
57
60
 
58
61
  def scroll(options = {})
59
62
  json.content do
60
- json.subviews do
63
+ json.childViews do
61
64
  @view_builder.add_view('panels_scroll', options.reverse_merge(width: 'matchParent'))
62
65
  end
63
66
  end
64
67
  end
65
68
 
66
69
  def form(options = {})
67
- scroll subviews: ->(scroll) do
70
+ scroll childViews: ->(scroll) do
68
71
  @view_builder.add_view('panels_form', options.reverse_merge(width: 'matchParent'))
69
72
  end
70
73
  end
@@ -0,0 +1,63 @@
1
+ class Glib::JsonUi::ViewBuilder
2
+ module Fields
3
+ class AbstractField < View
4
+ string :label
5
+
6
+ def name(name)
7
+ @name = name
8
+ end
9
+
10
+ def value(value)
11
+ @value = value
12
+ end
13
+
14
+ def prop(prop)
15
+ if (form = page.current_form)
16
+ @name ||= form.field_name(prop)
17
+ @value ||= form.field_value(prop)
18
+ end
19
+ end
20
+
21
+ # Override
22
+ def created
23
+ json.name @name
24
+ json.value @value
25
+ end
26
+
27
+ end
28
+
29
+ class Text < AbstractField
30
+ end
31
+
32
+ class Email < Text
33
+ end
34
+
35
+ class Password < Text
36
+ end
37
+
38
+ class Hidden < Text
39
+ end
40
+
41
+ class Textarea < Text
42
+ end
43
+
44
+ class Country < AbstractField
45
+ hash :region
46
+ end
47
+
48
+ class Select < AbstractField
49
+ array :options
50
+ end
51
+
52
+ class RadioGroup < View
53
+ string :name
54
+ views :childViews
55
+ end
56
+
57
+ class Radio < View
58
+ string :label
59
+ string :value
60
+ end
61
+ end
62
+ end
63
+
@@ -0,0 +1,117 @@
1
+ class Glib::JsonUi::ViewBuilder
2
+ module Panels
3
+ class Form < View
4
+ # boolean :local
5
+
6
+ def field_name(prop)
7
+ "#{@model_name}[#{prop}]"
8
+ end
9
+
10
+ def field_value(prop)
11
+ @model.send(prop)
12
+ end
13
+
14
+ def url(url)
15
+ @url = url
16
+ end
17
+
18
+ def method(method)
19
+ @method = method
20
+ end
21
+
22
+ def as(model_name)
23
+ @model_name = model_name
24
+ end
25
+
26
+ def model(models)
27
+ @model = models.is_a?(Array) ? models.last : models
28
+ @model_name ||= @model.class.model_name.singular
29
+ @url ||= page.context.polymorphic_url(models)
30
+ @method ||= if @model.persisted?
31
+ :patch
32
+ else
33
+ :post
34
+ end
35
+ end
36
+
37
+ # Override
38
+ def created
39
+ json.url @url
40
+ json.method @method
41
+ end
42
+
43
+ def childViews(block)
44
+ # insert_method_field = false
45
+ # method = @args[:method].to_sym
46
+ # case method
47
+ # when :patch, :put, :delete
48
+ # json.method :post
49
+ # insert_method_field = true
50
+ # else
51
+ # json.method method
52
+ # end
53
+
54
+ json.childViews do
55
+ json.child! do
56
+ json.view 'fields/hidden-v1'
57
+ json.name 'authenticity_token'
58
+ json.value page.context.form_authenticity_token
59
+ end
60
+
61
+ # if insert_method_field
62
+ # json.child! do
63
+ # json.view 'fields/hidden-v1'
64
+ # json.name '_method'
65
+ # json.value method
66
+ # end
67
+ # end
68
+
69
+ # NOTE: this pattern will not work for views that can be nested. Luckily forms shouldn't be nested anyway.
70
+ page.current_form = self
71
+ block.call(page.view_builder)
72
+ page.current_form = nil
73
+ end
74
+ end
75
+ end
76
+
77
+ class List < View
78
+ hash :nextPage
79
+
80
+ def firstSection(block)
81
+ json.sections [1] do
82
+ block.call page.list_section_builder
83
+ end
84
+ end
85
+ end
86
+
87
+ class Table < View
88
+ def firstSection(block)
89
+ json.sections [1] do
90
+ block.call page.table_section_builder
91
+ end
92
+ end
93
+ end
94
+
95
+ class Scroll < View
96
+ views :childViews
97
+ end
98
+
99
+ class Split < View
100
+ views :leftViews
101
+ views :centerViews
102
+ views :rightViews
103
+ end
104
+
105
+ class Vertical < View
106
+ views :childViews
107
+ string :distribution
108
+ end
109
+
110
+ class Horizontal < View
111
+ views :childViews
112
+ string :distribution
113
+ end
114
+
115
+ end
116
+ end
117
+
@@ -55,113 +55,6 @@ module Glib
55
55
  string :text
56
56
  end
57
57
 
58
- module Fields
59
- class AbstractField < View
60
- string :name
61
- string :label
62
- string :value
63
- end
64
-
65
- class Text < AbstractField
66
- end
67
-
68
- class Email < Text
69
- end
70
-
71
- class Password < Text
72
- end
73
-
74
- class Hidden < Text
75
- end
76
-
77
- class Country < AbstractField
78
- hash :region
79
- end
80
-
81
- class Select < AbstractField
82
- array :options
83
- end
84
-
85
- class RadioGroup < View
86
- string :name
87
- views :childViews
88
- end
89
-
90
- class Radio < View
91
- string :label
92
- string :value
93
- end
94
- end
95
-
96
- module Panels
97
- class Form < View
98
- string :url
99
- string :method
100
- # boolean :local
101
-
102
- def subviews(block)
103
- # insert_method_field = false
104
- # method = @args[:method].to_sym
105
- # case method
106
- # when :patch, :put, :delete
107
- # json.method :post
108
- # insert_method_field = true
109
- # else
110
- # json.method method
111
- # end
112
-
113
- json.subviews do
114
- json.child! do
115
- json.view 'fields/hidden-v1'
116
- json.name 'authenticity_token'
117
- json.value page.context.form_authenticity_token
118
- end
119
-
120
- # if insert_method_field
121
- # json.child! do
122
- # json.view 'fields/hidden-v1'
123
- # json.name '_method'
124
- # json.value method
125
- # end
126
- # end
127
-
128
- block.call(page.view_builder)
129
- end
130
- end
131
- end
132
-
133
- class List < View
134
- hash :nextPage
135
-
136
- def firstSection(block)
137
- json.sections [1] do
138
- block.call page.list_section_builder
139
- end
140
- end
141
- end
142
-
143
- class Table < View
144
- def firstSection(block)
145
- json.sections [1] do
146
- block.call page.table_section_builder
147
- end
148
- end
149
- end
150
-
151
- class Scroll < View
152
- views :subviews
153
- end
154
-
155
- class Split < View
156
- views :leftViews
157
- views :rightViews
158
- end
159
-
160
- class Vertical < View
161
- end
162
-
163
- end
164
-
165
58
  end
166
59
  end
167
60
  end
@@ -5,16 +5,6 @@ render "#{@path_prefix}/nav_menu", json: json
5
5
  json_ui_page json do |page|
6
6
 
7
7
  page.list firstSection: ->(section) do
8
- # section.header(padding: { top: 12, left: 16, right: 16, bottom: 12 }) do |header|
9
- # header.panels_split width: 'matchParent', leftViews: ->(split) do
10
- # split.label text: 'Left'
11
- # end, rightViews: ->(split) do
12
- # split.label text: 'Right'
13
- # end
14
-
15
- # header.fab icon: 'add', onClick: ->(action) { action.alert(message: 'TODO: edit name') }
16
- # end
17
-
18
8
  section.rows do |row|
19
9
  row.thumbnail title: 'dialogs/alert', onClick: ->(action) do
20
10
  action.dialogs_alert message: 'This is an alert'
@@ -2,60 +2,86 @@ json.title 'Home'
2
2
 
3
3
  render "#{@path_prefix}/nav_menu", json: json
4
4
 
5
- json_body_with_list json do
6
- json.rows do
7
- json.child! do
8
- json.template 'thumbnail-v1'
9
- json.title 'Pages'
10
- json.onClick do
11
- json.action 'windows/open-v1'
12
- json.url json_ui_garage_url(path: 'pages/index')
5
+ json_ui_page json do |page|
6
+ page.list firstSection: ->(section) do
7
+ section.rows do |row|
8
+ row.thumbnail title: 'Pages', onClick: ->(action) do
9
+ action.windows_open url: json_ui_garage_url(path: 'pages/index')
13
10
  end
14
- end
15
-
16
- json.child! do
17
- json.template 'thumbnail-v1'
18
- json.title 'Lists'
19
- json.onClick do
20
- json.action 'windows/open-v1'
21
- json.url json_ui_garage_url(path: 'lists/index')
11
+ row.thumbnail title: 'Lists', onClick: ->(action) do
12
+ action.windows_open url: json_ui_garage_url(path: 'lists/index')
22
13
  end
23
- end
24
-
25
- json.child! do
26
- json.template 'thumbnail-v1'
27
- json.title 'Forms'
28
- json.onClick do
29
- json.action 'windows/open-v1'
30
- json.url json_ui_garage_url(path: 'forms/index')
14
+ row.thumbnail title: 'Forms', onClick: ->(action) do
15
+ action.windows_open url: json_ui_garage_url(path: 'forms/index')
31
16
  end
32
- end
33
-
34
- json.child! do
35
- json.template 'thumbnail-v1'
36
- json.title 'Panels'
37
- json.onClick do
38
- json.action 'windows/open-v1'
39
- json.url json_ui_garage_url(path: 'panels/index')
17
+ row.thumbnail title: 'Panels', onClick: ->(action) do
18
+ action.windows_open url: json_ui_garage_url(path: 'panels/index')
40
19
  end
41
- end
42
-
43
- json.child! do
44
- json.template 'thumbnail-v1'
45
- json.title 'Views'
46
- json.onClick do
47
- json.action 'windows/open-v1'
48
- json.url json_ui_garage_url(path: 'views/index')
20
+ row.thumbnail title: 'Views', onClick: ->(action) do
21
+ action.windows_open url: json_ui_garage_url(path: 'views/index')
49
22
  end
50
- end
51
-
52
- json.child! do
53
- json.template 'thumbnail-v1'
54
- json.title 'Actions'
55
- json.onClick do
56
- json.action 'windows/open-v1'
57
- json.url json_ui_garage_url(path: 'actions/index')
23
+ row.thumbnail title: 'Actions', onClick: ->(action) do
24
+ action.windows_open url: json_ui_garage_url(path: 'actions/index')
58
25
  end
59
26
  end
27
+
60
28
  end
61
29
  end
30
+
31
+ # json_body_with_list json do
32
+ # json.rows do
33
+ # json.child! do
34
+ # json.template 'thumbnail-v1'
35
+ # json.title 'Pages'
36
+ # json.onClick do
37
+ # json.action 'windows/open-v1'
38
+ # json.url json_ui_garage_url(path: 'pages/index')
39
+ # end
40
+ # end
41
+
42
+ # json.child! do
43
+ # json.template 'thumbnail-v1'
44
+ # json.title 'Lists'
45
+ # json.onClick do
46
+ # json.action 'windows/open-v1'
47
+ # json.url json_ui_garage_url(path: 'lists/index')
48
+ # end
49
+ # end
50
+
51
+ # json.child! do
52
+ # json.template 'thumbnail-v1'
53
+ # json.title 'Forms'
54
+ # json.onClick do
55
+ # json.action 'windows/open-v1'
56
+ # json.url json_ui_garage_url(path: 'forms/index')
57
+ # end
58
+ # end
59
+
60
+ # json.child! do
61
+ # json.template 'thumbnail-v1'
62
+ # json.title 'Panels'
63
+ # json.onClick do
64
+ # json.action 'windows/open-v1'
65
+ # json.url json_ui_garage_url(path: 'panels/index')
66
+ # end
67
+ # end
68
+
69
+ # json.child! do
70
+ # json.template 'thumbnail-v1'
71
+ # json.title 'Views'
72
+ # json.onClick do
73
+ # json.action 'windows/open-v1'
74
+ # json.url json_ui_garage_url(path: 'views/index')
75
+ # end
76
+ # end
77
+
78
+ # json.child! do
79
+ # json.template 'thumbnail-v1'
80
+ # json.title 'Actions'
81
+ # json.onClick do
82
+ # json.action 'windows/open-v1'
83
+ # json.url json_ui_garage_url(path: 'actions/index')
84
+ # end
85
+ # end
86
+ # end
87
+ # end