glimmer 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/README.markdown +212 -161
  3. data/RUBY_VERSION +1 -0
  4. data/VERSION +1 -0
  5. data/icons/scaffold_app.icns +0 -0
  6. data/lib/glimmer.rb +5 -47
  7. data/lib/glimmer/config.rb +35 -0
  8. data/lib/glimmer/css/{rule_set.rb → rule.rb} +3 -5
  9. data/lib/glimmer/css/style_sheet.rb +4 -5
  10. data/lib/glimmer/data_binding/observable_model.rb +1 -1
  11. data/lib/glimmer/dsl/css/dsl.rb +2 -2
  12. data/lib/glimmer/dsl/css/dynamic_property_expression.rb +12 -0
  13. data/lib/glimmer/dsl/css/property_expression.rb +3 -3
  14. data/lib/glimmer/dsl/css/pv_expression.rb +17 -0
  15. data/lib/glimmer/dsl/css/{rule_set_expression.rb → rule_expression.rb} +4 -4
  16. data/lib/glimmer/dsl/css/s_expression.rb +3 -3
  17. data/lib/glimmer/dsl/engine.rb +35 -5
  18. data/lib/glimmer/dsl/expression_handler.rb +3 -3
  19. data/lib/glimmer/dsl/swt/color_expression.rb +2 -0
  20. data/lib/glimmer/dsl/swt/dsl.rb +2 -0
  21. data/lib/glimmer/dsl/swt/tab_item_expression.rb +1 -1
  22. data/lib/glimmer/dsl/swt/widget_listener_expression.rb +5 -5
  23. data/lib/glimmer/dsl/xml/name_space_expression.rb +1 -1
  24. data/lib/glimmer/launcher.rb +64 -19
  25. data/lib/glimmer/rake_task.rb +64 -23
  26. data/lib/glimmer/scaffold.rb +442 -0
  27. data/lib/glimmer/swt/layout_data_proxy.rb +1 -1
  28. data/lib/glimmer/swt/layout_proxy.rb +2 -2
  29. data/lib/glimmer/swt/swt_proxy.rb +3 -3
  30. data/lib/glimmer/swt/widget_proxy.rb +5 -5
  31. data/lib/glimmer/ui/custom_widget.rb +3 -3
  32. data/lib/glimmer/xml/node.rb +1 -1
  33. data/lib/glimmer/xml/xml_visitor.rb +2 -2
  34. metadata +16 -42
  35. data/bin/gladiator +0 -6
  36. data/lib/glimmer/dsl/css/p_expression.rb +0 -25
  37. data/lib/glimmer/ui/video.rb +0 -289
  38. data/samples/gladiator.rb +0 -765
@@ -0,0 +1 @@
1
+ jruby-9.2.11.1
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.7.0
Binary file
@@ -23,47 +23,12 @@ module Glimmer
23
23
 
24
24
  class << self
25
25
  def included(klass)
26
- if import_swt_packages
26
+ if Config.import_swt_packages
27
27
  klass.include(SWT::Packages)
28
28
  klass.extend(SWT::Packages)
29
29
  klass.extend(Glimmer)
30
30
  end
31
31
  end
32
-
33
- # Tells Glimmer to import SWT packages into including class (default: true)
34
- def import_swt_packages=(value)
35
- @@import_swt_packages = !!value
36
- end
37
-
38
- # Returns whether Glimmer will import SWT packages into including class
39
- def import_swt_packages
40
- unless defined? @@import_swt_packages
41
- @@import_swt_packages = true
42
- end
43
- @@import_swt_packages
44
- end
45
-
46
- # Returns Glimmer logger (standard Ruby logger)
47
- def logger
48
- # unless defined? @@logger
49
- # @@logger = Logger.new(STDOUT).tap {|logger| logger.level = Logger::WARN}
50
- # end
51
- @@logger if defined? @@logger
52
- end
53
-
54
- def enable_logging
55
- @@logger = Logger.new(STDOUT).tap {|logger| logger.level = Logger::WARN}
56
- end
57
-
58
- # Sets current DSL (e.g. :swt)
59
- def dsl=(dsl_name)
60
- Glimmer::DSL::Engine.dsl = dsl_name
61
- end
62
-
63
- # Currently set DSL (e.g. :swt or :xml)
64
- def dsl
65
- Glimmer::DSL::Engine.dsl
66
- end
67
32
  end
