glib-web 0.3.13 → 0.4.0

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
  SHA256:
3
- metadata.gz: 483dc48299df91d5551fd4ce401fa1dd654e41ef210b6a7d0e4b04ea5e9c48a4
4
- data.tar.gz: 2d7c3e9b6a3242099c19e20b110926badee014a6865d1f082f9aadf6bea5f80f
3
+ metadata.gz: 7c3733c91f64e84316ffc57ca5b343e2e65d4156e626c4f7df1be6733db3f151
4
+ data.tar.gz: 82242ce70ba7c5be935a9cad09e5fad12ac13e1da8df35fcfe62a0ba1d74d965
5
5
  SHA512:
6
- metadata.gz: 540ee1e2e471fd0dfae4e5137a09088e668149cb71e03488c0e747b1ca998bab76b75e49703c12d8506cff4149b44f75197a2dd99eaba66d195a967508a982e4
7
- data.tar.gz: f641a8945036d40bd336a89b70d41a69a8d26433dda816335c8e1c1f4c2578f3157b2315a63d6d3e021202f1e0bb8d2c86dab76781ee641e130f525488d965b3
6
+ metadata.gz: 85f494238a126745f03329d2cc45e04e048403b811d0f51d7eb49ab0fe267567094650d477e141ac76d99c2ab445dabac8f29fd9743f163ac1cf2a60f3808bec
7
+ data.tar.gz: ae42ea1a360b07361f66012f63e41a65a0ae6ad6cc908f656f3cdab5ede1fc6f75f93a3f82e9af18d7d14056377dc6f2d252841fdfb6ee402c5fe0b87823c6db
@@ -0,0 +1,103 @@
1
+ module Glib::Json::DynamicText
2
+ def __json_dynamic_text_perform
3
+ # if Rails.env.development? && params[:_validate] == 'true'
4
+ if (hash = json_transformation_start).is_a?(Hash)
5
+ @__specs = {}
6
+
7
+ crawl hash['header']&.[]('childViews')
8
+ crawl hash['body']&.[]('childViews')
9
+ crawl hash['footer']&.[]('childViews')
10
+
11
+ translated_texts = retrieve_example_texts(@__specs.keys)
12
+ translated_texts.each do |key, value|
13
+ @__specs[key].each do |spec|
14
+ spec.substitute_with(value)
15
+ end
16
+ end
17
+ end
18
+ # end
19
+ end
20
+
21
+ def retrieve_example_texts(keys)
22
+ examples_translations = {
23
+ 'home.json_ui_garage.hello' => 'Hello {{name}}',
24
+ 'home.json_ui_garage.greeting' => 'Good day!',
25
+ }
26
+
27
+ translated_texts = {}
28
+ keys.each do |key|
29
+ translated_texts[key] = examples_translations[key]
30
+ end
31
+ translated_texts
32
+ end
33
+
34
+ def crawl views
35
+ Glib::Json::DynamicText::crawl_multiple views, ->(view) do
36
+ extract_spec(view, 'text')
37
+ end
38
+ end
39
+
40
+ def extract_spec(view, prop)
41
+ if (spec = view[prop])
42
+ if spec.is_a?(Hash) && (key = spec['dt_key'])
43
+ @__specs[key] ||= []
44
+ @__specs[key] << TextSpec.new(view, prop, spec)
45
+ end
46
+ end
47
+ end
48
+
49
+ TextSpec = Struct.new(:view, :prop, :args) do
50
+ def substitute_with(text)
51
+ view[prop] = text.gsub(/\{\{(\w+)\}\}/) { args.fetch($1, "{{#{$1}}}") }
52
+ end
53
+ end
54
+
55
+ def self.crawl_multiple views, block
56
+ if views.is_a? Array
57
+ views.each do |view|
58
+ crawl_single view, block
59
+ end
60
+
61
+ # views.each do |view|
62
+ # case view['view']
63
+ # when 'panels/form-v1'
64
+ # @@forms << view
65
+ # crawl_single view, block
66
+ # @@forms.pop
67
+ # else
68
+ # crawl_single view, block
69
+ # end
70
+ # end
71
+ end
72
+ end
73
+
74
+ def self.crawl_vertical_content view, block
75
+ crawl_multiple view['childViews'], block if view
76
+ end
77
+
78
+ def self.crawl_single view, block
79
+ block.call view
80
+
81
+ # Generic view children
82
+ crawl_multiple view['childViews'], block
83
+
84
+ # panels/split
85
+ # crawl_multiple view['leftViews'], block
86
+ # crawl_multiple view['rightViews'], block
87
+
88
+ # Split panel
89
+ crawl_vertical_content view['left'], block
90
+ crawl_vertical_content view['center'], block
91
+ crawl_vertical_content view['right'], block
92
+
93
+ # TODO: crawl header and footer
94
+ # Table/List
95
+ if (sections = view['sections']).is_a? Array
96
+ sections.each do |section|
97
+ # Table
98
+ crawl_multiple section['rows'], block
99
+ end
100
+ end
101
+ end
102
+
103
+ end
@@ -44,6 +44,7 @@ module Glib::Json::Libs
44
44
  include Glib::Json::Transformation
