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
@@ -0,0 +1,23 @@
1
+ require 'glimmer/dsl/xml/node_parent_expression'
2
+ require 'glimmer/dsl/xml/xml_expression'
3
+ require 'glimmer/dsl/static_expression'
4
+
5
+ module Glimmer
6
+ module DSL
7
+ module XML
8
+ # This static html expression flips the DSL switch on for
9
+ # XML DSL in Glimmer
10
+ class MetaExpression < StaticExpression
11
+ include NodeParentExpression
12
+
13
+ def interpret(parent, keyword, *args, &block)
14
+ xml_expression.interpret(parent, keyword, *args, &block)
15
+ end
16
+
17
+ def xml_expression
18
+ @xml_expression ||= XmlExpression.new
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,37 @@
1
+ require 'glimmer/dsl/static_expression'
2
+ require 'glimmer/dsl/top_level_expression'
3
+ require 'glimmer/xml/node'
4
+ require 'glimmer/xml/depth_first_search_iterator'
5
+ require 'glimmer/xml/name_space_visitor'
6
+
7
+ module Glimmer
8
+ module DSL
9
+ module XML
10
+ class NameSpaceExpression < StaticExpression
11
+ include TopLevelExpression
12
+
13
+ def can_interpret?(parent, keyword, *args, &block)
14
+ (parent == nil or parent.is_a?(Glimmer::XML::Node)) and
15
+ (keyword.to_s == "name_space")
16
+ (args.size == 1) and
17
+ (args[0].is_a?(Symbol)) and
18
+ block
19
+ end
20
+
21
+ def interpret(parent, keyword, *args, &block)
22
+ node = block.call
23
+ unless node.is_a?(String)
24
+ name_space_visitor = Glimmer::XML::NameSpaceVisitor.new(args[0].to_s)
25
+ Glimmer::XML::DepthFirstSearchIterator.new(node, name_space_visitor).iterate
26
+ def node.process_block(block)
27
+ Glimmer.logger&.debug 'block'
28
+ #NOOP
29
+ end
30
+ end
31
+ parent.children << node if parent and !parent.children.include?(node)
32
+ node
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,33 @@
1
+ require 'glimmer'
2
+ require 'glimmer/dsl/parent_expression'
3
+ require 'glimmer/xml/node'
4
+
5
+ module Glimmer
6
+ module DSL
7
+ module XML
8
+ module NodeParentExpression
9
+ include ParentExpression
10
+ include Glimmer
11
+
12
+ def add_content(parent, &block)
13
+ return_value = block.call(parent)
14
+ if !return_value.is_a?(Glimmer::XML::Node) and !parent.children.include?(return_value)
15
+ text = return_value.to_s
16
+ first_match = text.match(/[#][^{]+[{][^}]+[}]/)
17
+ match = first_match
18
+ while (match)
19
+ instance_eval(parent.text_command(match.pre_match))
20
+ tag_text = match.to_s
21
+ instance_eval(parent.rubyize(tag_text))
22
+ text = tag_text
23
+ post_match = match.post_match
24
+ match = text.match(/[#]\w+[{]\w+[}]/)
25
+ end
26
+ instance_eval(parent.text_command(post_match)) if post_match
27
+ parent.children << return_value unless first_match
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,29 @@
1
+ require 'glimmer/dsl/xml/node_parent_expression'
2
+ require 'glimmer/dsl/xml/xml_expression'
3
+ require 'glimmer/dsl/static_expression'
4
+ require 'glimmer/dsl/top_level_expression'
5
+ require 'glimmer/xml/node'
6
+
7
+ module Glimmer
8
+ module DSL
9
+ module XML
10
+ class TagExpression < StaticExpression
11
+ include TopLevelExpression
12
+ include NodeParentExpression
13
+
14
+ def can_interpret?(parent, keyword, *args, &block)
15
+ (parent == nil or parent.is_a?(Glimmer::XML::Node)) and
16
+ (keyword.to_s == "tag") and
17
+ args[0].include?(:_name)
18
+ end
19
+
20
+ def interpret(parent, keyword, *args, &block)
21
+ attributes = args[0] if (args.size == 1)
22
+ tag_name = attributes[:_name]
23
+ attributes.delete(:_name)
24
+ Glimmer::XML::Node.new(parent, tag_name, attributes, &block)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,22 @@
1
+ require 'glimmer/dsl/static_expression'
2
+ require 'glimmer/xml/node'
3
+
4
+ module Glimmer
5
+ module DSL
6
+ module XML
7
+ class TextExpression < StaticExpression
8
+ def can_interpret?(parent, keyword, *args, &block)
9
+ (parent == nil or parent.is_a?(Glimmer::XML::Node)) and
10
+ (keyword.to_s == "text") and
11
+ (args.size == 1) and
12
+ !block
13
+ end
14
+
15
+ def interpret(parent, keyword, *args, &block)
16
+ parent.children << args[0].to_s if parent
17
+ args[0].to_s
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ require 'glimmer/dsl/xml/node_parent_expression'
2
+ require 'glimmer/dsl/expression'
3
+ require 'glimmer/xml/node'
4
+
5
+ module Glimmer
6
+ module DSL
7
+ module XML
8
+ class XmlExpression < Expression
9
+ include NodeParentExpression
10
+
11
+ def can_interpret?(parent, keyword, *args, &block)
12
+ parent.is_a?(Glimmer::XML::Node)
13
+ end
14
+
15
+ def interpret(parent, keyword, *args, &block)
16
+ Glimmer::XML::Node.new(parent, keyword.to_s, args, &block)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -11,7 +11,7 @@ namespace :glimmer do
11
11
  system('warble config')
12
12
  new_config = File.read('config/warble.rb').split("\n").inject('') do |output, line|
13
13
  if line.include?('config.dirs =')
14
- line = line.sub('# ', '').sub(/=[^=\n]+$/, '= %w(app config db lib script bin images sounds videos)')
14
+ line = line.sub('# ', '').sub(/=[^=\n]+$/, '= %w(app config db lib script bin docs fonts images sounds videos)')
15
15
  end
16
16
  if line.include?('config.autodeploy_dir =')
17
17
  line = line.sub('# ', '')
@@ -2,7 +2,6 @@ require 'glimmer/swt/swt_proxy'
2
2
  require 'glimmer/swt/widget_proxy'
3
3
  require 'glimmer/swt/display_proxy'
4
4
  require 'glimmer/swt/swt_proxy'
5
- require 'glimmer/dsl/shell_expression'
6
5
 
7
6
  module Glimmer
8
7
  module SWT
@@ -102,7 +101,7 @@ module Glimmer
102
101
  end
103
102
 
104
103
  def content(&block)
105
- Glimmer::DSL::Engine.add_content(self, DSL::ShellExpression.new, &block)
104
+ Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::SWT::ShellExpression.new, &block)
106
105
  end
107
106
 
108
107
  # (happens as part of `#open`)
@@ -4,7 +4,6 @@ require 'glimmer/swt/color_proxy'
4
4
  require 'glimmer/swt/font_proxy'
5
5
  require 'glimmer/swt/swt_proxy'
6
6
  require 'glimmer/data_binding/observable_widget'
7
- require 'glimmer/dsl/widget_expression'
8
7
 
9
8
  module Glimmer
10
9
  module SWT
@@ -267,7 +266,7 @@ module Glimmer
267
266
  end
268
267
 
269
268
  def content(&block)
270
- Glimmer::DSL::Engine.add_content(self, DSL::WidgetExpression.new, &block)
269
+ Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::SWT::WidgetExpression.new, &block)
271
270
  end
272
271
 
273
272
  private
@@ -432,7 +431,11 @@ module Glimmer
432
431
  value.to_java :string
433
432
  end,
434
433
  :text => proc do |value|
435
- value.to_s
434
+ if swt_widget.is_a?(Browser)
435
+ value.to_s
436
+ else
437
+ value.to_s
438
+ end
436
439
  end,
437
440
  :visible => proc do |value|
438
441
  !!value
@@ -109,7 +109,6 @@ module Glimmer
109
109
  @before_body_blocks << block
110
110
  end
111
111
 
112
- # TODO rename to content as well as before and after blocks
113
112
  def body(&block)
114
113
  @body_block = block
115
114
  end
@@ -155,11 +154,11 @@ module Glimmer
155
154
  end
156
155
 
157
156
  def can_add_observer?(attribute_name)
158
- respond_to?(attribute_name) || respond_to?("#{attribute_name}?") || @body_root.can_add_observer?(attribute_name)
157
+ has_instance_method?(attribute_name) || respond_to?("#{attribute_name}?") || @body_root.can_add_observer?(attribute_name)
159
158
  end
160
159
 
161
160
  def add_observer(observer, attribute_name)
162
- if respond_to?(attribute_name)
161
+ if has_instance_method?(attribute_name)
163
162
  super
164
163
  else
165
164
  @body_root.add_observer(observer, attribute_name)
@@ -179,8 +178,13 @@ module Glimmer
179
178
  end
180
179
  end
181
180
 
181
+ # This method ensures it has an instance method not coming from Glimmer DSL
182
+ def has_instance_method?(method_name)
183
+ respond_to?(method_name) && !method(method_name)&.source_location&.first&.include?('glimmer/dsl/engine.rb')
184
+ end
185
+
182
186
  def get_attribute(attribute_name)
183
- if respond_to?(attribute_name)
187
+ if has_instance_method?(attribute_name)
184
188
  send(attribute_name)
185
189
  else
186
190
  @body_root.get_attribute(attribute_name)
@@ -1,8 +1,6 @@
1
1
  require 'glimmer/ui/custom_widget'
2
2
  require 'glimmer/swt/color_proxy'
3
3
 
4
- #TODO consider the need to display a progress wheel while loading video as an option
5
-
6
4
  module Glimmer
7
5
  module UI
8
6
  class Video
@@ -27,38 +25,43 @@ module Glimmer
27
25
 
28
26
  body {
29
27
  browser(:no_scroll) {
30
- text <<~HTML
31
- <html>
32
- <head>
33
- <style id="style">
28
+ text html {
29
+ head {
30
+ style(id: "style") {
31
+ css {
34
32
  body {
35
- margin: 0;
36
- padding: 0;
37
- overflow: hidden;
33
+ margin 0
34
+ padding 0
35
+ overflow :hidden
38
36
  }
39
- </style>
40
- <style id="style-body-background">
37
+ }
38
+ }
39
+ style(id: "style-body-background") {
40
+ css {
41
41
  body {
42
- background: #{browser_body_background};
42
+ p 'background', browser_body_background
43
43
  }
44
- </style>
45
- <style id="style-body-offset-x">
44
+ }
45
+ }
46
+ style(id: "style-body-offset-x") {
47
+ css {
46
48
  body {
47
- margin-left: #{browser_body_offset_x}px;
49
+ margin_left "#{browser_body_offset_x}px"
48
50
  }
49
- </style>
50
- <style id="style-body-offset-y">
51
+ }
52
+ }
53
+ style(id: "style-body-offset-y") {
54
+ css {
51
55
  body {
52
- margin-top: #{browser_body_offset_y}px;
56
+ margin_top "#{browser_body_offset_y}px"
53
57
  }
54
- </style>
55
- </head>
56
- <body>
57
- <video id="video" src="#{source}" #{browser_video_width} #{browser_video_height} #{browser_video_loop} #{browser_video_controls} #{browser_video_autoplay}>
58
- </video>
59
- </body>
60
- </html>
61
- HTML
58
+ }
59
+ }
60
+ }
61
+ body {
62
+ video(browser_video_loop, browser_video_controls, browser_video_autoplay, id: 'video', src: source, width: browser_video_width, height: browser_video_height)
63
+ }
64
+ }
62
65
  on_completed {
63
66
  @completed = true
64
67
  }
@@ -257,11 +260,11 @@ module Glimmer
257
260
  end
258
261
 
259
262
  def browser_video_width
260
- "width='100%'" if fit_to_width
263
+ "100%" if fit_to_width
261
264
  end
262
265
 
263
266
  def browser_video_height
264
- "height='100%'" if fit_to_height
267
+ "100%" if fit_to_height
265
268
  end
266
269
 
267
270
  def browser_body_background
@@ -0,0 +1,22 @@
1
+ require 'glimmer/xml/node'
2
+
3
+ module Glimmer
4
+ module XML
5
+ class DepthFirstSearchIterator
6
+ def initialize(node, node_visitor)
7
+ @node = node
8
+ @node_visitor = node_visitor
9
+ end
10
+
11
+ def iterate
12
+ process(@node)
13
+ end
14
+
15
+ def process(node)
16
+ @node_visitor.process_before_children(node)
17
+ node.children.each { |child| process(child) } if node.is_a?(Node)
18
+ @node_visitor.process_after_children(node)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + "/node_visitor"
2
+
3
+ module Glimmer
4
+ module XML
5
+ class NameSpaceVisitor < NodeVisitor
6
+
7
+ def initialize(name_space_name)
8
+ @name_space_name = name_space_name
9
+ end
10
+
11
+ def process_before_children(node)
12
+ return if node.is_a?(String)
13
+ node.name_space = Node.new(nil, @name_space_name, nil) if node and !node.name_space
14
+ end
15
+
16
+ def process_after_children(node)
17
+ #NOOP
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,75 @@
1
+ require 'glimmer'
2
+ require 'glimmer/xml/depth_first_search_iterator'
3
+ require 'glimmer/xml/xml_visitor'
4
+
5
+ module Glimmer
6
+ module XML
7
+ class Node
8
+ include Glimmer
9
+
10
+ attr_accessor :children, :name, :contents, :attributes, :is_name_space, :is_attribute, :name_space, :parent
11
+
12
+ def initialize(parent, name, attributes, &contents)
13
+ @is_name_space = false
14
+ @children = []
15
+ @parent = parent
16
+ if attributes.is_a?(Array)
17
+ attributes = attributes.compact
18
+ hash_attributes = attributes.last.is_a?(Hash) ? attributes.delete(attributes.last) : {}
19
+ hash_attributes = attributes.reduce(hash_attributes) do |hash, attribute|
20
+ hash.merge(attribute => nil)
21
+ end
22
+ attributes = hash_attributes
23
+ end
24
+ if (parent and parent.is_name_space)
25
+ @name_space = parent
26
+ @parent = @name_space.parent
27
+ end
28
+ @parent.children << self if @parent
29
+ @name = name
30
+ @contents = contents
31
+ @attributes = attributes
32
+ if @attributes
33
+ @attributes.each_key do |attribute|
34
+ if attribute.is_a?(Node)
35
+ attribute.is_attribute = true
36
+ attribute.parent.children.delete(attribute) if attribute.parent
37
+ attribute.parent = nil #attributes do not usually have parents
38
+ end
39
+ end
40
+ Glimmer.logger&.debug(attributes)
41
+ end
42
+ end
43
+
44
+ def method_missing(symbol, *args, &block)
45
+ @is_name_space = true
46
+ parent.children.delete(self) if parent
47
+ Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::XML::HtmlExpression.new) {@tag = super}
48
+ @tag
49
+ end
50
+
51
+ def to_xml
52
+ xml_visitor = XmlVisitor.new
53
+ DepthFirstSearchIterator.new(self, xml_visitor).iterate
54
+ xml_visitor.document
55
+ end
56
+ alias to_html to_xml
57
+ alias to_s to_xml
58
+
59
+ def text_command(text)
60
+ "text \"#{text}\""
61
+ end
62
+
63
+ def rubyize(text)
64
+ text = text.gsub(/[}]/, '"}')
65
+ text = text.gsub(/[{]/, '{"')
66
+ text = text.gsub(/[#]/, '')
67
+ end
68
+
69
+ #override Object default id method and route it to Glimmer engine
70
+ def id
71
+ method_missing(:id)
72
+ end
73
+ end
74
+ end
75
+ end