glimmer-dsl-opal 0.4.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +56 -0
  3. data/README.md +892 -16
  4. data/VERSION +1 -1
  5. data/app/assets/images/glimmer/images/calendar.gif +0 -0
  6. data/app/assets/images/glimmer/images/ui-icons_222222_256x240.png +0 -0
  7. data/app/assets/images/glimmer/images/ui-icons_444444_256x240.png +0 -0
  8. data/app/assets/images/glimmer/images/ui-icons_555555_256x240.png +0 -0
  9. data/app/assets/images/glimmer/images/ui-icons_777620_256x240.png +0 -0
  10. data/app/assets/images/glimmer/images/ui-icons_777777_256x240.png +0 -0
  11. data/app/assets/images/glimmer/images/ui-icons_cc0000_256x240.png +0 -0
  12. data/app/assets/images/glimmer/images/ui-icons_ffffff_256x240.png +0 -0
  13. data/app/assets/stylesheets/glimmer/glimmer.css +15 -0
  14. data/app/assets/stylesheets/glimmer/jquery-ui.css +1312 -0
  15. data/app/assets/stylesheets/glimmer/jquery-ui.structure.css +886 -0
  16. data/app/assets/stylesheets/glimmer/jquery-ui.theme.css +443 -0
  17. data/app/assets/stylesheets/glimmer/jquery.ui.timepicker.css +57 -0
  18. data/lib/glimmer-dsl-opal.rb +16 -9
  19. data/lib/glimmer-dsl-opal/ext/date.rb +49 -3
  20. data/lib/glimmer-dsl-opal/samples/elaborate/tic_tac_toe.rb +23 -0
  21. data/lib/glimmer-dsl-opal/samples/hello/hello_checkbox.rb +85 -0
  22. data/lib/glimmer-dsl-opal/samples/hello/hello_checkbox_group.rb +68 -0
  23. data/lib/glimmer-dsl-opal/samples/hello/hello_combo.rb +5 -5
  24. data/lib/glimmer-dsl-opal/samples/hello/hello_custom_widget.rb +3 -3
  25. data/lib/glimmer-dsl-opal/samples/hello/hello_date_time.rb +63 -0
  26. data/lib/glimmer-dsl-opal/samples/hello/hello_group.rb +104 -0
  27. data/lib/glimmer-dsl-opal/samples/hello/hello_list_single_selection.rb +1 -1
  28. data/lib/glimmer-dsl-opal/samples/hello/hello_radio.rb +108 -0
  29. data/lib/glimmer-dsl-opal/samples/hello/hello_radio_group.rb +84 -0
  30. data/lib/glimmer-dsl-opal/samples/hello/hello_table.rb +283 -0
  31. data/lib/glimmer-dsl-opal/vendor/jquery-ui-timepicker/GPL-LICENSE.txt +278 -0
  32. data/lib/glimmer-dsl-opal/vendor/jquery-ui-timepicker/MIT-LICENSE.txt +20 -0
  33. data/lib/glimmer-dsl-opal/vendor/jquery-ui-timepicker/jquery.ui.timepicker.css +57 -0
  34. data/lib/glimmer-dsl-opal/vendor/jquery-ui-timepicker/jquery.ui.timepicker.js +1496 -0
  35. data/lib/glimmer-dsl-opal/vendor/jquery-ui/AUTHORS.txt +333 -0
  36. data/lib/glimmer-dsl-opal/vendor/jquery-ui/LICENSE.txt +43 -0
  37. data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_444444_256x240.png +0 -0
  38. data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_555555_256x240.png +0 -0
  39. data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_777620_256x240.png +0 -0
  40. data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_777777_256x240.png +0 -0
  41. data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_cc0000_256x240.png +0 -0
  42. data/lib/glimmer-dsl-opal/vendor/jquery-ui/images/ui-icons_ffffff_256x240.png +0 -0
  43. data/lib/glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.min.css +7 -0
  44. data/lib/glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.min.js +13 -0
  45. data/lib/glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.structure.min.css +5 -0
  46. data/lib/glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.theme.min.css +5 -0
  47. data/lib/glimmer-dsl-opal/vendor/jquery-ui/package.json +74 -0
  48. data/lib/glimmer-dsl-swt.rb +1 -0
  49. data/lib/glimmer/data_binding/element_binding.rb +2 -1
  50. data/lib/glimmer/data_binding/table_items_binding.rb +29 -18
  51. data/lib/glimmer/dsl/opal/block_property_expression.rb +41 -0
  52. data/lib/glimmer/dsl/opal/checkbox_group_selection_data_binding_expression.rb +61 -0
  53. data/lib/glimmer/dsl/opal/custom_widget_expression.rb +8 -6
  54. data/lib/glimmer/dsl/opal/dsl.rb +6 -0
  55. data/lib/glimmer/dsl/opal/property_expression.rb +4 -3
  56. data/lib/glimmer/dsl/opal/radio_group_selection_data_binding_expression.rb +61 -0
  57. data/lib/glimmer/dsl/opal/shell_expression.rb +7 -2
  58. data/lib/glimmer/dsl/opal/widget_expression.rb +6 -1
  59. data/lib/glimmer/engine.rb +9 -0
  60. data/lib/glimmer/swt.rb +3 -3
  61. data/lib/glimmer/swt/button_proxy.rb +16 -2
  62. data/lib/glimmer/swt/checkbox_proxy.rb +81 -0
  63. data/lib/glimmer/swt/color_proxy.rb +45 -45
  64. data/lib/glimmer/swt/combo_proxy.rb +6 -6
  65. data/lib/glimmer/swt/composite_proxy.rb +2 -2
  66. data/lib/glimmer/swt/custom/checkbox_group.rb +142 -0
  67. data/lib/glimmer/swt/custom/radio_group.rb +143 -0
  68. data/lib/glimmer/swt/date_time_proxy.rb +145 -0
  69. data/lib/glimmer/swt/display_proxy.rb +6 -2
  70. data/lib/glimmer/swt/fill_layout_proxy.rb +1 -1
  71. data/lib/glimmer/swt/grid_layout_proxy.rb +19 -8
  72. data/lib/glimmer/swt/group_proxy.rb +38 -0
  73. data/lib/glimmer/swt/label_proxy.rb +27 -7
  74. data/lib/glimmer/swt/layout_data_proxy.rb +39 -21
  75. data/lib/glimmer/swt/layout_proxy.rb +4 -4
  76. data/lib/glimmer/swt/list_proxy.rb +3 -3
  77. data/lib/glimmer/swt/make_shift_shell_proxy.rb +4 -4
  78. data/lib/glimmer/swt/message_box_proxy.rb +10 -8
  79. data/lib/glimmer/swt/property_owner.rb +2 -2
  80. data/lib/glimmer/swt/radio_proxy.rb +82 -0
  81. data/lib/glimmer/swt/row_layout_proxy.rb +33 -10
  82. data/lib/glimmer/swt/scrolled_composite_proxy.rb +20 -0
  83. data/lib/glimmer/swt/shell_proxy.rb +29 -9
  84. data/lib/glimmer/swt/tab_folder_proxy.rb +5 -5
  85. data/lib/glimmer/swt/tab_item_proxy.rb +7 -7
  86. data/lib/glimmer/swt/table_column_proxy.rb +62 -12
  87. data/lib/glimmer/swt/table_item_proxy.rb +14 -7
  88. data/lib/glimmer/swt/table_proxy.rb +225 -16
  89. data/lib/glimmer/swt/text_proxy.rb +50 -2
  90. data/lib/glimmer/swt/widget_proxy.rb +88 -39
  91. data/lib/glimmer/ui/custom_widget.rb +8 -8
  92. data/lib/net/http.rb +1 -5
  93. data/lib/uri.rb +3 -3
  94. metadata +56 -9
  95. data/lib/glimmer/data_binding/ext/observable_model.rb +0 -40