45
45
  include Glib::Json::Validation
46
46
  include Glib::Json::Ui
47
+ include Glib::Json::DynamicText
47
48
 
48
49
  before_action :__json_ui_start
49
50
 
@@ -52,6 +53,7 @@ module Glib::Json::Libs
52
53
  __json_ui_commit(options)
53
54
  end
54
55
  after_action :__json_transformation_commit
56
+ after_action :__json_dynamic_text_perform
55
57
  after_action :__json_validate_perform
56
58
  end
57
59
 
@@ -14,5 +14,17 @@ module Glib
14
14
  content = Glib::Text.get_content(new_key, default_value, options: options)
15
15
  content.gsub(/\{\{(\w+)\}\}/) { args.fetch($1.to_sym, "{{#{$1}}}") }
16
16
  end
17
+
18
+ def dt_json(key, default_value = '', **args)
19
+ new_key = key
20
+
21
+ if key.starts_with?('.')
22
+ new_key = "#{controller_name}.#{action_name}#{key}"
23
+ end
24
+
25
+ {
26
+ dt_key: new_key
27
+ }.merge(args)
28
+ end
17
29
  end
18
30
  end
@@ -133,6 +133,13 @@ module Glib
133
133
  end
134
134
  end
135
135
 
136
+ # Support either string or dynamic_text hash
137
+ def self.text propName, options = {}
138
+ define_method(propName) do |value|
139
+ json.set! propName, value
140
+ end
141
+ end
142
+
136
143
  def self.int propName
137
144
  define_method(propName) do |value|
138
145
  json.set! propName, value&.to_i
@@ -82,7 +82,6 @@ module Glib
82
82
  string :body
83
83
  string :tag
84
84
  int :timeout
85
- action :onClick
86
85
  end
87
86
 
88
87
  end
@@ -53,7 +53,8 @@ module Glib
53
53
 
54
54
  class AbstractText < View
55
55
  string :textAlign
56
- string :text
56
+ # string :text
57
+ text :text
57
58
  color :color
58
59
  end
59
60
 
@@ -69,6 +70,12 @@ module Glib
69
70
  class H4 < AbstractText
70
71
  end
71
72
 
73
+ class H5 < AbstractText
74
+ end
75
+
76
+ class H6 < AbstractText
77
+ end
78
+
72
79
  class P < AbstractText
73
80
  end
74
81
 
@@ -157,9 +157,10 @@ class Glib::JsonUi::ViewBuilder
157
157
  end
158
158
 
159
159
  class Column < View
160
- int :lg
161
- int :md
162
- int :sm
160
+ # int :lg
161
+ # int :md
162
+ # int :sm
163
+ hash :lg
163
164
  views :childViews
164
165
  end
165
166
 
@@ -38,6 +38,10 @@ if local_assigns[:top_nav] || json_ui_app_is_web?
38
38
  action.windows_open url: json_ui_garage_url(path: 'tables/index')
39
39
  end
40
40
 
41
+ menu.button text: 'Dynamic Texts', onClick: ->(action) do
42
+ action.windows_open url: json_ui_garage_url(path: 'dynamic_texts/index')
43
+ end
44
+
41
45
  menu.divider
