glimmer-dsl-opal 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +41 -0
  3. data/README.md +1003 -58
  4. data/VERSION +1 -1
  5. data/lib/glimmer-dsl-opal.rb +26 -8
  6. data/lib/glimmer/data_binding/element_binding.rb +1 -1
  7. data/lib/glimmer/data_binding/ext/observable_model.rb +40 -0
  8. data/lib/glimmer/data_binding/list_selection_binding.rb +1 -1
  9. data/lib/glimmer/data_binding/table_items_binding.rb +70 -0
  10. data/lib/glimmer/dsl/opal/async_exec_expression.rb +17 -0
  11. data/lib/glimmer/dsl/opal/column_properties_expression.rb +22 -0
  12. data/lib/glimmer/dsl/opal/combo_selection_data_binding_expression.rb +2 -2
  13. data/lib/glimmer/dsl/opal/dsl.rb +10 -12
  14. data/lib/glimmer/dsl/opal/layout_data_expression.rb +2 -2
  15. data/lib/glimmer/dsl/opal/{text_expression.rb → layout_expression.rb} +5 -5
  16. data/lib/glimmer/dsl/opal/list_selection_data_binding_expression.rb +2 -3
  17. data/lib/glimmer/dsl/opal/message_box_expression.rb +20 -0
  18. data/lib/glimmer/dsl/opal/observe_expression.rb +32 -0
  19. data/lib/glimmer/dsl/opal/shell_expression.rb +2 -2
  20. data/lib/glimmer/dsl/opal/{composite_expression.rb → table_column_expression.rb} +3 -3
  21. data/lib/glimmer/dsl/opal/{list_expression.rb → table_expression.rb} +3 -3
  22. data/lib/glimmer/dsl/opal/table_items_data_binding_expression.rb +29 -0
  23. data/lib/glimmer/dsl/opal/widget_expression.rb +23 -0
  24. data/lib/glimmer/opal/display_proxy.rb +23 -0
  25. data/lib/glimmer/opal/element_proxy.rb +48 -13
  26. data/lib/glimmer/swt/browser_proxy.rb +27 -0
  27. data/lib/glimmer/swt/button_proxy.rb +40 -0
  28. data/lib/glimmer/{opal/select_proxy.rb → swt/combo_proxy.rb} +15 -11
  29. data/lib/glimmer/swt/composite_proxy.rb +31 -0
  30. data/lib/glimmer/{opal → swt}/event_listener_proxy.rb +1 -1
  31. data/lib/glimmer/{opal → swt}/grid_layout_proxy.rb +7 -18
  32. data/lib/glimmer/swt/label_proxy.rb +30 -0
  33. data/lib/glimmer/swt/layout_data_proxy.rb +52 -0
  34. data/lib/glimmer/swt/layout_proxy.rb +60 -0
  35. data/lib/glimmer/{opal → swt}/list_proxy.rb +18 -15
  36. data/lib/glimmer/swt/message_box_proxy.rb +146 -0
  37. data/lib/glimmer/{opal → swt}/point.rb +1 -1
  38. data/lib/glimmer/{opal → swt}/property_owner.rb +1 -1
  39. data/lib/glimmer/swt/shell_proxy.rb +235 -0
  40. data/lib/glimmer/swt/tab_folder_proxy.rb +52 -0
  41. data/lib/glimmer/swt/tab_item_proxy.rb +101 -0
  42. data/lib/glimmer/swt/table_column_proxy.rb +56 -0
  43. data/lib/glimmer/swt/table_item_proxy.rb +147 -0
  44. data/lib/glimmer/swt/table_proxy.rb +177 -0
  45. data/lib/glimmer/swt/text_proxy.rb +46 -0
  46. data/lib/glimmer/swt/widget_proxy.rb +389 -0
  47. data/lib/jquery.js +2 -0
  48. data/lib/samples/elaborate/contact_manager.rb +2 -3
  49. data/lib/samples/elaborate/login.rb +0 -1
  50. data/lib/samples/elaborate/tic_tac_toe.rb +5 -5
  51. data/lib/samples/hello/hello_computed.rb +19 -19
  52. data/lib/samples/hello/hello_tab.rb +2 -2
  53. metadata +92 -59
  54. data/lib/glimmer/config.rb +0 -22
  55. data/lib/glimmer/dsl/engine.rb +0 -193
  56. data/lib/glimmer/dsl/expression.rb +0 -42
  57. data/lib/glimmer/dsl/expression_handler.rb +0 -48
  58. data/lib/glimmer/dsl/opal/browser_expression.rb +0 -17
  59. data/lib/glimmer/dsl/opal/button_expression.rb +0 -18
  60. data/lib/glimmer/dsl/opal/combo_expression.rb +0 -17
  61. data/lib/glimmer/dsl/opal/grid_layout_expression.rb +0 -17
  62. data/lib/glimmer/dsl/opal/label_expression.rb +0 -17
  63. data/lib/glimmer/dsl/parent_expression.rb +0 -12
  64. data/lib/glimmer/dsl/static_expression.rb +0 -36
  65. data/lib/glimmer/dsl/top_level_expression.rb +0 -7
  66. data/lib/glimmer/error.rb +0 -6
  67. data/lib/glimmer/invalid_keyword_error.rb +0 -6
  68. data/lib/glimmer/opal/div_proxy.rb +0 -20
  69. data/lib/glimmer/opal/document_proxy.rb +0 -90
  70. data/lib/glimmer/opal/iframe_proxy.rb +0 -23
  71. data/lib/glimmer/opal/input_proxy.rb +0 -41
  72. data/lib/glimmer/opal/label_proxy.rb +0 -25
  73. data/lib/glimmer/opal/layout_data_proxy.rb +0 -31