@@ -17,6 +17,7 @@ end
17
17
  class File
18
18
  class << self
19
19
  def read(*args, &block)
20
+ # TODO implement via asset downloads in the future
20
21
  # No Op in Opal
21
22
  end
22
23
  end
@@ -4,6 +4,7 @@ require 'glimmer/data_binding/observer'
4
4
  module Glimmer
5
5
  module DataBinding
6
6
  class ElementBinding
7
+ # TODO consider renaming to WidgetBinding since it's no longer dealing with elements directly yet widgets instead
7
8
  include Glimmer
8
9
  include Observable
9
10
  include Observer
@@ -27,7 +28,7 @@ module Glimmer
27
28
  @element.set_attribute(@property, converted_value) unless evaluate_property == converted_value
28
29
  end
29
30
 
30
- def evaluate_property
31
+ def evaluate_property
31
32
  @element.send(@property)
32
33
  end
33
34
  end
@@ -12,26 +12,32 @@ module Glimmer
12
12
  include DataBinding::Observer
13
13
 
14
14
  def initialize(parent, model_binding, column_properties)
15
- @last_model_collection = nil
15
+ @last_populated_model_collection = nil
16
16
  @table = parent
17
17
  @model_binding = model_binding
18
18
  @column_properties = column_properties
19
- if @table.respond_to?(:column_properties=)
20
- @table.column_properties = @column_properties
21
- ##else # assume custom widget
22
- ## @table.body_root.column_properties = @column_properties
23
- end
24
- call(@model_binding.evaluate_property)
25
- model = model_binding.base_model
26
- observe(model, model_binding.property_name_expression)
19
+ @table.data = @model_binding
27
20
  ##@table.on_widget_disposed do |dispose_event| # doesn't seem needed within Opal