68
33
 
69
34
  def method_missing(method_symbol, *args, &block)
@@ -71,30 +36,23 @@ module Glimmer
71
36
  if method_symbol.to_s.match(REGEX_METHODS_EXCLUDED)
72
37
  raise InvalidKeywordError, "Glimmer excluded keyword: #{method_symbol}"
73
38
  end
74
- Glimmer.logger&.debug "Interpreting keyword: #{method_symbol}"
39
+ Glimmer::Config.logger&.debug "Interpreting keyword: #{method_symbol}"
75
40
  Glimmer::DSL::Engine.interpret(method_symbol, *args, &block)
76
41
  rescue InvalidKeywordError => e
77
42
  if !method_symbol.to_s.match(REGEX_METHODS_EXCLUDED)
78
- Glimmer.logger&.error e.message
43
+ Glimmer::Config.logger&.error e.message
79
44
  end
80
- Glimmer.logger&.debug "#{e.message}\n#{e.backtrace.join("\n")}"
45
+ Glimmer::Config.logger&.debug "#{e.message}\n#{e.backtrace.join("\n")}"
81
46
  super(method_symbol, *args, &block)
82
47
  end
83
48
  end
84
49
 
85
- if ENV['GLIMMER_LOGGER_LEVEL']
86
- Glimmer.enable_logging
87
- Glimmer.logger.level = ENV['GLIMMER_LOGGER_LEVEL'].downcase
88
- end
89
-
90
50
  $LOAD_PATH.unshift(File.expand_path('..', __FILE__))
91
51
 
92
- require 'glimmer/launcher'
93
- require Glimmer::Launcher.swt_jar_file
52
+ require 'glimmer/config'
94
53
  require 'glimmer/swt/packages'
95
54
  require 'glimmer/dsl/swt/dsl'
96
55
  require 'glimmer/dsl/xml/dsl'
97
56
  require 'glimmer/dsl/css/dsl'
98
57
  require 'glimmer/error'
99
58
  require 'glimmer/invalid_keyword_error'
100
- require 'glimmer/ui/video'
@@ -0,0 +1,35 @@
1
+ module Glimmer
2
+ module Config
3
+ class << self
4
+ # Tells Glimmer to import SWT packages into including class (default: true)
5
+ def import_swt_packages=(value)
6
+ @@import_swt_packages = !!value
7
+ end
8
+
9
+ # Returns whether Glimmer will import SWT packages into including class
10
+ def import_swt_packages
11
+ unless defined? @@import_swt_packages
12
+ @@import_swt_packages = true
13
+ end
14
+ @@import_swt_packages
15
+ end
16
+
17
+ # Returns Glimmer logger (standard Ruby logger)
18
+ def logger
19
+ # unless defined? @@logger
20
+ # @@logger = Logger.new(STDOUT).tap {|logger| logger.level = Logger::WARN}
21
+ # end
22
+ @@logger if defined? @@logger
23
+ end
24
+
25
+ def enable_logging
26
+ @@logger = Logger.new(STDOUT).tap {|logger| logger.level = Logger::WARN}
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ if ENV['GLIMMER_LOGGER_LEVEL']
33
+ Glimmer::Config.enable_logging
34
+ Glimmer::Config.logger.level = ENV['GLIMMER_LOGGER_LEVEL'].downcase
35
+ end
@@ -1,6 +1,6 @@
1
1
  module Glimmer
2
2
  module CSS
3
- class RuleSet
3
+ class Rule
4
4
  attr_reader :selector, :properties