@@ -0,0 +1,29 @@
1
+ require 'glimmer/dsl/expression'
2
+ require 'glimmer/data_binding/model_binding'
3
+ require 'glimmer/data_binding/table_items_binding'
4
+ require 'glimmer/swt/table_proxy'
5
+
6
+ module Glimmer
7
+ module DSL
8
+ module Opal
9
+ #Depends on BindCommandHandler and TableColumnPropertiesDataBindingCommandHandler
10
+ class TableItemsDataBindingExpression < Expression
11
+ def can_interpret?(parent, keyword, *args, &block)
12
+ keyword == "items" and
13
+ block.nil? and
14
+ parent.is_a?(Glimmer::SWT::TableProxy) and
15
+ args.size == 2 and
16
+ args[0].is_a?(DataBinding::ModelBinding) and
17
+ args[0].evaluate_property.is_a?(Array) and
18
+ args[1].is_a?(Array)
19
+ end
20
+
21
+ def interpret(parent, keyword, *args, &block)
22
+ model_binding = args[0]
23
+ column_properties = args[1]
24
+ DataBinding::TableItemsBinding.new(parent, model_binding, column_properties)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,23 @@
1
+ require 'glimmer/dsl/expression'
2
+ require 'glimmer/dsl/parent_expression'
3
+ require 'glimmer/swt/widget_proxy'
4
+
5
+ module Glimmer
6
+ module DSL
7
+ module Opal
8
+ class WidgetExpression < Expression
9
+ include ParentExpression
10
+ EXCLUDED_KEYWORDS = %w[shell display]
11
+
12
+ def can_interpret?(parent, keyword, *args, &block)
13
+ !EXCLUDED_KEYWORDS.include?(keyword) and
14
+ parent.is_a?(Glimmer::SWT::WidgetProxy)
15
+ end
16
+
17
+ def interpret(parent, keyword, *args, &block)
18
+ Glimmer::SWT::WidgetProxy.for(keyword, parent, args)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ module Glimmer
2
+ module Opal
3
+ class DisplayProxy
4
+ class << self
5
+ def instance
6
+ @instance ||= new
7
+ end
8
+ end
9
+
10
+ def async_exec(&block)
11
+ executer = lambda do
12
+ if Document.find('.modal').to_a.empty?
13
+ block.call
14
+ else
15
+ sleep(0.05)
16
+ Async::Task.new(&executer)
17
+ end
18
+ end
19
+ Async::Task.new(&executer)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,25 +1,54 @@
1
- require 'glimmer/opal/property_owner'
1
+ require 'glimmer/swt/property_owner'
2
2
 