28
21
  ## unregister_all_observables
29
22
  ##end
23
+ if @table.respond_to?(:column_properties=)
24
+ @table.column_properties = @column_properties
25
+ else # assume custom widget
26
+ @table.body_root.column_properties = @column_properties
27
+ end
28
+ @table_observer_registration = observe(model_binding)
29
+ call
30
30
  end
31
31
 
32
32
  def call(new_model_collection=nil)
33
+ new_model_collection = @model_binding.evaluate_property # this ensures applying converters (e.g. :on_read)
34
+ table_cells = @table.items.map {|item| @table.column_properties.size.times.map {|i| item.get_text(i)} }
35
+ model_cells = new_model_collection.to_a.map {|m| @table.cells_for(m)}
36
+ return if table_cells == model_cells
33
37
  if new_model_collection and new_model_collection.is_a?(Array)
34
- observe(new_model_collection, @column_properties)
38
+ # @table_items_observer_registration&.unobserve
39
+ @table_items_observer_registration = observe(new_model_collection, @column_properties)
40
+ add_dependent(@table_observer_registration => @table_items_observer_registration)
35
41
  @model_collection = new_model_collection
36
42
  end
37
43
  populate_table(@model_collection, @table, @column_properties)
@@ -39,8 +45,8 @@ module Glimmer
39
45
  end
40
46
 
41
47
  def populate_table(model_collection, parent, column_properties)
42
- return if model_collection&.sort_by(&:hash) == @last_model_collection&.sort_by(&:hash)
43
- @last_model_collection = model_collection
48
+ return if model_collection&.sort_by(&:hash) == @last_populated_model_collection&.sort_by(&:hash)
49
+ @last_populated_model_collection = model_collection
44
50
  # TODO improve performance
45
51
  selected_table_item_models = parent.selection.map(&:get_data)
46
52
  old_items = parent.items
@@ -55,16 +61,21 @@ module Glimmer
55
61
  table_item.id = old_item_ids_per_model[model.hash] if old_item_ids_per_model[model.hash]
56
62
  end
57
63
  selected_table_items = parent.search {|item| selected_table_item_models.include?(item.get_data) }
58
- selected_table_items = [parent.items.first] if selected_table_items.empty? && !parent.items.empty?
59
- parent.selection = selected_table_items unless selected_table_items.empty?
64
+ parent.selection = selected_table_items
60
65
  parent.redraw
61
66
  end
62
67
 
63
68
  def sort_table(model_collection, parent, column_properties)
64
- return if model_collection == @last_model_collection
65
- parent.items = parent.items.sort_by { |item| model_collection.index(item.get_data) }
66
- @last_model_collection = model_collection
67
- end
69
+ return if model_collection == @last_sorted_model_collection
70
+ if model_collection == @last_populated_model_collection
71
+ # Reapply the last table sort. The model collection has just been populated since it diverged from what it was before
72
+ parent.sort!
73
+ else
74
+ # The model collection was sorted by the model, but beyond sorting, it did not change from the last populated model collection.
75
+ parent.items = parent.items.sort_by { |item| model_collection.index(item.get_data) }
76
+ @last_sorted_model_collection = @last_populated_model_collection = model_collection
77
+ end
78
+ end
68
79
  end
69
80
  end
70
81
  end
