glimmer 0.1.0.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +20 -0
- data/README.markdown +54 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/bin/glimmer +132 -0
- data/glimmer.gemspec +145 -0
- data/images/Bitter-sweet.jpg +0 -0
- data/{src → lib}/command_handler.rb +7 -10
- data/{src → lib}/command_handler_chain_factory.rb +29 -22
- data/{src → lib}/command_handler_chain_link.rb +19 -22
- data/{src → lib}/command_handlers.rb +29 -26
- data/{src → lib}/command_handlers/bind_command_handler.rb +25 -28
- data/lib/command_handlers/combo_selection_data_binding_command_handler.rb +39 -0
- data/{src → lib}/command_handlers/data_binding_command_handler.rb +61 -64
- data/lib/command_handlers/list_selection_data_binding_command_handler.rb +42 -0
- data/lib/command_handlers/models/list_observer.rb +31 -0
- data/{src → lib}/command_handlers/models/model_observer.rb +28 -25
- data/{src → lib}/command_handlers/models/observable_array.rb +53 -46
- data/lib/command_handlers/models/observable_model.rb +61 -0
- data/{src → lib}/command_handlers/models/r_runnable.rb +11 -14
- data/{src → lib}/command_handlers/models/r_shell.rb +23 -26
- data/lib/command_handlers/models/r_tab_item_composite.rb +25 -0
- data/{src → lib}/command_handlers/models/r_widget.rb +16 -14
- data/lib/command_handlers/models/r_widget_listener.rb +9 -0
- data/{src → lib}/command_handlers/models/r_widget_packages.rb +5 -8
- data/{src → lib}/command_handlers/models/table_items_updater.rb +38 -39
- data/{src → lib}/command_handlers/models/widget_observer.rb +4 -6
- data/{src → lib}/command_handlers/shell_command_handler.rb +14 -17
- data/{src → lib}/command_handlers/swt_constant_command_handler.rb +18 -21
- data/lib/command_handlers/tab_item_command_handler.rb +22 -0
- data/{src → lib}/command_handlers/table_column_properties_data_binding_command_handler.rb +20 -23
- data/{src → lib}/command_handlers/table_items_data_binding_command_handler.rb +26 -29
- data/{src → lib}/command_handlers/widget_command_handler.rb +22 -25
- data/{src → lib}/command_handlers/widget_listener_command_handler.rb +36 -34
- data/{src → lib}/command_handlers/widget_method_command_handler.rb +18 -21
- data/{src → lib}/glimmer.rb +52 -45
- data/lib/parent.rb +5 -0
- data/{src → lib}/shine.rb +21 -24
- data/{src → lib}/xml_command_handlers.rb +15 -18
- data/{src → lib}/xml_command_handlers/html_command_handler.rb +45 -49
- data/{src → lib}/xml_command_handlers/models/depth_first_search_iterator.rb +17 -20
- data/{src → lib}/xml_command_handlers/models/name_space_visitor.rb +17 -20
- data/{src → lib}/xml_command_handlers/models/node.rb +80 -83
- data/{src → lib}/xml_command_handlers/models/node_visitor.rb +8 -11
- data/{src → lib}/xml_command_handlers/models/xml_visitor.rb +58 -61
- data/{src → lib}/xml_command_handlers/xml_command_handler.rb +18 -22
- data/{src → lib}/xml_command_handlers/xml_name_space_command_handler.rb +31 -34
- data/{src → lib}/xml_command_handlers/xml_tag_command_handler.rb +23 -26
- data/{src → lib}/xml_command_handlers/xml_text_command_handler.rb +19 -22
- data/samples/contactmanager/contact.rb +0 -3
- data/samples/contactmanager/contact_manager.rb +1 -4
- data/samples/contactmanager/contact_manager_presenter.rb +0 -3
- data/samples/contactmanager/contact_repository.rb +0 -3
- data/samples/hello_combo.rb +32 -0
- data/samples/hello_world.rb +1 -4
- data/samples/login.rb +1 -4
- data/samples/tictactoe/tic_tac_toe.rb +2 -5
- data/samples/tictactoe/tic_tac_toe_board.rb +0 -3
- data/test/glimmer_combo_data_binding_test.rb +131 -0
- data/test/glimmer_constant_test.rb +6 -11
- data/test/glimmer_data_binding_test.rb +16 -16
- data/test/glimmer_list_data_binding_test.rb +223 -0
- data/test/glimmer_listeners_test.rb +6 -6
- data/test/glimmer_shine_data_binding_test.rb +7 -6
- data/test/glimmer_tab_item_test.rb +61 -0
- data/test/glimmer_table_data_binding_test.rb +7 -20
- data/test/glimmer_test.rb +18 -13
- data/test/helper.rb +21 -0
- data/test/observable_model_test.rb +2 -4
- data/test/r_widget_test.rb +5 -5
- data/test/samples/contactmanager/contact_manager_presenter_test.rb +1 -4
- data/test/samples/tictactoe/tic_tac_toe_test.rb +1 -4
- data/test/xml/glimmer_xml_test.rb +43 -43
- metadata +210 -105
- data/COPYING.LGPL +0 -504
- data/README +0 -27
- data/src/command_handlers/models/observable_model.rb +0 -35
- data/src/command_handlers/models/r_widget_listener.rb +0 -12
- data/src/parent.rb +0 -8
- data/src/swt.rb +0 -10
- data/src/xml.rb +0 -10
data/lib/parent.rb
ADDED
data/{src → lib}/shine.rb
RENAMED
@@ -1,24 +1,21 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
1
|
+
require File.dirname(__FILE__) + "/glimmer"
|
2
|
+
|
3
|
+
class Array
|
4
|
+
include Glimmer
|
5
|
+
|
6
|
+
alias original_compare <=>
|
7
|
+
|
8
|
+
def <=>(other)
|
9
|
+
if (self[0].class.name == "RWidget")
|
10
|
+
add_contents(self[0]) {
|
11
|
+
if (other.size == 2)
|
12
|
+
eval("#{self[1]} bind (other[0], other[1])")
|
13
|
+
elsif (other.size == 3)
|
14
|
+
eval("#{self[1]} bind (other[0], other[1], other[2])")
|
15
|
+
end
|
16
|
+
}
|
17
|
+
else
|
18
|
+
original_compare(other)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,18 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
require File.dirname(__FILE__) + "/
|
5
|
-
require File.dirname(__FILE__) + "/xml_command_handlers/
|
6
|
-
require File.dirname(__FILE__) + "/xml_command_handlers/
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
HtmlCommandHandler.new,
|
17
|
-
XmlCommandHandler.new
|
18
|
-
)
|
1
|
+
require File.dirname(__FILE__) + "/command_handler_chain_factory"
|
2
|
+
require File.dirname(__FILE__) + "/xml_command_handlers/xml_name_space_command_handler"
|
3
|
+
require File.dirname(__FILE__) + "/xml_command_handlers/xml_text_command_handler"
|
4
|
+
require File.dirname(__FILE__) + "/xml_command_handlers/xml_tag_command_handler"
|
5
|
+
require File.dirname(__FILE__) + "/xml_command_handlers/html_command_handler"
|
6
|
+
require File.dirname(__FILE__) + "/xml_command_handlers/xml_command_handler"
|
7
|
+
|
8
|
+
# edit to add more command handlers and extend Glimmer
|
9
|
+
CommandHandlerChainFactory.def_dsl(:xml,
|
10
|
+
XmlNameSpaceCommandHandler.new,
|
11
|
+
XmlTextCommandHandler.new,
|
12
|
+
XmlTagCommandHandler.new,
|
13
|
+
HtmlCommandHandler.new,
|
14
|
+
XmlCommandHandler.new
|
15
|
+
)
|
@@ -1,49 +1,45 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
attributes
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
attributes[:class] = class_value if class_value
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
1
|
+
require File.dirname(__FILE__) + "/../command_handler"
|
2
|
+
require File.dirname(__FILE__) + "/models/node"
|
3
|
+
|
4
|
+
class HtmlCommandHandler
|
5
|
+
include CommandHandler
|
6
|
+
|
7
|
+
def can_handle?(parent, command_symbol, *args, &block)
|
8
|
+
(parent == nil or parent.is_a?(Node)) and
|
9
|
+
(args.size == 0 or ((args.size == 1) and ((args[0].is_a?(Hash)) or (args[0].is_a?(Hash)))))
|
10
|
+
end
|
11
|
+
|
12
|
+
def do_handle(parent, command_symbol, *args, &block)
|
13
|
+
attributes = Hash.new
|
14
|
+
attributes = args[0] if (args.size == 1)
|
15
|
+
append_id_and_class_attributes(command_symbol.to_s, attributes)
|
16
|
+
tag_name = parse_tag_name(command_symbol.to_s)
|
17
|
+
Node.new(parent, tag_name, attributes, &block)
|
18
|
+
end
|
19
|
+
|
20
|
+
def parse_tag_name(command)
|
21
|
+
match_data = command.match("_")
|
22
|
+
if (match_data.to_a.size > 0)
|
23
|
+
command.match("_").pre_match
|
24
|
+
else
|
25
|
+
command
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def append_id_and_class_attributes(command, attributes)
|
30
|
+
class_only_match = command.match("__.+").to_s
|
31
|
+
if class_only_match.length > 0
|
32
|
+
class_value = class_only_match[2, class_only_match.length]
|
33
|
+
else
|
34
|
+
match_data = command.match("_[^_]+")
|
35
|
+
return unless match_data
|
36
|
+
match = match_data.to_s
|
37
|
+
id_value = match[1, match.length] if match.length > 0
|
38
|
+
attributes[:id] = id_value if id_value
|
39
|
+
match2 = match_data.post_match.match("_[^_]+").to_s if match_data.post_match
|
40
|
+
class_value = match2[1, match2.length] if match2.length > 0
|
41
|
+
end
|
42
|
+
attributes[:class] = class_value if class_value
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -1,20 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
1
|
+
class DepthFirstSearchIterator
|
2
|
+
def initialize(node, node_visitor)
|
3
|
+
@node = node
|
4
|
+
@node_visitor = node_visitor
|
5
|
+
end
|
6
|
+
|
7
|
+
def iterate
|
8
|
+
process(@node)
|
9
|
+
end
|
10
|
+
|
11
|
+
def process(node)
|
12
|
+
@node_visitor.process_before_children(node)
|
13
|
+
node.children.each { |child| process(child) } unless node.is_a?(String)
|
14
|
+
@node_visitor.process_after_children(node)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -1,21 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
#NOOP
|
19
|
-
end
|
20
|
-
|
1
|
+
require File.dirname(__FILE__) + "/node_visitor"
|
2
|
+
|
3
|
+
class NameSpaceVisitor < NodeVisitor
|
4
|
+
|
5
|
+
def initialize(name_space_name)
|
6
|
+
@name_space_name = name_space_name
|
7
|
+
end
|
8
|
+
|
9
|
+
def process_before_children(node)
|
10
|
+
return if node.is_a?(String)
|
11
|
+
node.name_space = Node.new(nil, @name_space_name, nil) if node and !node.name_space
|
12
|
+
end
|
13
|
+
|
14
|
+
def process_after_children(node)
|
15
|
+
#NOOP
|
16
|
+
end
|
17
|
+
|
21
18
|
end
|
@@ -1,83 +1,80 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
@
|
21
|
-
@
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
@
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
end
|
82
|
-
|
83
|
-
end
|
1
|
+
require File.dirname(__FILE__) + "/depth_first_search_iterator"
|
2
|
+
require File.dirname(__FILE__) + "/xml_visitor"
|
3
|
+
|
4
|
+
class Node
|
5
|
+
include Parent, Glimmer
|
6
|
+
|
7
|
+
attr_accessor :children, :name, :contents, :attributes, :is_name_space, :is_attribute, :name_space, :parent
|
8
|
+
|
9
|
+
def initialize(parent, name, attributes, &contents)
|
10
|
+
@is_name_space = false
|
11
|
+
@children = []
|
12
|
+
@parent = parent
|
13
|
+
if (parent and parent.is_name_space)
|
14
|
+
@name_space = parent
|
15
|
+
@parent = @name_space.parent
|
16
|
+
end
|
17
|
+
@parent.children << self if @parent
|
18
|
+
@name = name
|
19
|
+
@contents = contents
|
20
|
+
@attributes = attributes
|
21
|
+
if @attributes
|
22
|
+
@attributes.each_key do |attribute|
|
23
|
+
if attribute.is_a?(Node)
|
24
|
+
attribute.is_attribute = true
|
25
|
+
attribute.parent.children.delete(attribute) if attribute.parent
|
26
|
+
attribute.parent = nil #attributes do not usually have parents
|
27
|
+
end
|
28
|
+
end
|
29
|
+
p attributes
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def method_missing(symbol, *args, &block)
|
34
|
+
@is_name_space = true
|
35
|
+
parent.children.delete(self) if parent
|
36
|
+
Glimmer.add_contents(self) {@tag = super}
|
37
|
+
@tag
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_xml
|
41
|
+
xml_visitor = XmlVisitor.new
|
42
|
+
DepthFirstSearchIterator.new(self, xml_visitor).iterate
|
43
|
+
xml_visitor.document
|
44
|
+
end
|
45
|
+
|
46
|
+
def process_block(block)
|
47
|
+
return_value = block.call(@widget)
|
48
|
+
if return_value.is_a?(String) and !@children.include?(return_value)
|
49
|
+
text = return_value
|
50
|
+
first_match = text.match(/[#][^{]+[{][^}]+[}]/)
|
51
|
+
match = first_match
|
52
|
+
while (match)
|
53
|
+
Glimmer.module_eval(text_command(match.pre_match))
|
54
|
+
tag_text = match.to_s
|
55
|
+
Glimmer.module_eval(rubyize(tag_text))
|
56
|
+
text = tag_text
|
57
|
+
post_match = match.post_match
|
58
|
+
match = text.match(/[#]\w+[{]\w+[}]/)
|
59
|
+
end
|
60
|
+
Glimmer.module_eval(text_command(post_match)) if post_match
|
61
|
+
@children << return_value unless first_match
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def text_command(text)
|
66
|
+
"text \"#{text}\""
|
67
|
+
end
|
68
|
+
|
69
|
+
def rubyize(text)
|
70
|
+
text = text.gsub(/[}]/, '"}')
|
71
|
+
text = text.gsub(/[{]/, '{"')
|
72
|
+
text = text.gsub(/[#]/, '')
|
73
|
+
end
|
74
|
+
|
75
|
+
#override Object default id method and route it to Glimmer engine
|
76
|
+
def id
|
77
|
+
method_missing(:id)
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
@@ -1,12 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def process_after_children
|
10
|
-
raise "must be implemented by a class"
|
11
|
-
end
|
1
|
+
class NodeVisitor
|
2
|
+
def process_before_children
|
3
|
+
raise "must be implemented by a class"
|
4
|
+
end
|
5
|
+
|
6
|
+
def process_after_children
|
7
|
+
raise "must be implemented by a class"
|
8
|
+
end
|
12
9
|
end
|
@@ -1,62 +1,59 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
@document << "
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
1
|
+
require File.dirname(__FILE__) + "/node_visitor"
|
2
|
+
|
3
|
+
class XmlVisitor < NodeVisitor
|
4
|
+
|
5
|
+
attr_reader :document
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@document = ""
|
9
|
+
end
|
10
|
+
|
11
|
+
def process_before_children(node)
|
12
|
+
if (node.is_a?(String))
|
13
|
+
@document << node
|
14
|
+
return
|
15
|
+
end
|
16
|
+
begin_open_tag(node)
|
17
|
+
append_attributes(node) if node.attributes
|
18
|
+
end_open_tag(node)
|
19
|
+
end
|
20
|
+
|
21
|
+
def process_after_children(node)
|
22
|
+
return if (node.is_a?(String))
|
23
|
+
append_close_tag(node)
|
24
|
+
end
|
25
|
+
|
26
|
+
def begin_open_tag(node)
|
27
|
+
@document << "<"
|
28
|
+
@document << "#{node.name_space.name}:" if node.name_space
|
29
|
+
@document << node.name
|
30
|
+
end
|
31
|
+
|
32
|
+
def end_open_tag(node)
|
33
|
+
if (node.contents)
|
34
|
+
@document << ">"
|
35
|
+
else
|
36
|
+
@document << " " if node.attributes.keys.size > 0
|
37
|
+
@document << "/>"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def append_close_tag(node)
|
42
|
+
if (node.contents)
|
43
|
+
@document << "</"
|
44
|
+
@document << "#{node.name_space.name}:" if node.name_space
|
45
|
+
@document << "#{node.name}>"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def append_attributes(node)
|
50
|
+
puts "Take 3"
|
51
|
+
p node.attributes
|
52
|
+
node.attributes.each_key do |attribute|
|
53
|
+
attribute_name = attribute
|
54
|
+
attribute_name = "#{attribute.name_space.name}:#{attribute.name}" if attribute.is_a?(Node)
|
55
|
+
@document << " #{attribute_name}=\"#{node.attributes[attribute]}\""
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
62
59
|
end
|