3
3
  module Glimmer
4
4
  module Opal
5
5
  class ElementProxy
6
6
  include Glimmer
7
- include PropertyOwner
8
- attr_reader :parent, :args, :css_classes, :style
7
+ include Glimmer::SWT::PropertyOwner
8
+ attr_reader :parent, :args, :css_classes, :css, :children, :enabled
9
+
10
+ class << self
11
+ def next_id_number_for(name)
12
+ @max_id_numbers[name] = max_id_number_for(name) + 1
13
+ end
14
+
15
+ def max_id_number_for(name)
16
+ @max_id_numbers[name] = max_id_numbers[name] || 0
17
+ end
18
+
19
+ def max_id_numbers
20
+ @max_id_numbers ||= reset_max_id_numbers!
21
+ end
22
+
23
+ def reset_max_id_numbers!
24
+ @max_id_numbers = {}
25
+ end
26
+ end
9
27
 
10
28
  def initialize(parent, args)
11
29
  @parent = parent
12
30
  @args = args
13
- @children = []
14
- @parent.add_child(self)
31
+ @children = Set.new
15
32
  @css_classes = Set.new
33
+ @css = ''
34
+ @enabled = true
35
+ @parent.add_child(self)
36
+ end
37
+
38
+ def dispose
39
+ dom.remove
16
40
  end
17
41
 
18
42
  def add_child(child)
19
- return if @children.include?(child)
43
+ # return if @children.include?(child) # TODO consider adding an option to enable this if needed to prevent dom repetition
20
44
  @children << child
21
45
  dom << child.dom
22
46
  end
47
+
48
+ def enabled=(value)
49
+ @enabled = value
50
+ redraw
51
+ end
23
52
 
24
53
  def redraw
25
54
  if @dom
@@ -29,6 +58,9 @@ module Glimmer
29
58
  else
30
59
  dom
31
60
  end
61
+ @children.each do |child|
62
+ child.redraw
63
+ end
32
64
  end
33
65
 
34
66
  # Subclasses must override with their own mappings
@@ -41,9 +73,14 @@ module Glimmer
41
73
  end
42
74
 
43
75
  def id
44
- "#{name}-#{hash}"
76
+ @id ||= "#{name}-#{ElementProxy.next_id_number_for(name)}"
45
77
  end
46
-
78
+
79
+ # Sets id explicitly. Useful in cases of wanting to maintain a stable id
80
+ def id=(value)
81
+ @id = value
82
+ end
83
+
47
84
  # Subclasses can override with their own selector
48
85
  def selector
49
86
  "#{name}##{id}"
@@ -74,10 +111,8 @@ module Glimmer
74
111
  redraw
75
112
  end
76
113
 
77
- # TODO rename to avoid conflict with SWT Style verbiage
78
-
79
- def style=(css)
80
- @style = css
114
+ def css=(css)
115
+ @css = css
81
116
  redraw
82
117
  end
83
118
 
@@ -185,7 +220,7 @@ module Glimmer
185
220
  # },