@@ -0,0 +1,41 @@
1
+ # Copyright (c) 2007-2020 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'glimmer/dsl/expression'
23
+
24
+ module Glimmer
25
+ module DSL
26
+ module Opal
27
+ class BlockPropertyExpression < Expression
28
+ def can_interpret?(parent, keyword, *args, &block)
29
+ block_given? and
30
+ args.size == 0 and
31
+ parent.respond_to?("#{keyword}_block=")
32
+ end
33
+
34
+ def interpret(parent, keyword, *args, &block)
35
+ parent.send("#{keyword}_block=", block)
36
+ nil
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,61 @@
1
+ # Copyright (c) 2020 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'glimmer/dsl/expression'
23
+ require 'glimmer/data_binding/model_binding'
24
+ require 'glimmer/data_binding/element_binding'
25
+
26
+ module Glimmer
27
+ module DSL
28
+ module Opal
29
+ class CheckboxGroupSelectionDataBindingExpression < Expression
30
+
31
+ def can_interpret?(parent, keyword, *args, &block)
32
+ keyword == 'selection' and
33
+ block.nil? and
34
+ (parent.is_a?(Glimmer::SWT::Custom::CheckboxGroup) or (parent.is_a?(Glimmer::UI::CustomWidget) and parent.body_root.is_a?(Glimmer::SWT::Custom::CheckboxGroup)) ) and
35
+ args.size == 1 and
36
+ args[0].is_a?(DataBinding::ModelBinding) and
37
+ args[0].evaluate_options_property.is_a?(Array)
38
+ end
39
+
40
+ def interpret(parent, keyword, *args, &block)
41
+ model_binding = args[0]
42
+
43
+ #TODO make this options observer dependent and all similar observers in widget specific data binding handlers
44
+ # TODO consider delegating some of this work
45
+ widget_binding = DataBinding::ElementBinding.new(parent, 'items')
46
+ widget_binding.call(model_binding.evaluate_options_property)
47
+ model = model_binding.base_model
48
+ widget_binding.observe(model, model_binding.options_property_name)
49
+
50
+ widget_binding = DataBinding::ElementBinding.new(parent, 'selection')
51
+ widget_binding.call(model_binding.evaluate_property)
52
+ widget_binding.observe(model, model_binding.property_name_expression)
53
+
54
+ parent.on_widget_selected do
55
+ model_binding.call(widget_binding.evaluate_property)
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2020 Andy Maleh
2
- #
2
+ #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
5
5
  # "Software"), to deal in the Software without restriction, including
@@ -7,10 +7,10 @@
7
7
  # distribute, sublicense, and/or sell copies of the Software, and to
8
8
  # permit persons to whom the Software is furnished to do so, subject to
9
9
  # the following conditions:
10
- #
10
+ #
11
11
  # The above copyright notice and this permission notice shall be
12
12
  # included in all copies or substantial portions of the Software.
13
- #
13
+ #
14
14
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
15
  # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
16
  # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -26,6 +26,8 @@ require 'glimmer/dsl/top_level_expression'
26
26
  require 'glimmer/ui/custom_widget'
27
27
  require 'glimmer/ui/custom_shell'
28
28
  require 'glimmer/swt/make_shift_shell_proxy'
29
+ require 'glimmer/swt/custom/radio_group'
30
+ require 'glimmer/swt/custom/checkbox_group'
29
31
 
30
32
  module Glimmer
31
33
  module DSL
@@ -42,7 +44,7 @@ module Glimmer
42
44
  def interpret(parent, keyword, *args, &block)
43
45
  custom_widget_class = UI::CustomWidget.for(keyword)
44
46
  # TODO clean code by extracting methods into CustomShell
45
- if !Glimmer::UI::CustomShell.requested? && custom_widget_class.ancestors.include?(Glimmer::UI::CustomShell)
47
+ if !Glimmer::UI::CustomShell.requested? && custom_widget_class&.ancestors&.to_a.include?(Glimmer::UI::CustomShell)
46
48
  if Glimmer::SWT::DisplayProxy.instance.shells.empty?
47
49
  custom_widget_class.new(parent, *args, {}, &block)
48
50
  else
@@ -52,7 +54,7 @@ module Glimmer
52
54
  'custom_shell' => keyword
53
55
  }.merge(options)
54
56
  param_string = params.to_a.map {|k, v| "#{k}=#{URI.encode_www_form_component(v)}"}.join('&')
55
- url = "#{`document.location.href`}?#{param_string}"
57
+ url = "#{`document.location.href`}?#{param_string}"
56
58
  `window.open(#{url})`
57
59
  # just a placeholder that has an open method # TODO return an actual CustomShell in the future that does the work happening above in the #open method
58
60
  Glimmer::SWT::MakeShiftShellProxy.new
@@ -64,7 +66,7 @@ module Glimmer
64
66
  custom_shell_keyword = parameters.delete('custom_shell')