5
5
 
6
6
  def initialize(selector)
@@ -14,10 +14,8 @@ module Glimmer
14
14
  end
15
15
 
16
16
  def to_css
17
- css = "#{@selector} {\n"
18
- @properties.each do |name, value|
19
- css << " #{name}: #{value};\n"
20
- end
17
+ css = "#{@selector}{"
18
+ css << @properties.map { |name, value| "#{name}:#{value}" }.join(';')
21
19
  css << "}"
22
20
  end
23
21
 
@@ -1,17 +1,16 @@
1
- require 'glimmer/css/rule_set'
1
+ require 'glimmer/css/rule'
2
2
 
3
3
  module Glimmer
4
4
  module CSS
5
5
  class StyleSheet
6
- attr_reader :rule_sets
6
+ attr_reader :rules
7
7
 
8
8
  def initialize
9
- @rule_sets = []
9
+ @rules = []
10
10
  end
11
11
 
12
12
  def to_css
13
- rule_set_css = rule_sets.map(&:to_css).join("\n\n")
14
- "#{rule_set_css}\n"
13
+ rules.map(&:to_css).join
15
14
  end
16
15
 
17
16
  alias to_s to_css
@@ -76,7 +76,7 @@ module Glimmer
76
76
  end
77
77
  rescue => e
78
78
  # ignore writing if no property writer exists
79
- Glimmer.logger&.debug "No need to observe property writer: #{property_writer_name}\n#{e.message}\n#{e.backtrace.join("\n")}"
79
+ Glimmer::Config.logger&.debug "No need to observe property writer: #{property_writer_name}\n#{e.message}\n#{e.backtrace.join("\n")}"
80
80
  end
81
81
 
82
82
  def unregister_dependent_observers(property_name, old_value)
@@ -4,7 +4,7 @@ Dir[File.expand_path('../*_expression.rb', __FILE__)].each {|f| require f}
4
4
  Glimmer::DSL::Engine.add_dynamic_expressions(
5
5
  Glimmer::DSL::CSS,
6
6
  %w[
7
- rule_set
8
- property
7
+ rule
8
+ dynamic_property
9
9
  ]
10
10
  )
@@ -0,0 +1,12 @@
1
+ require 'glimmer/dsl/expression'
2
+ require 'glimmer/dsl/css/property_expression'
3
+
4
+ module Glimmer
5
+ module DSL
6
+ module CSS
7
+ class DynamicPropertyExpression < Expression
8
+ include PropertyExpression
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,14 +1,14 @@
1
1
  require 'glimmer/dsl/expression'
2
- require 'glimmer/css/rule_set'
2
+ require 'glimmer/css/rule'
3
3
 
4
4
  module Glimmer
5
5
  module DSL
6
6
  module CSS
7
- class PropertyExpression < Expression
7
+ module PropertyExpression
8
8
  include ParentExpression
9
9
 
10
10
  def can_interpret?(parent, keyword, *args, &block)
11
- parent.is_a?(Glimmer::CSS::RuleSet) and
11
+ parent.is_a?(Glimmer::CSS::Rule) and
12
12
  !block_given? and
13
13
  !args.empty?
14
14
  end
@@ -0,0 +1,17 @@
1
+ require 'glimmer/dsl/static_expression'
2
+ require 'glimmer/dsl/css/property_expression'
3
+
4
+ module Glimmer
5
+ module DSL
6
+ module CSS
7
+ # Static keyword 'pv' version of CSS DSL dynamic property expression
8
+ class PVExpression < StaticExpression
9
+ include PropertyExpression
10
+
11
+ def interpret(parent, keyword, *args, &block)
12
+ parent.add_property(args[0], args[1])
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,11 +1,11 @@
1
1
  require 'glimmer/dsl/expression'
2
2
  require 'glimmer/css/style_sheet'
3
- require 'glimmer/css/rule_set'
3
+ require 'glimmer/css/rule'
4
4
 
5
5
  module Glimmer