42
46
  menu.label text: 'Misc Menu'
43
47
 
@@ -0,0 +1,11 @@
1
+ json.title 'Dynamic Texts'
2
+
3
+ json_ui_page json do |page|
4
+ render "#{@path_prefix}/nav_menu", json: json, page: page
5
+
6
+ page.scroll padding: glib_json_padding_body, childViews: ->(scroll) do
7
+ scroll.h3 text: dt_json('.hello', name: 'John')
8
+ scroll.label text: dt_json('.greeting')
9
+ end
10
+
11
+ end
@@ -0,0 +1,14 @@
1
+ json.title 'Dynamic Texts'
2
+
3
+ json_ui_page json do |page|
4
+ render "#{@path_prefix}/nav_menu", json: json, page: page, top_nav: true
5
+
6
+ page.list firstSection: ->(section) do
7
+ section.rows builder: ->(template) do
8
+ template.thumbnail title: 'Basic', onClick: ->(action) do
9
+ action.windows_open url: json_ui_garage_url(path: 'dynamic_texts/basic')
10
+ end
11
+ end
12
+
13
+ end
14
+ end
@@ -6,9 +6,7 @@ json_ui_page json do |page|
6
6
  page.list firstSection: ->(section) do
7
7
  section.rows builder: ->(template) do
8
8
  template.thumbnail title: 'Send Desktop Notification', onClick: ->(action) do
9
- action.dialogs_notification title: 'Hello World', body: 'Body Message', onClick: ->(action) do
10
- action.dialogs_alert message: 'TODO'
11
- end
9
+ action.dialogs_notification title: 'Hello World', body: 'Body Message'
12
10
  end
13
11
  end
14
12
  end
@@ -9,7 +9,7 @@ json_ui_page json do |page|
9
9
  scroll.spacer height: 20
10
10
  scroll.h2 text: 'Responsive panel with 12 columns'
11
11
  scroll.spacer height: 6
12
- scroll.panels_responsive childViews: ->(horizontal) do
12
+ scroll.panels_responsive width: 'matchParent', childViews: ->(horizontal) do
13
13
  horizontal.panels_column lg: 8, backgroundColor: '#c3cad2', childViews: ->(column) do
14
14
  column.button text: '1'
15
15
  end
@@ -21,7 +21,7 @@ json_ui_page json do |page|
21
21
  scroll.spacer height: 20
22
22
  scroll.h2 text: 'Responsive panel with more than 12 columns'
23
23
  scroll.spacer height: 6
24
- scroll.panels_responsive childViews: ->(horizontal) do
24
+ scroll.panels_responsive width: 'matchParent', childViews: ->(horizontal) do
25
25
  horizontal.panels_column lg: 4, backgroundColor: '#c3cad2', childViews: ->(column) do
26
26
  column.button text: '1'
27
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glib-web
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.13
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
@@ -40,6 +40,7 @@ files:
40
40
  - app/controllers/concerns/application/json/transformation.rb
41
41
  - app/controllers/concerns/application/json/ui.rb
42
42
  - app/controllers/concerns/application/json/validation.rb
43
+ - app/controllers/concerns/glib/json/dynamic_text.rb
43
44
  - app/controllers/concerns/glib/json/libs.rb
44
45
  - app/controllers/concerns/glib/json/transformation.rb
45
46
  - app/controllers/concerns/glib/json/ui.rb
@@ -65,6 +66,8 @@ files:
65
66
  - app/views/app/views/json_ui/vue/renderer.html.erb
66
67
  - app/views/json_ui/garage/_nav_menu.json.jbuilder
67
68
  - app/views/json_ui/garage/actions/index.json.jbuilder
69
+ - app/views/json_ui/garage/dynamic_texts/basic.json.jbuilder
70
+ - app/views/json_ui/garage/dynamic_texts/index.json.jbuilder
68
71
  - app/views/json_ui/garage/forms/_alert_post_data.json.jbuilder
69
72
  - app/views/json_ui/garage/forms/basic.json.jbuilder
70
73
  - app/views/json_ui/garage/forms/basic_post.json.jbuilder