65
67
  CustomWidgetExpression.new.interpret(nil, custom_shell_keyword, *[parameters])
66
68
  `history.pushState(#{parameters.reject {|k,v| k == 'custom_shell_handled'}}, document.title, #{"?#{Glimmer::UI::CustomShell.encoded_request_parameter_string.sub('&custom_shell_handled=true', '')}"})`
67
- # just a placeholder that has an open method # TODO return an actual CustomShell in the future that does the work happening above in the #open method
69
+ # just a placeholder that has an open method # TODO return an actual CustomShell in the future that does the work happening above in the #open method
68
70
  Glimmer::SWT::MakeShiftShellProxy.new
69
71
  else
70
72
  custom_widget_class&.new(parent, *args, {}, &block)
@@ -23,6 +23,9 @@ require 'glimmer/dsl/opal/rgb_expression'
23
23
  require 'glimmer/dsl/opal/rgba_expression'
24
24
  require 'glimmer/dsl/opal/custom_widget_expression'
25
25
  require 'glimmer/dsl/opal/swt_expression'
26
+ require 'glimmer/dsl/opal/radio_group_selection_data_binding_expression'
27
+ require 'glimmer/dsl/opal/checkbox_group_selection_data_binding_expression'
28
+ require 'glimmer/dsl/opal/block_property_expression'
26
29
 
27
30
  module Glimmer
28
31
  module DSL
@@ -35,9 +38,12 @@ module Glimmer
35
38
  table_items_data_binding
36
39
  combo_selection_data_binding
37
40
  list_selection_data_binding
41
+ radio_group_selection_data_binding
42
+ checkbox_group_selection_data_binding
38
43
  data_binding
39
44
  font
40
45
  layout
46
+ block_property
41
47
  property
42
48
  widget
43
49
  ]
@@ -7,9 +7,10 @@ module Glimmer
7
7
  include TopLevelExpression
8
8
 
9
9
  def can_interpret?(parent, keyword, *args, &block)
10
- parent and
11
- parent.respond_to?(:set_attribute) and
12
- keyword and
10
+ parent and
11
+ parent.respond_to?(:set_attribute) and
12
+ parent.respond_to?(keyword, *args) and
13
+ keyword and
13
14
  block.nil?
14
15
  end
15
16
 
@@ -0,0 +1,61 @@
1
+ # Copyright (c) 2020 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'glimmer/dsl/expression'
23
+ require 'glimmer/data_binding/model_binding'
24
+ require 'glimmer/data_binding/element_binding'
25
+
26
+ module Glimmer
27
+ module DSL
28
+ module Opal
29
+ class RadioGroupSelectionDataBindingExpression < Expression
30
+
31
+ def can_interpret?(parent, keyword, *args, &block)
32
+ keyword == 'selection' and
33
+ block.nil? and
34
+ (parent.is_a?(Glimmer::SWT::Custom::RadioGroup) or (parent.is_a?(Glimmer::UI::CustomWidget) and parent.body_root.is_a?(Glimmer::SWT::Custom::RadioGroup)) ) and
35
+ args.size == 1 and
36
+ args[0].is_a?(DataBinding::ModelBinding) and
37
+ args[0].evaluate_options_property.is_a?(Array)
38
+ end
39
+
40
+ def interpret(parent, keyword, *args, &block)
41
+ model_binding = args[0]
42
+
43
+ #TODO make this options observer dependent and all similar observers in widget specific data binding handlers
44
+ # TODO consider delegating some of this work
45
+ widget_binding = DataBinding::ElementBinding.new(parent, 'items')
46
+ widget_binding.call(model_binding.evaluate_options_property)
47
+ model = model_binding.base_model
48
+ widget_binding.observe(model, model_binding.options_property_name)
49
+
50
+ widget_binding = DataBinding::ElementBinding.new(parent, 'selection')
51
+ widget_binding.call(model_binding.evaluate_property)
52
+ widget_binding.observe(model, model_binding.property_name_expression)
53
+
54
+ parent.on_widget_selected do
55
+ model_binding.call(widget_binding.evaluate_property)
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -13,14 +13,14 @@ module Glimmer
13
13
  include TopLevelExpression
14
14
  include ParentExpression
15
15
 
16
- def interpret(parent, keyword, *args, &block)
16
+ def interpret(parent, keyword, *args, &block)
17
17
  if Glimmer::UI::CustomShell.requested_and_not_handled?
18
18
  parameters = Glimmer::UI::CustomShell.request_parameter_string.split("&").map {|str| str.split("=")}.to_h