6
6
  module DSL
7
7
  module CSS
8
- class RuleSetExpression < Expression
8
+ class RuleExpression < Expression
9
9
  include ParentExpression
10
10
 
11
11
  def can_interpret?(parent, keyword, *args, &block)
@@ -15,8 +15,8 @@ module Glimmer
15
15
  end
16
16
 
17
17
  def interpret(parent, keyword, *args, &block)
18
- Glimmer::CSS::RuleSet.new(keyword.to_s.downcase).tap do |rule_set|
19
- parent.rule_sets << rule_set
18
+ Glimmer::CSS::Rule.new(keyword.to_s.downcase).tap do |rule|
19
+ parent.rules << rule
20
20
  end
21
21
  end
22
22
  end
@@ -1,6 +1,6 @@
1
1
  require 'glimmer/dsl/static_expression'
2
2
  require 'glimmer/css/style_sheet'
3
- require 'glimmer/css/rule_set'
3
+ require 'glimmer/css/rule'
4
4
 
5
5
  module Glimmer
6
6
  module DSL
@@ -16,8 +16,8 @@ module Glimmer
16
16
  end
17
17
 
18
18
  def interpret(parent, keyword, *args, &block)
19
- Glimmer::CSS::RuleSet.new(args.first.to_s).tap do |rule_set|
20
- parent.rule_sets << rule_set
19
+ Glimmer::CSS::Rule.new(args.first.to_s).tap do |rule|
20
+ parent.rules << rule
21
21
  end
22
22
  end
23
23
  end
@@ -24,6 +24,36 @@ module Glimmer
24
24
  dsl_stack.last
25
25
  end
26
26
 
27
+ def dsls
28
+ static_expressions.values.map(&:keys).flatten.uniq
29
+ end
30
+
31
+ def disable_dsl(dsl_name)
32
+ dsl_name = dsl_name.to_sym
33
+ disabled_dsls << dsl_name
34
+ end
35
+
36
+ def enable_dsl(dsl_name)
37
+ dsl_name = dsl_name.to_sym
38
+ disabled_dsls.delete(dsl_name)
39
+ end
40
+
41
+ def disabled_dsls
42
+ @disabled_dsls ||= []
43
+ end
44
+
45
+ def enabled_dsls=(dsl_names)
46
+ dsls.each {|dsl_name| disable_dsl(dsl_name)}
47
+ dsl_names.each {|dsl_name| enable_dsl(dsl_name)}
48
+ end
49
+
50
+ # Resets Glimmer's engine activity and configuration. Useful in rspec before or after blocks in tests.
51
+ def reset
52
+ parent_stack.clear
53
+ dsl_stack.clear
54
+ disabled_dsls.clear
55
+ end
56
+
27
57
  # Dynamic expression chains of responsibility indexed by dsl
28
58
  def dynamic_expression_chains_of_responsibility
29
59
  @dynamic_expression_chains_of_responsibility ||= {}
@@ -46,7 +76,7 @@ module Glimmer
46
76
  dynamic_expression_chains_of_responsibility[dsl] = expression_names.reverse.map do |expression_name|
47
77
  expression_class(dsl_namespace, expression_name).new
48
78
  end.reduce(nil) do |last_expresion_handler, expression|
49
- Glimmer.logger&.debug "Adding dynamic expression: #{expression.class.name}"
79
+ Glimmer::Config.logger&.debug "Adding dynamic expression: #{expression.class.name}"
50
80
  expression_handler = ExpressionHandler.new(expression)
51
81
  expression_handler.next = last_expresion_handler if last_expresion_handler
52
82
  expression_handler
@@ -54,7 +84,7 @@ module Glimmer
54
84
  end
55
85
 
56
86
  def add_static_expression(static_expression)
57
- Glimmer.logger&.debug "Adding static expression: #{static_expression.class.name}"
87
+ Glimmer::Config.logger&.debug "Adding static expression: #{static_expression.class.name}"
58
88
  keyword = static_expression.class.keyword
