glimmer 0.8.2 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +116 -95
- data/VERSION +1 -1
- data/lib/glimmer.rb +0 -20
- data/lib/glimmer/config.rb +0 -13
- data/lib/glimmer/dsl/engine.rb +25 -18
- data/lib/glimmer/dsl/expression.rb +0 -7
- data/lib/glimmer/dsl/static_expression.rb +2 -2
- metadata +47 -177
- data/RUBY_VERSION +0 -1
- data/bin/girb +0 -10
- data/bin/girb_runner.rb +0 -13
- data/bin/glimmer +0 -5
- data/icons/scaffold_app.icns +0 -0
- data/lib/glimmer/css/rule.rb +0 -25
- data/lib/glimmer/css/style_sheet.rb +0 -19
- data/lib/glimmer/data_binding/list_selection_binding.rb +0 -52
- data/lib/glimmer/data_binding/model_binding.rb +0 -248
- data/lib/glimmer/data_binding/observable.rb +0 -21
- data/lib/glimmer/data_binding/observable_array.rb +0 -107
- data/lib/glimmer/data_binding/observable_model.rb +0 -108
- data/lib/glimmer/data_binding/observable_widget.rb +0 -17
- data/lib/glimmer/data_binding/observer.rb +0 -124
- data/lib/glimmer/data_binding/shine.rb +0 -23
- data/lib/glimmer/data_binding/table_items_binding.rb +0 -56
- data/lib/glimmer/data_binding/tree_items_binding.rb +0 -71
- data/lib/glimmer/data_binding/widget_binding.rb +0 -33
- data/lib/glimmer/dsl/css/css_expression.rb +0 -21
- data/lib/glimmer/dsl/css/dsl.rb +0 -10
- data/lib/glimmer/dsl/css/dynamic_property_expression.rb +0 -12
- data/lib/glimmer/dsl/css/property_expression.rb +0 -22
- data/lib/glimmer/dsl/css/pv_expression.rb +0 -17
- data/lib/glimmer/dsl/css/rule_expression.rb +0 -25
- data/lib/glimmer/dsl/css/s_expression.rb +0 -26
- data/lib/glimmer/dsl/swt/async_exec_expression.rb +0 -14
- data/lib/glimmer/dsl/swt/bind_expression.rb +0 -37
- data/lib/glimmer/dsl/swt/color_expression.rb +0 -19
- data/lib/glimmer/dsl/swt/column_properties_expression.rb +0 -24
- data/lib/glimmer/dsl/swt/combo_selection_data_binding_expression.rb +0 -42
- data/lib/glimmer/dsl/swt/custom_widget_expression.rb +0 -36
- data/lib/glimmer/dsl/swt/data_binding_expression.rb +0 -34
- data/lib/glimmer/dsl/swt/dialog_expression.rb +0 -26
- data/lib/glimmer/dsl/swt/display_expression.rb +0 -19
- data/lib/glimmer/dsl/swt/dsl.rb +0 -28
- data/lib/glimmer/dsl/swt/exec_expression.rb +0 -28
- data/lib/glimmer/dsl/swt/layout_data_expression.rb +0 -25
- data/lib/glimmer/dsl/swt/layout_expression.rb +0 -27
- data/lib/glimmer/dsl/swt/list_selection_data_binding_expression.rb +0 -44
- data/lib/glimmer/dsl/swt/menu_bar_expression.rb +0 -33
- data/lib/glimmer/dsl/swt/menu_expression.rb +0 -32
- data/lib/glimmer/dsl/swt/message_box_expression.rb +0 -29
- data/lib/glimmer/dsl/swt/observe_expression.rb +0 -32
- data/lib/glimmer/dsl/swt/property_expression.rb +0 -22
- data/lib/glimmer/dsl/swt/rgb_expression.rb +0 -12
- data/lib/glimmer/dsl/swt/rgba_expression.rb +0 -12
- data/lib/glimmer/dsl/swt/shell_expression.rb +0 -25
- data/lib/glimmer/dsl/swt/swt_expression.rb +0 -25
- data/lib/glimmer/dsl/swt/sync_exec_expression.rb +0 -15
- data/lib/glimmer/dsl/swt/tab_item_expression.rb +0 -33
- data/lib/glimmer/dsl/swt/table_items_data_binding_expression.rb +0 -31
- data/lib/glimmer/dsl/swt/tree_items_data_binding_expression.rb +0 -31
- data/lib/glimmer/dsl/swt/tree_properties_expression.rb +0 -26
- data/lib/glimmer/dsl/swt/widget_expression.rb +0 -35
- data/lib/glimmer/dsl/swt/widget_listener_expression.rb +0 -32
- data/lib/glimmer/dsl/xml/dsl.rb +0 -11
- data/lib/glimmer/dsl/xml/html_expression.rb +0 -25
- data/lib/glimmer/dsl/xml/meta_expression.rb +0 -23
- data/lib/glimmer/dsl/xml/name_space_expression.rb +0 -37
- data/lib/glimmer/dsl/xml/node_parent_expression.rb +0 -33
- data/lib/glimmer/dsl/xml/tag_expression.rb +0 -29
- data/lib/glimmer/dsl/xml/text_expression.rb +0 -22
- data/lib/glimmer/dsl/xml/xml_expression.rb +0 -21
- data/lib/glimmer/launcher.rb +0 -199
- data/lib/glimmer/package.rb +0 -55
- data/lib/glimmer/rake_task.rb +0 -58
- data/lib/glimmer/scaffold.rb +0 -582
- data/lib/glimmer/swt/color_proxy.rb +0 -53
- data/lib/glimmer/swt/display_proxy.rb +0 -88
- data/lib/glimmer/swt/font_proxy.rb +0 -72
- data/lib/glimmer/swt/layout_data_proxy.rb +0 -84
- data/lib/glimmer/swt/layout_proxy.rb +0 -82
- data/lib/glimmer/swt/menu_proxy.rb +0 -101
- data/lib/glimmer/swt/message_box_proxy.rb +0 -48
- data/lib/glimmer/swt/packages.rb +0 -13
- data/lib/glimmer/swt/shell_proxy.rb +0 -152
- data/lib/glimmer/swt/swt_proxy.rb +0 -106
- data/lib/glimmer/swt/tab_item_proxy.rb +0 -65
- data/lib/glimmer/swt/table_proxy.rb +0 -150
- data/lib/glimmer/swt/tree_proxy.rb +0 -120
- data/lib/glimmer/swt/widget_listener_proxy.rb +0 -34
- data/lib/glimmer/swt/widget_proxy.rb +0 -489
- data/lib/glimmer/ui/custom_shell.rb +0 -45
- data/lib/glimmer/ui/custom_widget.rb +0 -244
- data/lib/glimmer/util/proc_tracker.rb +0 -16
- data/lib/glimmer/xml/depth_first_search_iterator.rb +0 -22
- data/lib/glimmer/xml/name_space_visitor.rb +0 -21
- data/lib/glimmer/xml/node.rb +0 -75
- data/lib/glimmer/xml/node_visitor.rb +0 -13
- data/lib/glimmer/xml/xml_visitor.rb +0 -65
- data/vendor/swt/linux/swt.jar +0 -0
- data/vendor/swt/mac/swt.jar +0 -0
- data/vendor/swt/windows/swt.jar +0 -0
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'glimmer/error'
|
2
|
-
|
3
|
-
module Glimmer
|
4
|
-
module UI
|
5
|
-
module CustomShell
|
6
|
-
include SuperModule
|
7
|
-
include Glimmer::UI::CustomWidget
|
8
|
-
|
9
|
-
def initialize(parent, *swt_constants, options, &content)
|
10
|
-
super
|
11
|
-
raise Error, 'Invalid custom shell body root! Must be a shell or another custom shell.' unless body_root.swt_widget.is_a?(org.eclipse.swt.widgets.Shell)
|
12
|
-
end
|
13
|
-
|
14
|
-
# Classes may override
|
15
|
-
def open
|
16
|
-
body_root.open
|
17
|
-
end
|
18
|
-
|
19
|
-
# DO NOT OVERRIDE. JUST AN ALIAS FOR `#open`. OVERRIDE `#open` INSTEAD.
|
20
|
-
def show
|
21
|
-
open
|
22
|
-
end
|
23
|
-
|
24
|
-
def close
|
25
|
-
body_root.close
|
26
|
-
end
|
27
|
-
|
28
|
-
def hide
|
29
|
-
body_root.hide
|
30
|
-
end
|
31
|
-
|
32
|
-
def visible?
|
33
|
-
body_root.visible?
|
34
|
-
end
|
35
|
-
|
36
|
-
def center
|
37
|
-
body_root.center
|
38
|
-
end
|
39
|
-
|
40
|
-
def start_event_loop
|
41
|
-
body_root.start_event_loop
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,244 +0,0 @@
|
|
1
|
-
require 'glimmer'
|
2
|
-
require 'glimmer/error'
|
3
|
-
require 'glimmer/swt/swt_proxy'
|
4
|
-
require 'glimmer/swt/display_proxy'
|
5
|
-
require 'glimmer/util/proc_tracker'
|
6
|
-
require 'glimmer/data_binding/observer'
|
7
|
-
require 'glimmer/data_binding/observable_model'
|
8
|
-
require 'glimmer/data_binding/observable_widget'
|
9
|
-
|
10
|
-
module Glimmer
|
11
|
-
module UI
|
12
|
-
module CustomWidget
|
13
|
-
include SuperModule
|
14
|
-
include DataBinding::ObservableModel
|
15
|
-
|
16
|
-
super_module_included do |klass|
|
17
|
-
klass.include(Glimmer) unless klass.name.include?('Glimmer::UI::CustomShell')
|
18
|
-
klass.prepend DataBinding::ObservableWidget
|
19
|
-
Glimmer::UI::CustomWidget.add_custom_widget_namespaces_for(klass) unless klass.name.include?('Glimmer::UI::CustomShell')
|
20
|
-
end
|
21
|
-
|
22
|
-
class << self
|
23
|
-
def for(underscored_custom_widget_name)
|
24
|
-
extracted_namespaces = underscored_custom_widget_name.
|
25
|
-
to_s.
|
26
|
-
split(/__/).map do |namespace|
|
27
|
-
namespace.camelcase(:upper)
|
28
|
-
end
|
29
|
-
custom_widget_namespaces.each do |base|
|
30
|
-
extracted_namespaces.reduce(base) do |result, namespace|
|
31
|
-
if !result.constants.include?(namespace)
|
32
|
-
namespace = result.constants.detect {|c| c.to_s.upcase == namespace.to_s.upcase } || namespace
|
33
|
-
end
|
34
|
-
begin
|
35
|
-
constant = result.const_get(namespace)
|
36
|
-
return constant if constant.ancestors.include?(Glimmer::UI::CustomWidget)
|
37
|
-
constant
|
38
|
-
rescue => e
|
39
|
-
# Glimmer::Config.logger&.debug "#{e.message}\n#{e.backtrace.join("\n")}"
|
40
|
-
result
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
raise "#{underscored_custom_widget_name} has no custom widget class!"
|
45
|
-
rescue => e
|
46
|
-
Glimmer::Config.logger&.debug e.message
|
47
|
-
Glimmer::Config.logger&.debug "#{e.message}\n#{e.backtrace.join("\n")}"
|
48
|
-
nil
|
49
|
-
end
|
50
|
-
|
51
|
-
def add_custom_widget_namespaces_for(klass)
|
52
|
-
Glimmer::UI::CustomWidget.namespaces_for_class(klass).drop(1).each do |namespace|
|
53
|
-
Glimmer::UI::CustomWidget.custom_widget_namespaces << namespace
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def namespaces_for_class(m)
|
58
|
-
return [m] if m.name.nil?
|
59
|
-
namespace_constants = m.name.split(/::/).map(&:to_sym)
|
60
|
-
namespace_constants.reduce([Object]) do |output, namespace_constant|
|
61
|
-
output += [output.last.const_get(namespace_constant)]
|
62
|
-
end[1..-1].uniq.reverse
|
63
|
-
end
|
64
|
-
|
65
|
-
def custom_widget_namespaces
|
66
|
-
@custom_widget_namespaces ||= reset_custom_widget_namespaces
|
67
|
-
end
|
68
|
-
|
69
|
-
def reset_custom_widget_namespaces
|
70
|
-
@custom_widget_namespaces = Set[Object, Glimmer::UI]
|
71
|
-
end
|
72
|
-
|
73
|
-
# Allows defining convenience option accessors for an array of option names
|
74
|
-
# Example: `options :color1, :color2` defines `#color1` and `#color2`
|
75
|
-
# where they return the instance values `options[:color1]` and `options[:color2]`
|
76
|
-
# respectively.
|
77
|
-
# Can be called multiple times to set more options additively.
|
78
|
-
# When passed no arguments, it returns list of all option names captured so far
|
79
|
-
def options(*new_options)
|
80
|
-
new_options = new_options.compact.map(&:to_s).map(&:to_sym)
|
81
|
-
if new_options.empty?
|
82
|
-
@options ||= {} # maps options to defaults
|
83
|
-
else
|
84
|
-
new_options = new_options.reduce({}) {|new_options_hash, new_option| new_options_hash.merge(new_option => nil)}
|
85
|
-
@options = options.merge(new_options)
|
86
|
-
def_option_attr_accessors(new_options)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def option(new_option, default: nil)
|
91
|
-
new_option = new_option.to_s.to_sym
|
92
|
-
new_options = {new_option => default}
|
93
|
-
@options = options.merge(new_options)
|
94
|
-
def_option_attr_accessors(new_options)
|
95
|
-
end
|
96
|
-
|
97
|
-
def def_option_attr_accessors(new_options)
|
98
|
-
new_options.each do |option, default|
|
99
|
-
class_eval <<-end_eval, __FILE__, __LINE__
|
100
|
-
def #{option}
|
101
|
-
options[:#{option}]
|
102
|
-
end
|
103
|
-
def #{option}=(option_value)
|
104
|
-
self.options[:#{option}] = option_value
|
105
|
-
end
|
106
|
-
end_eval
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def before_body(&block)
|
111
|
-
@before_body_blocks ||= []
|
112
|
-
@before_body_blocks << block
|
113
|
-
end
|
114
|
-
|
115
|
-
def body(&block)
|
116
|
-
@body_block = block
|
117
|
-
end
|
118
|
-
|
119
|
-
def after_body(&block)
|
120
|
-
@after_body_blocks ||= []
|
121
|
-
@after_body_blocks << block
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
attr_reader :body_root, :swt_widget, :parent, :swt_style, :options
|
126
|
-
|
127
|
-
def initialize(parent, *swt_constants, options, &content)
|
128
|
-
@parent = parent
|
129
|
-
@swt_style = SWT::SWTProxy[*swt_constants]
|
130
|
-
options ||= {}
|
131
|
-
@options = self.class.options.merge(options)
|
132
|
-
@content = Util::ProcTracker.new(content) if content
|
133
|
-
execute_hooks('before_body')
|
134
|
-
body_block = self.class.instance_variable_get("@body_block")
|
135
|
-
raise Glimmer::Error, 'Invalid custom widget for having no body! Please define body block!' if body_block.nil?
|
136
|
-
@body_root = instance_exec(&body_block)
|
137
|
-
execute_hooks('after_body')
|
138
|
-
@swt_widget = @body_root.swt_widget
|
139
|
-
end
|
140
|
-
|
141
|
-
def can_handle_observation_request?(observation_request)
|
142
|
-
result = false
|
143
|
-
if observation_request.start_with?('on_updated_')
|
144
|
-
property = observation_request.sub(/^on_updated_/, '')
|
145
|
-
result = can_add_observer?(property)
|
146
|
-
end
|
147
|
-
result || body_root&.can_handle_observation_request?(observation_request)
|
148
|
-
end
|
149
|
-
|
150
|
-
def handle_observation_request(observation_request, &block)
|
151
|
-
if observation_request.start_with?('on_updated_')
|
152
|
-
property = observation_request.sub(/^on_updated_/, '') # TODO look into eliminating duplication from above
|
153
|
-
add_observer(DataBinding::Observer.proc(&block), property) if can_add_observer?(property)
|
154
|
-
else
|
155
|
-
body_root.handle_observation_request(observation_request, &block)
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
def can_add_observer?(attribute_name)
|
160
|
-
has_instance_method?(attribute_name) || respond_to?("#{attribute_name}?") || @body_root.can_add_observer?(attribute_name)
|
161
|
-
end
|
162
|
-
|
163
|
-
def add_observer(observer, attribute_name)
|
164
|
-
if has_instance_method?(attribute_name)
|
165
|
-
super
|
166
|
-
else
|
167
|
-
@body_root.add_observer(observer, attribute_name)
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
def has_attribute?(attribute_name, *args)
|
172
|
-
respond_to?(attribute_setter(attribute_name), args) ||
|
173
|
-
@body_root.has_attribute?(attribute_name, *args)
|
174
|
-
end
|
175
|
-
|
176
|
-
def set_attribute(attribute_name, *args)
|
177
|
-
if respond_to?(attribute_setter(attribute_name), args)
|
178
|
-
send(attribute_setter(attribute_name), *args)
|
179
|
-
else
|
180
|
-
@body_root.set_attribute(attribute_name, *args)
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
# This method ensures it has an instance method not coming from Glimmer DSL
|
185
|
-
def has_instance_method?(method_name)
|
186
|
-
respond_to?(method_name) && !method(method_name)&.source_location&.first&.include?('glimmer/dsl/engine.rb')
|
187
|
-
end
|
188
|
-
|
189
|
-
def get_attribute(attribute_name)
|
190
|
-
if has_instance_method?(attribute_name)
|
191
|
-
send(attribute_name)
|
192
|
-
else
|
193
|
-
@body_root.get_attribute(attribute_name)
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
def attribute_setter(attribute_name)
|
198
|
-
"#{attribute_name}="
|
199
|
-
end
|
200
|
-
|
201
|
-
|
202
|
-
def has_style?(style)
|
203
|
-
(swt_style & SWT::SWTProxy[style]) == SWT::SWTProxy[style]
|
204
|
-
end
|
205
|
-
|
206
|
-
# TODO see if it is worth it to eliminate duplication of async_exec/sync_exec
|
207
|
-
# delegation to DisplayProxy, via a module
|
208
|
-
|
209
|
-
def async_exec(&block)
|
210
|
-
SWT::DisplayProxy.instance.async_exec(&block)
|
211
|
-
end
|
212
|
-
|
213
|
-
def sync_exec(&block)
|
214
|
-
SWT::DisplayProxy.instance.sync_exec(&block)
|
215
|
-
end
|
216
|
-
|
217
|
-
# Returns content block if used as an attribute reader (no args)
|
218
|
-
# Otherwise, if a block is passed, it adds it as content to this custom widget
|
219
|
-
def content(&block)
|
220
|
-
if block_given?
|
221
|
-
body_root.content(&block)
|
222
|
-
else
|
223
|
-
@content
|
224
|
-
end
|
225
|
-
end
|
226
|
-
|
227
|
-
def dispose
|
228
|
-
body_root.dispose
|
229
|
-
end
|
230
|
-
|
231
|
-
def method_missing(method, *args, &block)
|
232
|
-
body_root.send(method, *args, &block)
|
233
|
-
end
|
234
|
-
|
235
|
-
private
|
236
|
-
|
237
|
-
def execute_hooks(hook_name)
|
238
|
-
self.class.instance_variable_get("@#{hook_name}_blocks")&.each do |hook_block|
|
239
|
-
instance_exec(&hook_block)
|
240
|
-
end
|
241
|
-
end
|
242
|
-
end
|
243
|
-
end
|
244
|
-
end
|
@@ -1,22 +0,0 @@
|
|
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
|
@@ -1,21 +0,0 @@
|
|
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
|
data/lib/glimmer/xml/node.rb
DELETED
@@ -1,75 +0,0 @@
|
|
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::Config.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
|
@@ -1,65 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/node_visitor"
|
2
|
-
require File.dirname(__FILE__) + "/node"
|
3
|
-
|
4
|
-
module Glimmer
|
5
|
-
module XML
|
6
|
-
class XmlVisitor < NodeVisitor
|
7
|
-
|
8
|
-
attr_reader :document
|
9
|
-
|
10
|
-
def initialize
|
11
|
-
@document = ""
|
12
|
-
end
|
13
|
-
|
14
|
-
def process_before_children(node)
|
15
|
-
if (!node.is_a?(Glimmer::XML::Node))
|
16
|
-
@document << node.to_s
|
17
|
-
return
|
18
|
-
end
|
19
|
-
begin_open_tag(node)
|
20
|
-
append_attributes(node) if node.attributes
|
21
|
-
end_open_tag(node)
|
22
|
-
end
|
23
|
-
|
24
|
-
def process_after_children(node)
|
25
|
-
return if (!node.is_a?(Glimmer::XML::Node))
|
26
|
-
append_close_tag(node)
|
27
|
-
end
|
28
|
-
|
29
|
-
def begin_open_tag(node)
|
30
|
-
@document << "<"
|
31
|
-
@document << "#{node.name_space.name}:" if node.name_space
|
32
|
-
@document << node.name
|
33
|
-
end
|
34
|
-
|
35
|
-
def end_open_tag(node)
|
36
|
-
if (node.contents)
|
37
|
-
@document << ">"
|
38
|
-
else
|
39
|
-
@document << " " if node.attributes.keys.size > 0
|
40
|
-
@document << "/>"
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def append_close_tag(node)
|
45
|
-
if (node.contents)
|
46
|
-
@document << "</"
|
47
|
-
@document << "#{node.name_space.name}:" if node.name_space
|
48
|
-
@document << "#{node.name}>"
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def append_attributes(node)
|
53
|
-
Glimmer::Config.logger&.debug "Take 3"
|
54
|
-
Glimmer::Config.logger&.debug(node.attributes)
|
55
|
-
node.attributes.each do |attribute, value|
|
56
|
-
attribute_name = attribute
|
57
|
-
attribute_name = "#{attribute.name_space.name}:#{attribute.name}" if attribute.is_a?(Node)
|
58
|
-
@document << " #{attribute_name}"
|
59
|
-
@document << "=\"#{value}\"" unless value.nil?
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|