19
19
  `history.pushState(#{parameters.merge('custom_shell_handled' => 'true')}, document.title, #{"?#{Glimmer::UI::CustomShell.encoded_request_parameter_string}&custom_shell_handled=true"})`
20
20
  custom_shell_keyword = parameters.delete('custom_shell')
21
21
  CustomWidgetExpression.new.interpret(nil, custom_shell_keyword, *[parameters])
22
22
  `history.pushState(#{parameters.reject {|k,v| k == 'custom_shell_handled'}}, document.title, #{"?#{Glimmer::UI::CustomShell.encoded_request_parameter_string.sub('&custom_shell_handled=true', '')}"})`
23
- # just a placeholder that has an open method # TODO return an actual CustomShell in the future that does the work happening above in the #open method
23
+ # just a placeholder that has an open method # TODO return an actual CustomShell in the future that does the work happening above in the #open method
24
24
  Glimmer::SWT::MakeShiftShellProxy.new
25
25
  else
26
26
  Glimmer::SWT::ShellProxy.new(*args)
@@ -30,6 +30,11 @@ module Glimmer
30
30
  def add_content(parent, &content)
31
31
  content.call(parent) if parent.is_a?(Glimmer::SWT::ShellProxy)
32
32
  end
33
+
34
+ def add_content(parent, &block)
35
+ super(parent, &block)
36
+ parent.post_add_content
37
+ end
33
38
  end
34
39
  end
35
40
  end
@@ -16,7 +16,12 @@ module Glimmer
16
16
  end
17
17
 
18
18
  def interpret(parent, keyword, *args, &block)
19
- Glimmer::SWT::WidgetProxy.for(keyword, parent, args)
19
+ Glimmer::SWT::WidgetProxy.for(keyword, parent, args, block)
20
+ end
21
+
22
+ def add_content(parent, &block)
23
+ super(parent, &block)
24
+ parent.post_add_content
20
25
  end
21
26
  end
22
27
  end
@@ -0,0 +1,9 @@
1
+ module Glimmer
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Glimmer
4
+
5
+ initializer "glimmer.assets.precompile" do |app|
6
+ app.config.assets.precompile += %w( glimmer/glimmer.css )
7
+ end
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2020 Andy Maleh
2
- #
2
+ #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
5
5
  # "Software"), to deal in the Software without restriction, including
@@ -7,10 +7,10 @@
7
7
  # distribute, sublicense, and/or sell copies of the Software, and to
8
8
  # permit persons to whom the Software is furnished to do so, subject to
9
9
  # the following conditions:
10
- #
10
+ #
11
11
  # The above copyright notice and this permission notice shall be
12
12
  # included in all copies or substantial portions of the Software.
13
- #
13
+ #
14
14
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
15
  # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
16
  # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -1,8 +1,22 @@
1
1
  require 'glimmer/swt/widget_proxy'
2
+ require 'glimmer/swt/radio_proxy'
3
+ require 'glimmer/swt/checkbox_proxy'
2
4
 
3
5
  module Glimmer
4
6
  module SWT
5
7
  class ButtonProxy < WidgetProxy
8
+ class << self
9
+ def create(keyword, parent, args, block)
10
+ if args.to_a.include?(:radio)
11
+ RadioProxy.new(parent, args, block)
12
+ elsif args.to_a.include?(:check)
13
+ CheckboxProxy.new(parent, args, block)
14
+ else
15
+ new(parent, args, block)
16
+ end
17
+ end
18
+ end
19
+
6
20
  attr_reader :text
7
21
 
8
22
  def text=(value)
@@ -18,7 +32,7 @@ module Glimmer
18
32
  {
19
33
  'on_widget_selected' => {
20
34
  event: 'click'
21
- },
35
+ },
22
36
  }
23
37
  end
24
38
 
@@ -30,7 +44,7 @@ module Glimmer
30
44
  input_disabled = @enabled ? {} : {'disabled': 'disabled'}
31
45
  input_args = input_args.merge(type: 'password') if has_style?(:password)
32
46
  @dom ||= html {
33
- button(input_args.merge(id: input_id, class: name, style: input_style, style: 'min-width: 27px; min-height: 27px;').merge(input_disabled)) {
47
+ button(input_args.merge(id: input_id, class: name, style: input_style, style: 'min-width: 32px; min-height: 32px;').merge(input_disabled)) {
34
48
  input_text.to_s == '' ? '&nbsp;' : input_text
35
49
  }
36
50
  }.to_s