glimmer 0.5.11 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/README.markdown +129 -15
  3. data/lib/glimmer.rb +13 -1
  4. data/lib/glimmer/css/rule_set.rb +27 -0
  5. data/lib/glimmer/css/style_sheet.rb +20 -0
  6. data/lib/glimmer/dsl/css/css_expression.rb +21 -0
  7. data/lib/glimmer/dsl/css/dsl.rb +10 -0
  8. data/lib/glimmer/dsl/css/p_expression.rb +25 -0
  9. data/lib/glimmer/dsl/css/property_expression.rb +22 -0
  10. data/lib/glimmer/dsl/css/rule_set_expression.rb +25 -0
  11. data/lib/glimmer/dsl/css/s_expression.rb +26 -0
  12. data/lib/glimmer/dsl/engine.rb +90 -18
  13. data/lib/glimmer/dsl/expression.rb +9 -4
  14. data/lib/glimmer/dsl/static_expression.rb +13 -13
  15. data/lib/glimmer/dsl/swt/async_exec_expression.rb +14 -0
  16. data/lib/glimmer/dsl/swt/bind_expression.rb +37 -0
  17. data/lib/glimmer/dsl/swt/color_expression.rb +17 -0
  18. data/lib/glimmer/dsl/swt/column_properties_expression.rb +24 -0
  19. data/lib/glimmer/dsl/swt/combo_selection_data_binding_expression.rb +42 -0
  20. data/lib/glimmer/dsl/swt/custom_widget_expression.rb +36 -0
  21. data/lib/glimmer/dsl/swt/data_binding_expression.rb +34 -0
  22. data/lib/glimmer/dsl/swt/display_expression.rb +19 -0
  23. data/lib/glimmer/dsl/swt/dsl.rb +26 -0
  24. data/lib/glimmer/dsl/swt/exec_expression.rb +28 -0
  25. data/lib/glimmer/dsl/swt/layout_data_expression.rb +25 -0
  26. data/lib/glimmer/dsl/swt/layout_expression.rb +27 -0
  27. data/lib/glimmer/dsl/swt/list_selection_data_binding_expression.rb +44 -0
  28. data/lib/glimmer/dsl/swt/menu_bar_expression.rb +33 -0
  29. data/lib/glimmer/dsl/swt/menu_expression.rb +32 -0
  30. data/lib/glimmer/dsl/swt/observe_expression.rb +32 -0
  31. data/lib/glimmer/dsl/swt/property_expression.rb +22 -0
  32. data/lib/glimmer/dsl/swt/rgb_expression.rb +12 -0
  33. data/lib/glimmer/dsl/swt/rgba_expression.rb +12 -0
  34. data/lib/glimmer/dsl/swt/shell_expression.rb +20 -0
  35. data/lib/glimmer/dsl/swt/swt_expression.rb +25 -0
  36. data/lib/glimmer/dsl/swt/sync_exec_expression.rb +15 -0
  37. data/lib/glimmer/dsl/swt/tab_item_expression.rb +33 -0
  38. data/lib/glimmer/dsl/swt/table_items_data_binding_expression.rb +31 -0
  39. data/lib/glimmer/dsl/swt/tree_items_data_binding_expression.rb +31 -0
  40. data/lib/glimmer/dsl/swt/tree_properties_expression.rb +26 -0
  41. data/lib/glimmer/dsl/swt/widget_expression.rb +27 -0
  42. data/lib/glimmer/dsl/swt/widget_listener_expression.rb +32 -0
  43. data/lib/glimmer/dsl/top_level_expression.rb +7 -0
  44. data/lib/glimmer/dsl/xml/dsl.rb +11 -0
  45. data/lib/glimmer/dsl/xml/html_expression.rb +25 -0
  46. data/lib/glimmer/dsl/xml/meta_expression.rb +23 -0
  47. data/lib/glimmer/dsl/xml/name_space_expression.rb +37 -0
  48. data/lib/glimmer/dsl/xml/node_parent_expression.rb +33 -0
  49. data/lib/glimmer/dsl/xml/tag_expression.rb +29 -0
  50. data/lib/glimmer/dsl/xml/text_expression.rb +22 -0
  51. data/lib/glimmer/dsl/xml/xml_expression.rb +21 -0
  52. data/lib/glimmer/rake_task.rb +1 -1
  53. data/lib/glimmer/swt/shell_proxy.rb +1 -2
  54. data/lib/glimmer/swt/widget_proxy.rb +6 -3
  55. data/lib/glimmer/ui/custom_widget.rb +8 -4
  56. data/lib/glimmer/ui/video.rb +31 -28
  57. data/lib/glimmer/xml/depth_first_search_iterator.rb +22 -0
  58. data/lib/glimmer/xml/name_space_visitor.rb +21 -0
  59. data/lib/glimmer/xml/node.rb +75 -0
  60. data/lib/glimmer/xml/node_visitor.rb +13 -0
  61. data/lib/glimmer/xml/xml_visitor.rb +65 -0
  62. data/samples/gladiator.rb +52 -12
  63. metadata +55 -31
  64. data/lib/glimmer/dsl.rb +0 -26
  65. data/lib/glimmer/dsl/async_exec_expression.rb +0 -12
  66. data/lib/glimmer/dsl/bind_expression.rb +0 -35
  67. data/lib/glimmer/dsl/color_expression.rb +0 -22
  68. data/lib/glimmer/dsl/column_properties_expression.rb +0 -22
  69. data/lib/glimmer/dsl/combo_selection_data_binding_expression.rb +0 -40
  70. data/lib/glimmer/dsl/custom_widget_expression.rb +0 -33
  71. data/lib/glimmer/dsl/data_binding_expression.rb +0 -32
  72. data/lib/glimmer/dsl/display_expression.rb +0 -14
  73. data/lib/glimmer/dsl/exec_expression.rb +0 -23
  74. data/lib/glimmer/dsl/layout_data_expression.rb +0 -23
  75. data/lib/glimmer/dsl/layout_expression.rb +0 -25
  76. data/lib/glimmer/dsl/list_selection_data_binding_expression.rb +0 -42
  77. data/lib/glimmer/dsl/menu_bar_expression.rb +0 -31
  78. data/lib/glimmer/dsl/menu_expression.rb +0 -30
  79. data/lib/glimmer/dsl/observe_expression.rb +0 -27
  80. data/lib/glimmer/dsl/property_expression.rb +0 -20
  81. data/lib/glimmer/dsl/shell_expression.rb +0 -16
  82. data/lib/glimmer/dsl/swt_expression.rb +0 -23
  83. data/lib/glimmer/dsl/sync_exec_expression.rb +0 -13
  84. data/lib/glimmer/dsl/tab_item_expression.rb +0 -31
  85. data/lib/glimmer/dsl/table_items_data_binding_expression.rb +0 -29
  86. data/lib/glimmer/dsl/tree_items_data_binding_expression.rb +0 -29
  87. data/lib/glimmer/dsl/tree_properties_expression.rb +0 -24
  88. data/lib/glimmer/dsl/widget_expression.rb +0 -25
  89. data/lib/glimmer/dsl/widget_listener_expression.rb +0 -30