186
221
  InputProxy => {
187
222
  :text => lambda do |observer|
188
- on_modify_text { |modify_event|
223
+ on_modify_text { |modify_event|
189
224
  observer.call(text)
190
225
  }
191
226
  end,
@@ -0,0 +1,27 @@
1
+ require 'glimmer/swt/widget_proxy'
2
+
3
+ module Glimmer
4
+ module SWT
5
+ class BrowserProxy < WidgetProxy
6
+ attr_reader :url
7
+
8
+ def url=(value)
9
+ @url = value
10
+ redraw
11
+ end
12
+
13
+ def element
14
+ 'iframe'
15
+ end
16
+
17
+ def dom
18
+ iframe_id = id
19
+ iframe_url = url
20
+ @dom ||= html {
21
+ iframe(id: iframe_id, class: name, src: iframe_url, frameBorder: 0) {
22
+ }
23
+ }.to_s
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,40 @@
1
+ require 'glimmer/swt/widget_proxy'
2
+
3
+ module Glimmer
4
+ module SWT
5
+ class ButtonProxy < WidgetProxy
6
+ attr_reader :text
7
+
8
+ def text=(value)
9
+ @text = value
10
+ redraw
11
+ end
12
+
13
+ def element
14
+ 'button'
15
+ end
16
+
17
+ def observation_request_to_event_mapping
18
+ {
19
+ 'on_widget_selected' => {
20
+ event: 'click'
21
+ },
22
+ }
23
+ end
24
+
25
+ def dom
26
+ input_text = @text
27
+ input_id = id
28
+ input_style = css
29
+ input_args = {}
30
+ input_disabled = @enabled ? {} : {'disabled': 'disabled'}
31
+ input_args = input_args.merge(type: 'password') if has_style?(:password)
32
+ @dom ||= html {
33
+ button(input_args.merge(id: input_id, class: name, style: input_style, style: 'min-width: 27px;').merge(input_disabled)) {
34
+ input_text.to_s == '' ? '&nbsp;' : input_text
35
+ }
36
+ }.to_s
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,10 +1,9 @@
1
1
  require 'glimmer/data_binding/observable_element'
2
- require 'glimmer/opal/event_listener_proxy'
3
- require 'glimmer/opal/element_proxy'
2
+ require 'glimmer/swt/widget_proxy'
4
3
 
5
4
  module Glimmer
6
- module Opal
7
- class SelectProxy < ElementProxy
5
+ module SWT
6
+ class ComboProxy < WidgetProxy
8
7
  include Glimmer::DataBinding::ObservableElement
9
8
  attr_reader :text, :items
10
9
 
@@ -13,9 +12,13 @@ module Glimmer
13
12
  @items = []
14
13
  end
15
14
 
15
+ def element
16
+ 'select'
17
+ end
18
+
16
19
  def text=(value)
17
20
  @text = value
18
- redraw
21
+ Document.find(path).value = value
19
22
  end
20
23
 
21
24
  def items=(the_items)
@@ -23,12 +26,12 @@ module Glimmer
23
26
  redraw
24
27
  end
25
28
 
26
- def observation_request_to_event_mapping
29
+ def observation_request_to_event_mapping
27
30
  {
28
31
  'on_widget_selected' => {
29
32
  event: 'change',
30
33
  event_handler: -> (event_listener) {
31
- -> (event) {
34
+ -> (event) {
32
35
  @text = event.target.value
33
36
  event_listener.call(event)
34
37
  }
@@ -41,9 +44,10 @@ module Glimmer
41
44
  select_text = @text
42
45
  items = @items
43
46
  select_id = id
44
- select_style = style
45
- @dom ||= DOM {
46
- select(id: select_id, style: select_style) {
47
+ select_style = css
48
+ select_class = name
49
+ @dom ||= html {
50
+ select(id: select_id, class: select_class, style: select_style) {
47
51
  items.to_a.each do |item|
48
52
  option_hash = {value: item}
49
53
  option_hash[:selected] = 'selected' if select_text == item
@@ -52,7 +56,7 @@ module Glimmer
52
56
  }
53
57
  end
54
58
  }
55
- }
59
+ }.to_s
56
60
  end
57
61
  end
58
62
  end
@@ -0,0 +1,31 @@
1
+ require 'glimmer/swt/grid_layout_proxy'
2
+ require 'glimmer/swt/widget_proxy'
3
+
4
+ module Glimmer
5
+ module SWT
6
+ class CompositeProxy < WidgetProxy
7
+ attr_reader :layout
8
+
9
+ def initialize(parent, args)
10
+ super(parent, args)
11
+ @layout = GridLayoutProxy.new(self, [])
12
+ end
13
+
14
+ def redraw
15
+ super()
16
+ @children.each do |child|
17
+ add_child(child) # TODO think of impact of this on performance, and of other alternatives
18
+ end
19
+ end
20
+
21
+ def dom
22
+ div_id = id
23
+ div_style = css
24
+ div_class = "#{name} grid-layout"
25
+ @dom ||= html {
26
+ div(id: div_id, class: div_class, style: div_style)
27
+ }.to_s
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,5 +1,5 @@
1
1
  module Glimmer
2
- module Opal
2
+ module SWT
3
3
  class EventListenerProxy
4
4
  attr_reader :element_proxy, :event, :selector, :delegate
5
5
 
@@ -1,16 +1,15 @@
1
- require 'glimmer/opal/property_owner'
1
+ require 'glimmer/swt/layout_proxy'
2
2
 
3
3
  module Glimmer
4
- module Opal
5
- class GridLayoutProxy
6
- include PropertyOwner
7
- attr_reader :parent, :args, :num_columns, :make_columns_equal_width, :horizontal_spacing, :vertical_spacing
4
+ module SWT
5
+ class GridLayoutProxy < LayoutProxy
6
+ attr_reader :num_columns, :make_columns_equal_width, :horizontal_spacing, :vertical_spacing
8
7
 
9
8
  def initialize(parent, args)
10
- @parent = parent
11
- @args = args
12
- @parent.add_css_class('grid-layout')
9
+ super(parent, args)
10
+ @horizontal_spacing = 10
13
11
  @vertical_spacing = 10
12
+ @num_columns = @args.first || 1
14
13
  reapply
15
14
  end
16
15
 
@@ -37,16 +36,6 @@ module Glimmer
37
36
  # @parent.add_css_class("vertical-spacing-#{@vertical_spacing}")
38
37
  reapply
39
38
  end
40
-
41
- def reapply
42
- @parent.style = <<~CSS
43
- display: grid;
44
- grid-template-columns: #{'auto ' * @num_columns.to_i};
45
- grid-row-gap: #{@vertical_spacing}px;
46
- grid-column-gap: #{@horizontal_spacing}px;
47
- justify-content: start;
48
- CSS
49
- end
50
39
  end
51
40
  end
52
41
  end
@@ -0,0 +1,30 @@
1
+ require 'glimmer/swt/widget_proxy'
2
+
3
+ module Glimmer
4
+ module SWT
5
+ class LabelProxy < WidgetProxy
6
+ attr_reader :text
7
+
8
+ def text=(value)
9
+ @text = value
10
+ redraw
11
+ end
12
+
13
+ def element
14
+ 'label'
15
+ end
16
+
17
+ def dom
18
+ label_text = @text
19
+ label_id = id
20
+ label_style = css
21
+ label_class = name
22
+ @dom ||= html {
23
+ label(id: label_id, style: label_style, class: label_class) {
24
+ label_text
25
+ }
26
+ }.to_s
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,52 @@
1
+ require 'glimmer/swt/property_owner'
2
+
3
+ module Glimmer
4
+ module SWT
5
+ class LayoutDataProxy
6
+ include Glimmer::SWT::PropertyOwner
7
+ attr_reader :parent,
8
+ :args,
9
+ :horizontal_alignment,
10
+ :vertical_alignment,
11
+ :grab_excess_horizontal_space,
12
+ :grab_excess_vertical_space,
13
+ :height_hint
14
+
15
+ def initialize(parent, args)
16
+ @parent = parent
17
+ @args = args
18
+ reapply
19
+ end
20
+
21
+ def height_hint=(height_hint)
22
+ @height_hint = height_hint
23
+ reapply
24
+ end
25
+
26
+ def horizontal_alignment=(horizontal_alignment)
27
+ @horizontal_alignment = horizontal_alignment
28
+ reapply
29
+ end
30
+
31
+ def vertical_alignment=(vertical_alignment)
32
+ @vertical_alignment = vertical_alignment
33
+ reapply
34
+ end
35
+
36
+ def grab_excess_horizontal_space=(grab_excess_horizontal_space)
37
+ @grab_excess_horizontal_space = grab_excess_horizontal_space
38
+ reapply
39
+ end
40
+
41
+ def grab_excess_vertical_space=(grab_excess_vertical_space)
42
+ @grab_excess_vertical_space = grab_excess_vertical_space
43
+ reapply
44
+ end
45
+
46
+ def reapply
47
+ # @parent.css = <<~CSS
48
+ # CSS
49
+ end
50
+ end
51
+ end
52
+ end