59
89
  static_expression_dsl = static_expression.class.dsl
60
90
  static_expressions[keyword] ||= {}
@@ -62,7 +92,7 @@ module Glimmer
62
92
  Glimmer.define_method(keyword) do |*args, &block|
63
93
  begin
64
94
  retrieved_static_expression = Glimmer::DSL::Engine.static_expressions[keyword][Glimmer::DSL::Engine.dsl]
65
- static_expression_dsl = Glimmer::DSL::Engine.static_expressions[keyword].keys.first if retrieved_static_expression.nil?
95
+ static_expression_dsl = (Glimmer::DSL::Engine.static_expressions[keyword].keys - Glimmer::DSL::Engine.disabled_dsls).first if retrieved_static_expression.nil?
66
96
  if retrieved_static_expression.nil? && Glimmer::DSL::Engine.dsl && (static_expression_dsl.nil? || !Glimmer::DSL::Engine.static_expressions[keyword][static_expression_dsl].is_a?(TopLevelExpression))
67
97
  begin
68
98
  return Glimmer::DSL::Engine.interpret(keyword, *args, &block)
@@ -76,7 +106,7 @@ module Glimmer
76
106
  if !static_expression.can_interpret?(Glimmer::DSL::Engine.parent, keyword, *args, &block)
77
107
  raise Error, "Invalid use of Glimmer keyword #{keyword} with args #{args} under parent #{Glimmer::DSL::Engine.parent}"
78
108
  else
79
- Glimmer.logger&.debug "#{static_expression.class.name} will handle expression keyword #{keyword}"
109
+ Glimmer::Config.logger&.debug "#{static_expression.class.name} will handle expression keyword #{keyword}"
80
110
  return static_expression.interpret(Glimmer::DSL::Engine.parent, keyword, *args, &block).tap do |ui_object|
81
111
  Glimmer::DSL::Engine.add_content(ui_object, static_expression, &block) unless block.nil?
82
112
  Glimmer::DSL::Engine.dsl_stack.pop
@@ -100,7 +130,7 @@ module Glimmer
100
130
  # Interprets Glimmer dynamic DSL expression consisting of keyword, args, and block (e.g. shell(:no_resize) { ... })
101
131
  def interpret(keyword, *args, &block)
102
132
  keyword = keyword.to_s
103
- dynamic_expression_dsl = dynamic_expression_chains_of_responsibility.keys.first if dsl.nil?
133
+ dynamic_expression_dsl = (dynamic_expression_chains_of_responsibility.keys - disabled_dsls).first if dsl.nil?
104
134
  dsl_stack.push(dynamic_expression_dsl || dsl)
105
135
  expression = dynamic_expression_chains_of_responsibility[dsl].handle(parent, keyword, *args, &block)
106
136
  expression.interpret(parent, keyword, *args, &block).tap do |ui_object|
@@ -23,9 +23,9 @@ module Glimmer
23
23
  # Otherwise, it forwards to the next handler configured via `#next=` method
24
24
  # If there is no handler next, then it raises an error
25
25
  def handle(parent, keyword, *args, &block)
26
- Glimmer.logger&.debug "Attempting to handle #{keyword} with #{@expression.class.name.split(":").last}"
26
+ Glimmer::Config.logger&.debug "Attempting to handle #{keyword} with #{@expression.class.name.split(":").last}"
27
27
  if @expression.can_interpret?(parent, keyword, *args, &block)
28
- Glimmer.logger&.debug "#{@expression.class.name} will handle expression keyword #{keyword}"
28
+ Glimmer::Config.logger&.debug "#{@expression.class.name} will handle expression keyword #{keyword}"
29
29
  return @expression
30
30
  elsif @next_expression_handler
31
31
  return @next_expression_handler.handle(parent, keyword, *args, &block)
@@ -34,7 +34,7 @@ module Glimmer
34
34
  message = "Glimmer keyword #{keyword} with args #{args} cannot be handled"