@@ -1,40 +0,0 @@
1
- require 'glimmer/dsl/expression'
2
- require 'glimmer/data_binding/model_binding'
3
- require 'glimmer/data_binding/widget_binding'
4
-
5
- module Glimmer
6
- module DSL
7
- class ComboSelectionDataBindingExpression < Expression
8
- include_package 'org.eclipse.swt.widgets'
9
-
10
- def can_interpret?(parent, keyword, *args, &block)
11
- keyword == 'selection' and
12
- block.nil? and
13
- widget?(parent) and
14
- parent.swt_widget.is_a?(Combo) and
15
- args.size == 1 and
16
- args[0].is_a?(DataBinding::ModelBinding) and
17
- args[0].evaluate_options_property.is_a?(Array)
18
- end
19
-
20
- def interpret(parent, keyword, *args, &block)
21
- model_binding = args[0]
22
-
23
- #TODO make this options observer dependent and all similar observers in widget specific data binding handlers
24
- # TODO consider delegating some of this work
25
- widget_binding = DataBinding::WidgetBinding.new(parent, 'items')
26
- widget_binding.call(model_binding.evaluate_options_property)
27
- model = model_binding.base_model
28
- widget_binding.observe(model, model_binding.options_property_name)
29
-
30
- widget_binding = DataBinding::WidgetBinding.new(parent, 'text')
31
- widget_binding.call(model_binding.evaluate_property)
32
- widget_binding.observe(model, model_binding.property_name_expression)
33
-
34
- parent.on_widget_selected do
35
- model_binding.call(widget_binding.evaluate_property)
36
- end
37
- end
38
- end
39
- end
40
- end
@@ -1,33 +0,0 @@
1
- require 'glimmer'
2
- require 'glimmer/dsl/expression'
3
- require 'glimmer/dsl/parent_expression'
4
- require 'glimmer/ui/custom_widget'
5
- require 'glimmer/ui/custom_shell'
6
-
7
- module Glimmer
8
- module DSL
9
- class CustomWidgetExpression < Expression
10
- include ParentExpression
11
- def can_interpret?(parent, keyword, *args, &block)
12
- custom_widget_class = UI::CustomWidget.for(keyword)
13
- custom_widget_class and
14
- (widget?(parent) or
15
- custom_widget_class.ancestors.include?(UI::CustomShell))
16
- end
17
-
18
- def interpret(parent, keyword, *args, &block)
19
- options = args.last.is_a?(Hash) ? args.pop : {}
20
- UI::CustomWidget.for(keyword).new(parent, *args, options, &block)
21
- end
22
-
23
- def add_content(parent, &block)
24
- # TODO consider avoiding source_location
25
- if block.source_location == parent.content&.__getobj__.source_location
26
- parent.content.call(parent) unless parent.content.called?
27
- else
28
- super
29
- end
30
- end
31
- end
32
- end
33
- end
@@ -1,32 +0,0 @@
1
- require 'glimmer/dsl/expression'
2
- require 'glimmer/data_binding/model_binding'
3
- require 'glimmer/data_binding/widget_binding'
4
-
5
- module Glimmer
6
- module DSL
7
- # Responsible for wiring two-way data-binding for text and selection properties
8
- # on Text, Button, and Spinner widgets.
9
- # Does so by using the output of the bind(model, property) command in the form
10
- # of a ModelBinding, which is then connected to an anonymous widget observer
11
- # (aka widget_data_binder as per widget_data_binders array)
12
- #
13
- # Depends on BindCommandHandler
14
- class DataBindingExpression < Expression
15
- def can_interpret?(parent, keyword, *args, &block)
16
- args.size == 1 and
17
- args[0].is_a?(DataBinding::ModelBinding)
18
- end
19
-
20
- def interpret(parent, keyword, *args, &block)
21
- model_binding = args[0]
22
- widget_binding_parameters = [parent, keyword]
23
- widget_binding = DataBinding::WidgetBinding.new(*widget_binding_parameters)
24
- widget_binding.call(model_binding.evaluate_property)
25
- #TODO make this options observer dependent and all similar observers in widget specific data binding handlers
26
- widget_binding.observe(model_binding)
27
- # TODO simplify this logic and put it where it belongs
28
- parent.add_observer(model_binding, keyword) if parent.respond_to?(:add_observer, [model_binding, keyword])
29
- end
30
- end
31
- end
32
- end
@@ -1,14 +0,0 @@
1
- require 'glimmer/dsl/static_expression'
2
- require 'glimmer/dsl/parent_expression'
3
- require 'glimmer/swt/display_proxy'
4
-
5
- module Glimmer
6
- module DSL
7
- class DisplayExpression < StaticExpression
8
- include ParentExpression
9
- def interpret(parent, keyword, *args, &block)
10
- SWT::DisplayProxy.instance(*args)
11
- end
12
- end
13
- end
14
- end
@@ -1,23 +0,0 @@
1
- require 'glimmer/swt/display_proxy'
2
-
3
- module Glimmer
4
- module DSL
5
- # Mixin for common code in async_exec and sync_exec expressions
6
- # Uses name in subclass to auto-derive exec_operation
7
- module ExecExpression
8
- def exec_operation
9
- @exec_operation ||= self.class.name.split(/::/).last.sub(/Expression$/, '').underscore
10
- end
11
-
12
- def can_interpret?(parent, keyword, *args, &block)
13
- keyword == exec_operation and
14
- block_given? and
15
- args.empty?
16
- end
17
-
18
- def interpret(parent, keyword, *args, &block)
19
- SWT::DisplayProxy.instance.send(exec_operation, &block)
20
- end
21
- end
22
- end
23
- end
@@ -1,23 +0,0 @@
1
- require 'glimmer'
2
- require 'glimmer/dsl/static_expression'
3
- require 'glimmer/dsl/parent_expression'
4
- require 'glimmer/swt/layout_data_proxy'
5
-
6
- # TODO consider turning static keywords like layout_data into methods
7
-
8
- module Glimmer
9
- module DSL
10
- class LayoutDataExpression < StaticExpression
11
- include ParentExpression
12
-
13
- def can_interpret?(parent, keyword, *args, &block)
14
- keyword == 'layout_data' and
15
- widget?(parent)
16
- end
17
-
18
- def interpret(parent, keyword, *args, &block)
19
- SWT::LayoutDataProxy.new(parent, args)
20
- end
21
- end
22
- end
23
- end
@@ -1,25 +0,0 @@
1
- require 'glimmer'
2
- require 'glimmer/dsl/expression'
3
- require 'glimmer/dsl/parent_expression'
4
- require 'glimmer/swt/layout_proxy'
5
-
6
- module Glimmer
7
- module DSL
8
- class LayoutExpression < Expression
9
- include ParentExpression
10
-
11
- include_package 'org.eclipse.swt.widgets'
12
-
13
- def can_interpret?(parent, keyword, *args, &block)
14
- keyword.to_s.end_with?('_layout') and
15
- widget?(parent) and
16
- parent.swt_widget.is_a?(Composite) and
17
- SWT::LayoutProxy.layout_exists?(keyword.to_s)
18
- end
19
-
20
- def interpret(parent, keyword, *args, &block)
21
- SWT::LayoutProxy.new(keyword, parent, args)
22
- end
23
- end
24
- end
25
- end
@@ -1,42 +0,0 @@
1
- require 'glimmer/dsl/expression'
2
- require 'glimmer/data_binding/model_binding'
3
- require 'glimmer/data_binding/widget_binding'
4
- require 'glimmer/data_binding/list_selection_binding'
5
-
6
- module Glimmer
7
- module DSL
8
- class ListSelectionDataBindingExpression < Expression
9
- include_package 'org.eclipse.swt.widgets'
10
-
11
- def can_interpret?(parent, keyword, *args, &block)
12
- keyword == 'selection' and
13
- block.nil? and
14
- widget?(parent) and
15
- parent.swt_widget.is_a?(List) and
16
- args.size == 1 and
17
- args[0].is_a?(DataBinding::ModelBinding) and
18
- args[0].evaluate_options_property.is_a?(Array)
19
- end
20
-
21
- def interpret(parent, keyword, *args, &block)
22
- model_binding = args[0]
23
- widget_binding = DataBinding::WidgetBinding.new(parent, 'items')
24
- widget_binding.call(model_binding.evaluate_options_property)
25
- model = model_binding.base_model
26
- #TODO make this options observer dependent and all similar observers in widget specific data binding interpretrs
27
- widget_binding.observe(model, model_binding.options_property_name)
28
-
29
- property_type = :string
30
- property_type = :array if parent.has_style?(:multi)
31
- list_selection_binding = DataBinding::ListSelectionBinding.new(parent, property_type)
32
- list_selection_binding.call(model_binding.evaluate_property)
33
- #TODO check if nested data binding works for list widget and other widgets that need custom data binding
34
- list_selection_binding.observe(model, model_binding.property_name_expression)
35
-
36
- parent.on_widget_selected do
37
- model_binding.call(list_selection_binding.evaluate_property)
38
- end
39
- end
40
- end
41
- end
42
- end
@@ -1,31 +0,0 @@
1
- require 'glimmer'
2
- require 'glimmer/dsl/static_expression'
3
- require 'glimmer/dsl/parent_expression'
4
- require 'glimmer/swt/menu_proxy'
5
-
6
- module Glimmer
7
- module DSL
8
- class MenuBarExpression < StaticExpression
9
- include ParentExpression
10
-
11
- include_package 'org.eclipse.swt.widgets'
12
-
13
- def can_interpret?(parent, keyword, *args, &block)
14
- initial_condition = (keyword == 'menu_bar')
15
- if initial_condition
16
- if parent.swt_widget.is_a?(Shell)
17
- return true
18
- else
19
- raise Glimmer::Error, "menu_bar may only be nested under a shell!"
20
- end
21
- end
22
- false
23
- end
24
-
25
- def interpret(parent, keyword, *args, &block)
26
- args = args.unshift(:bar)
27
- SWT::MenuProxy.new(parent, args)
28
- end
29
- end
30
- end
31
- end
@@ -1,30 +0,0 @@
1
- require 'glimmer'
2
- require 'glimmer/dsl/static_expression'
3
- require 'glimmer/dsl/parent_expression'
4
- require 'glimmer/swt/menu_proxy'
5
-
6
- module Glimmer
7
- module DSL
8
- class MenuExpression < StaticExpression
9
- include ParentExpression
10
-
11
- include_package 'org.eclipse.swt.widgets'
12
-
13
- def can_interpret?(parent, keyword, *args, &block)
14
- initial_condition = (keyword == 'menu')
15
- if initial_condition
16
- if widget?(parent)
17
- return true
18
- else
19
- raise Glimmer::Error, "menu may only be nested under a widget (like shell or another menu)!"
20
- end
21
- end
22
- false
23
- end
24
-
25
- def interpret(parent, keyword, *args, &block)
26
- SWT::MenuProxy.new(parent, args)
27
- end
28
- end
29
- end
30
- end
@@ -1,27 +0,0 @@
1
- require 'glimmer/dsl/static_expression'
2
- require 'glimmer/data_binding/observer'
3
- require 'glimmer/data_binding/model_binding'
4
-
5
- module Glimmer
6
- module DSL
7
- class ObserveExpression < StaticExpression
8
- REGEX_NESTED_OR_INDEXED_PROPERTY = /([^\[]+)(\[[^\]]+\])?/
9
-
10
- def can_interpret?(parent, keyword, *args, &block)
11
- keyword == 'observe' and
12
- block_given? and
13
- (args.size == 2) and
14
- textual?(args[1])
15
- end
16
-
17
- def interpret(parent, keyword, *args, &block)
18
- observer = DataBinding::Observer.proc(&block)
19
- if args[1].to_s.match(REGEX_NESTED_OR_INDEXED_PROPERTY)
20
- observer.observe(DataBinding::ModelBinding.new(args[0], args[1]))
21
- else
22
- observer.observe(args[0], args[1])
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,20 +0,0 @@
1
- require 'glimmer/dsl/expression'
2
-
3
- module Glimmer
4
- module DSL
5
- class PropertyExpression < Expression
6
- def can_interpret?(parent, keyword, *args, &block)
7
- block.nil? and
8
- args.size > 0 and
9
- parent.respond_to?(:set_attribute) and
10
- parent.respond_to?(:has_attribute?) and
11
- parent.has_attribute?(keyword, *args)
12
- end
13
-
14
- def interpret(parent, keyword, *args, &block)
15
- parent.set_attribute(keyword, *args)
16
- nil
17
- end
18
- end
19
- end
20
- end
@@ -1,16 +0,0 @@
1
- require 'glimmer/dsl/static_expression'
2
- require 'glimmer/dsl/parent_expression'
3
- require 'glimmer/swt/shell_proxy'
4
-
5
- module Glimmer
6
- module DSL
7
- class ShellExpression < StaticExpression
8
- include ParentExpression
9
-
10
- def interpret(parent, keyword, *args, &block)
11
- args = [parent] + args unless parent.nil?
12
- SWT::ShellProxy.send(:new, *args)
13
- end
14
- end
15
- end
16
- end
@@ -1,23 +0,0 @@
1
- require 'glimmer/dsl/static_expression'
2
- require 'glimmer/swt/swt_proxy'
3
-
4
- # TODO consider turning static keywords like bind into methods
5
-
6
- module Glimmer
7
- module DSL
8
- # Responsible for returning SWT constant values
9
- #
10
- # Named SwtExpression (not SWTExpression) so that the DSL engine
11
- # discovers quickly by convention
12
- class SwtExpression < StaticExpression
13
- def can_interpret?(parent, keyword, *args, &block)
14
- block.nil? &&
15
- args.size > 0
16
- end
17
-
18
- def interpret(parent, keyword, *args, &block)
19
- SWT::SWTProxy[*args]
20
- end
21
- end
22
- end
23
- end
@@ -1,13 +0,0 @@
1
- require 'glimmer/dsl/static_expression'
2
- require 'glimmer/dsl/exec_expression'
3
-
4
- module Glimmer
5
- module DSL
6
- # Synchronously executes code block against the SWT Event Loop
7
- # to manipulate SWT UI objects on the UI thread safely with
8
- # immediate priority when needed.
9
- class SyncExecExpression < StaticExpression
10
- include ExecExpression
11
- end
12
- end
13
- end
@@ -1,31 +0,0 @@
1
- require 'glimmer'
2
- require 'glimmer/dsl/static_expression'
3
- require 'glimmer/dsl/parent_expression'
4
- require 'glimmer/swt/widget_proxy'
5
- require 'glimmer/swt/tab_item_proxy'
6
-
7
- module Glimmer
8
- module DSL
9
- class TabItemExpression < StaticExpression
10
- include ParentExpression
11
-
12
- include_package 'org.eclipse.swt.widgets'
13
-
14
- def can_interpret?(parent, keyword, *args, &block)
15
- initial_condition = (keyword == 'tab_item') and widget?(parent)
16
- if initial_condition
17
- if parent.swt_widget.is_a?(TabFolder)
18
- return true
19
- else
20
- Glimmer.logger&.error "tab_item widget may only be used directly under a tab_folder widget!"
21
- end
22
- end
23
- false
24
- end
25
-
26
- def interpret(parent, keyword, *args, &block)
27
- SWT::TabItemProxy.new(parent, args)
28
- end
29
- end
30
- end
31
- end