35
35
  message += " inside parent #{parent}" if parent
36
36
  message += "! Check the validity of the code."
37
- # Glimmer.logger&.error message
37
+ # Glimmer::Config.logger&.error message
38
38
  raise InvalidKeywordError, message
39
39
  end
40
40
  end
@@ -1,4 +1,5 @@
1
1
  require 'glimmer/dsl/static_expression'
2
+ require 'glimmer/dsl/top_level_expression'
2
3
  require 'glimmer/swt/color_proxy'
3
4
  require 'glimmer/swt/display_proxy'
4
5
 
@@ -6,6 +7,7 @@ module Glimmer
6
7
  module DSL
7
8
  module SWT
8
9
  class ColorExpression < StaticExpression
10
+ include TopLevelExpression
9
11
  include_package 'org.eclipse.swt.widgets'
10
12
 
11
13
  def interpret(parent, keyword, *args, &block)
@@ -1,3 +1,5 @@
1
+ require 'glimmer/launcher'
2
+ require Glimmer::Launcher.swt_jar_file
1
3
  require 'glimmer/dsl/engine'
2
4
  Dir[File.expand_path('../*_expression.rb', __FILE__)].each {|f| require f}
3
5
 
@@ -18,7 +18,7 @@ module Glimmer
18
18
  if parent.swt_widget.is_a?(TabFolder)
19
19
  return true
20
20
  else
21
- Glimmer.logger&.error "tab_item widget may only be used directly under a tab_folder widget!"
21
+ Glimmer::Config.logger&.error "tab_item widget may only be used directly under a tab_folder widget!"
22
22
  end
23
23
  end
24
24
  false
@@ -8,17 +8,17 @@ module Glimmer
8
8
  include_package 'org.eclipse.swt.widgets'
9
9
 
10
10
  def can_interpret?(parent, keyword, *args, &block)
11
- Glimmer.logger&.debug "keyword starts with on_: #{keyword.start_with?('on_')}"
11
+ Glimmer::Config.logger&.debug "keyword starts with on_: #{keyword.start_with?('on_')}"
12
12
  return false unless keyword.start_with?('on_')
13
13
  widget_or_display_parentage = widget?(parent) || parent.is_a?(Glimmer::SWT::DisplayProxy)
14
- Glimmer.logger&.debug "parent is a widget or display: #{widget_or_display_parentage}"
14
+ Glimmer::Config.logger&.debug "parent is a widget or display: #{widget_or_display_parentage}"
15
15
  return false unless widget_or_display_parentage
16
- Glimmer.logger&.debug "block exists?: #{!block.nil?}"
16
+ Glimmer::Config.logger&.debug "block exists?: #{!block.nil?}"
17
17
  raise Glimmer::Error, "Listener is missing block for keyword: #{keyword}" unless block_given?
18
- Glimmer.logger&.debug "args are empty?: #{args.empty?}"
18
+ Glimmer::Config.logger&.debug "args are empty?: #{args.empty?}"
19
19
  raise Glimmer::Error, "Invalid listener arguments for keyword: #{keyword}(#{args})" unless args.empty?
20
20
  result = parent.can_handle_observation_request?(keyword)
21
- Glimmer.logger&.debug "can add listener? #{result}"
21
+ Glimmer::Config.logger&.debug "can add listener? #{result}"
22
22
  raise Glimmer::Error, "Invalid listener keyword: #{keyword}" unless result
23
23
  true
24
24
  end
@@ -24,7 +24,7 @@ module Glimmer
24
24
  name_space_visitor = Glimmer::XML::NameSpaceVisitor.new(args[0].to_s)
25
25
  Glimmer::XML::DepthFirstSearchIterator.new(node, name_space_visitor).iterate
26
26
  def node.process_block(block)
27
- Glimmer.logger&.debug 'block'
27
+ Glimmer::Config.logger&.debug 'block'
28
28
  #NOOP
29
29
  end
30
30
  end