celerity 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/History.txt +14 -0
- data/Manifest.txt +127 -151
- data/README.txt +15 -20
- data/lib/celerity.rb +13 -5
- data/lib/celerity/browser.rb +296 -0
- data/lib/celerity/clickable_element.rb +1 -0
- data/lib/celerity/collections.rb +4 -0
- data/lib/celerity/container.rb +69 -2
- data/lib/celerity/disabled_element.rb +1 -0
- data/lib/celerity/element.rb +103 -38
- data/lib/celerity/element_collections.rb +14 -8
- data/lib/celerity/element_locator.rb +61 -50
- data/lib/celerity/element_map.rb +51 -0
- data/lib/celerity/elements/button.rb +1 -0
- data/lib/celerity/elements/file_field.rb +3 -2
- data/lib/celerity/elements/form.rb +1 -0
- data/lib/celerity/elements/frame.rb +16 -1
- data/lib/celerity/elements/image.rb +15 -13
- data/lib/celerity/elements/link.rb +4 -1
- data/lib/celerity/elements/option.rb +1 -0
- data/lib/celerity/elements/radio_check.rb +19 -7
- data/lib/celerity/elements/select_list.rb +17 -2
- data/lib/celerity/elements/table.rb +34 -20
- data/lib/celerity/elements/table_body.rb +2 -2
- data/lib/celerity/elements/table_cell.rb +3 -1
- data/lib/celerity/elements/table_footer.rb +2 -2
- data/lib/celerity/elements/table_header.rb +2 -2
- data/lib/celerity/elements/table_row.rb +4 -2
- data/lib/celerity/elements/text_field.rb +20 -9
- data/lib/celerity/exception.rb +11 -18
- data/lib/celerity/extra/method_generator.rb +13 -8
- data/lib/celerity/htmlunit/download.sh +23 -0
- data/lib/celerity/htmlunit/htmlunit-2.2.jar +0 -0
- data/lib/celerity/htmlunit/htmlunit-core-js-2.2.jar +0 -0
- data/lib/celerity/htmlunit/{nekohtml-1.9.7.jar → nekohtml-1.9.8.jar} +0 -0
- data/lib/celerity/input_element.rb +1 -1
- data/lib/celerity/version.rb +1 -1
- data/lib/celerity/watir_compatibility.rb +37 -23
- data/spec/area_spec.rb +19 -4
- data/spec/areas_spec.rb +2 -3
- data/spec/{ie_spec.rb → browser_spec.rb} +66 -15
- data/spec/button_spec.rb +36 -3
- data/spec/buttons_spec.rb +2 -3
- data/spec/checkbox_spec.rb +43 -8
- data/spec/checkboxes_spec.rb +2 -3
- data/spec/div_spec.rb +31 -4
- data/spec/divs_spec.rb +2 -3
- data/spec/element_spec.rb +36 -6
- data/spec/filefield_spec.rb +28 -13
- data/spec/filefields_spec.rb +2 -3
- data/spec/form_spec.rb +6 -3
- data/spec/forms_spec.rb +2 -3
- data/spec/frame_spec.rb +14 -5
- data/spec/frames_spec.rb +71 -0
- data/spec/hidden_spec.rb +21 -3
- data/spec/hiddens_spec.rb +2 -3
- data/spec/hn_spec.rb +30 -12
- data/spec/hns_spec.rb +14 -10
- data/spec/html/form_js_bug.html +11 -0
- data/spec/html/forms_with_input_elements.html +2 -1
- data/spec/html/invalid_js.html +11 -0
- data/spec/html/latin1_text.html +1 -0
- data/spec/html/non_control_elements.html +8 -4
- data/spec/html/simple_ajax.html +22 -0
- data/spec/htmlunit_spec.rb +4 -5
- data/spec/image_spec.rb +33 -3
- data/spec/images_spec.rb +2 -3
- data/spec/label_spec.rb +16 -3
- data/spec/labels_spec.rb +2 -3
- data/spec/li_spec.rb +25 -3
- data/spec/link_spec.rb +35 -3
- data/spec/links_spec.rb +2 -3
- data/spec/lis_spec.rb +2 -3
- data/spec/map_spec.rb +19 -3
- data/spec/maps_spec.rb +2 -3
- data/spec/meta_spec.rb +3 -1
- data/spec/ol_spec.rb +17 -3
- data/spec/ols_spec.rb +2 -3
- data/spec/option_spec.rb +28 -3
- data/spec/p_spec.rb +30 -2
- data/spec/pre_spec.rb +25 -3
- data/spec/pres_spec.rb +2 -3
- data/spec/ps_spec.rb +2 -3
- data/spec/radio_spec.rb +47 -3
- data/spec/radios_spec.rb +2 -3
- data/spec/select_list_spec.rb +42 -3
- data/spec/select_lists_spec.rb +2 -3
- data/spec/span_spec.rb +32 -7
- data/spec/spans_spec.rb +2 -4
- data/spec/spec_helper.rb +5 -25
- data/spec/table_bodies_spec.rb +7 -5
- data/spec/table_body_spec.rb +11 -4
- data/spec/table_cell_spec.rb +15 -4
- data/spec/table_cells_spec.rb +3 -4
- data/spec/table_footer_spec.rb +11 -4
- data/spec/table_footers_spec.rb +7 -5
- data/spec/table_header_spec.rb +11 -4
- data/spec/table_headers_spec.rb +7 -5
- data/spec/table_row_spec.rb +31 -7
- data/spec/table_rows_spec.rb +5 -4
- data/spec/table_spec.rb +36 -7
- data/spec/tables_spec.rb +2 -3
- data/spec/text_field_spec.rb +51 -13
- data/spec/text_fields_spec.rb +2 -3
- data/spec/ul_spec.rb +18 -3
- data/spec/uls_spec.rb +2 -3
- data/spec/{watir_compatability_spec.rb → watir_compatibility_spec.rb} +42 -35
- data/support/spec_server.rb +9 -0
- metadata +167 -161
- metadata.gz.sig +0 -0
- data/benchmark/bm_2000_spans.rb +0 -48
- data/benchmark/bm_digg.rb +0 -26
- data/benchmark/bm_google_images.rb +0 -36
- data/benchmark/bm_input_locator.rb +0 -69
- data/benchmark/loader.rb +0 -9
- data/config/hoe.rb +0 -68
- data/config/requirements.rb +0 -15
- data/lib/celerity/htmlunit/htmlunit-2.2-SNAPSHOT.jar +0 -0
- data/lib/celerity/htmlunit/js-1.7R1.jar +0 -0
- data/lib/celerity/ie.rb +0 -195
- data/setup.rb +0 -1583
- data/support/celerity_viewer/rubycocoa/CelerityViewer.icns +0 -0
- data/support/celerity_viewer/rubycocoa/English.lproj/Main.nib/classes.nib +0 -37
- data/support/celerity_viewer/rubycocoa/English.lproj/Main.nib/info.nib +0 -19
- data/support/celerity_viewer/rubycocoa/English.lproj/Main.nib/keyedobjects.nib +0 -0
- data/support/celerity_viewer/rubycocoa/Info.plist.erb +0 -28
- data/support/celerity_viewer/rubycocoa/MainController.rb +0 -23
- data/support/celerity_viewer/rubycocoa/README +0 -94
- data/support/celerity_viewer/rubycocoa/Rakefile +0 -100
- data/support/celerity_viewer/rubycocoa/distributed_viewer.rb +0 -86
- data/support/celerity_viewer/rubycocoa/main.m +0 -7
- data/support/celerity_viewer/rubycocoa/main.rb +0 -27
- data/tasks/benchmark.rake +0 -4
- data/tasks/environment.rake +0 -7
- data/tasks/simple_ci.rake +0 -94
data/lib/celerity/collections.rb
CHANGED
data/lib/celerity/container.rb
CHANGED
@@ -1,15 +1,42 @@
|
|
1
1
|
module Celerity
|
2
|
+
|
3
|
+
# This class contains methods for accessing elements inside a container.
|
4
|
+
# (usually the Browser object, meaning the current page).
|
5
|
+
#
|
6
|
+
# The most common syntax is
|
7
|
+
# browser.elem(:attribute, 'value')
|
8
|
+
#
|
9
|
+
# Note that the element is located lazily, so no exceptions will be thrown
|
10
|
+
# if the element doesn't exist until you call a method on the resulting object.
|
11
|
+
# To do this you would normally use +Element#exists?+ or an action method,
|
12
|
+
# like +ClickableElement#click+.
|
13
|
+
#
|
14
|
+
# You can also pass in a hash:
|
15
|
+
#
|
16
|
+
# browser.link(:index => 1).click
|
17
|
+
#
|
18
|
+
# All elements support multiple attributes identification using the
|
19
|
+
# hash syntax (though might not always be compatible with Watir):
|
20
|
+
#
|
21
|
+
# browser.span(:class_name => 'product', :index => 5).text
|
22
|
+
#
|
23
|
+
# You can also get all the elements of a certain type by using the plural form:
|
24
|
+
#
|
25
|
+
# browser.links => #<Celerity::Links:0x7a1c2da2 ...>
|
26
|
+
#
|
27
|
+
# See +Celerity::ElementCollections+ for details.
|
2
28
|
module Container
|
3
29
|
include Celerity::Exception
|
4
30
|
attr_accessor :page_container
|
5
31
|
|
6
|
-
def
|
32
|
+
def container=(container)
|
7
33
|
@container = container
|
8
34
|
@page_container = container.page_container
|
35
|
+
container
|
9
36
|
end
|
10
37
|
|
11
38
|
def update_page(page)
|
12
|
-
@page_container.
|
39
|
+
@page_container.page = page
|
13
40
|
end
|
14
41
|
|
15
42
|
def frame(*args)
|
@@ -17,10 +44,16 @@ module Celerity
|
|
17
44
|
Frame.new(self, *args)
|
18
45
|
end
|
19
46
|
|
47
|
+
def frames
|
48
|
+
assert_exists
|
49
|
+
Frames.new(self)
|
50
|
+
end
|
51
|
+
|
20
52
|
def table(*args)
|
21
53
|
assert_exists
|
22
54
|
Table.new(self, *args)
|
23
55
|
end
|
56
|
+
|
24
57
|
def tables
|
25
58
|
assert_exists
|
26
59
|
Tables.new(self)
|
@@ -30,6 +63,7 @@ module Celerity
|
|
30
63
|
assert_exists
|
31
64
|
TableHeader.new(self, *args)
|
32
65
|
end
|
66
|
+
|
33
67
|
def theads
|
34
68
|
assert_exists
|
35
69
|
TableHeaders.new(self)
|
@@ -39,6 +73,7 @@ module Celerity
|
|
39
73
|
assert_exists
|
40
74
|
TableBody.new(self, *args)
|
41
75
|
end
|
76
|
+
|
42
77
|
def tbodies
|
43
78
|
assert_exists
|
44
79
|
TableBodies.new(self)
|
@@ -48,6 +83,7 @@ module Celerity
|
|
48
83
|
assert_exists
|
49
84
|
TableFooter.new(self, *args)
|
50
85
|
end
|
86
|
+
|
51
87
|
def tfoots
|
52
88
|
assert_exists
|
53
89
|
TableFooters.new(self)
|
@@ -58,6 +94,7 @@ module Celerity
|
|
58
94
|
assert_exists
|
59
95
|
TableCell.new(self, *args)
|
60
96
|
end
|
97
|
+
|
61
98
|
def cells
|
62
99
|
assert_exists
|
63
100
|
TableCells.new(self)
|
@@ -67,6 +104,7 @@ module Celerity
|
|
67
104
|
assert_exists
|
68
105
|
TableRow.new(self, *args)
|
69
106
|
end
|
107
|
+
|
70
108
|
def rows
|
71
109
|
assert_exists
|
72
110
|
TableRows.new(self)
|
@@ -76,6 +114,7 @@ module Celerity
|
|
76
114
|
assert_exists
|
77
115
|
Button.new(self, *args)
|
78
116
|
end
|
117
|
+
|
79
118
|
def buttons
|
80
119
|
assert_exists
|
81
120
|
Buttons.new(self)
|
@@ -85,6 +124,7 @@ module Celerity
|
|
85
124
|
assert_exists
|
86
125
|
FileField.new(self, *args)
|
87
126
|
end
|
127
|
+
|
88
128
|
def file_fields
|
89
129
|
assert_exists
|
90
130
|
FileFields.new(self)
|
@@ -94,6 +134,7 @@ module Celerity
|
|
94
134
|
assert_exists
|
95
135
|
TextField.new(self, *args)
|
96
136
|
end
|
137
|
+
|
97
138
|
def text_fields
|
98
139
|
assert_exists
|
99
140
|
TextFields.new(self)
|
@@ -103,6 +144,7 @@ module Celerity
|
|
103
144
|
assert_exists
|
104
145
|
Hidden.new(self, *args)
|
105
146
|
end
|
147
|
+
|
106
148
|
def hiddens
|
107
149
|
assert_exists
|
108
150
|
Hiddens.new(self)
|
@@ -112,6 +154,7 @@ module Celerity
|
|
112
154
|
assert_exists
|
113
155
|
SelectList.new(self, *args)
|
114
156
|
end
|
157
|
+
|
115
158
|
def select_lists
|
116
159
|
assert_exists
|
117
160
|
SelectLists.new(self)
|
@@ -136,6 +179,7 @@ module Celerity
|
|
136
179
|
assert_exists
|
137
180
|
Radio.new(self, *args)
|
138
181
|
end
|
182
|
+
|
139
183
|
def radios
|
140
184
|
assert_exists
|
141
185
|
Radios.new(self)
|
@@ -155,6 +199,7 @@ module Celerity
|
|
155
199
|
assert_exists
|
156
200
|
Ul.new(self, *args)
|
157
201
|
end
|
202
|
+
|
158
203
|
def uls
|
159
204
|
assert_exists
|
160
205
|
Uls.new(self)
|
@@ -164,6 +209,7 @@ module Celerity
|
|
164
209
|
assert_exists
|
165
210
|
Ol.new(self, *args)
|
166
211
|
end
|
212
|
+
|
167
213
|
def ols
|
168
214
|
assert_exists
|
169
215
|
Ols.new(self)
|
@@ -173,6 +219,7 @@ module Celerity
|
|
173
219
|
assert_exists
|
174
220
|
Li.new(self, *args)
|
175
221
|
end
|
222
|
+
|
176
223
|
def lis
|
177
224
|
assert_exists
|
178
225
|
Lis.new(self)
|
@@ -182,6 +229,7 @@ module Celerity
|
|
182
229
|
assert_exists
|
183
230
|
Map.new(self, *args)
|
184
231
|
end
|
232
|
+
|
185
233
|
def maps
|
186
234
|
assert_exists
|
187
235
|
Maps.new(self)
|
@@ -191,6 +239,7 @@ module Celerity
|
|
191
239
|
assert_exists
|
192
240
|
Area.new(self, *args)
|
193
241
|
end
|
242
|
+
|
194
243
|
def areas
|
195
244
|
assert_exists
|
196
245
|
Areas.new(self)
|
@@ -200,6 +249,7 @@ module Celerity
|
|
200
249
|
assert_exists
|
201
250
|
Image.new(self, *args)
|
202
251
|
end
|
252
|
+
|
203
253
|
def images
|
204
254
|
assert_exists
|
205
255
|
Images.new(self)
|
@@ -209,6 +259,7 @@ module Celerity
|
|
209
259
|
assert_exists
|
210
260
|
Div.new(self, *args)
|
211
261
|
end
|
262
|
+
|
212
263
|
def divs
|
213
264
|
assert_exists
|
214
265
|
Divs.new(self)
|
@@ -218,6 +269,7 @@ module Celerity
|
|
218
269
|
assert_exists
|
219
270
|
Form.new(self, *args)
|
220
271
|
end
|
272
|
+
|
221
273
|
def forms
|
222
274
|
assert_exists
|
223
275
|
Forms.new(self)
|
@@ -227,6 +279,7 @@ module Celerity
|
|
227
279
|
assert_exists
|
228
280
|
Span.new(self, *args)
|
229
281
|
end
|
282
|
+
|
230
283
|
def spans
|
231
284
|
assert_exists
|
232
285
|
Spans.new(self)
|
@@ -236,6 +289,7 @@ module Celerity
|
|
236
289
|
assert_exists
|
237
290
|
P.new(self, *args)
|
238
291
|
end
|
292
|
+
|
239
293
|
def ps
|
240
294
|
assert_exists
|
241
295
|
Ps.new(self)
|
@@ -245,6 +299,7 @@ module Celerity
|
|
245
299
|
assert_exists
|
246
300
|
Pre.new(self, *args)
|
247
301
|
end
|
302
|
+
|
248
303
|
def pres
|
249
304
|
assert_exists
|
250
305
|
Pres.new(self)
|
@@ -254,6 +309,7 @@ module Celerity
|
|
254
309
|
assert_exists
|
255
310
|
Label.new(self, *args)
|
256
311
|
end
|
312
|
+
|
257
313
|
def labels
|
258
314
|
assert_exists
|
259
315
|
Labels.new(self)
|
@@ -263,46 +319,57 @@ module Celerity
|
|
263
319
|
assert_exists
|
264
320
|
H1.new(self, *args)
|
265
321
|
end
|
322
|
+
|
266
323
|
def h2(*args)
|
267
324
|
assert_exists
|
268
325
|
H2.new(self, *args)
|
269
326
|
end
|
327
|
+
|
270
328
|
def h3(*args)
|
271
329
|
assert_exists
|
272
330
|
H3.new(self, *args)
|
273
331
|
end
|
332
|
+
|
274
333
|
def h4(*args)
|
275
334
|
assert_exists
|
276
335
|
H4.new(self, *args)
|
277
336
|
end
|
337
|
+
|
278
338
|
def h5(*args)
|
279
339
|
assert_exists
|
280
340
|
H5.new(self, *args)
|
281
341
|
end
|
342
|
+
|
282
343
|
def h6(*args)
|
283
344
|
assert_exists
|
284
345
|
H6.new(self, *args)
|
285
346
|
end
|
347
|
+
|
286
348
|
def h1s
|
287
349
|
assert_exists
|
288
350
|
H1s.new(self)
|
289
351
|
end
|
352
|
+
|
290
353
|
def h2s
|
291
354
|
assert_exists
|
292
355
|
H2s.new(self)
|
293
356
|
end
|
357
|
+
|
294
358
|
def h3s
|
295
359
|
assert_exists
|
296
360
|
H3s.new(self)
|
297
361
|
end
|
362
|
+
|
298
363
|
def h4s
|
299
364
|
assert_exists
|
300
365
|
H4s.new(self)
|
301
366
|
end
|
367
|
+
|
302
368
|
def h5s
|
303
369
|
assert_exists
|
304
370
|
H5s.new(self)
|
305
371
|
end
|
372
|
+
|
306
373
|
def h6s
|
307
374
|
assert_exists
|
308
375
|
H6s.new(self)
|
data/lib/celerity/element.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
module Celerity
|
2
|
+
|
3
|
+
# Superclass for all HTML elements.
|
2
4
|
class Element
|
3
5
|
include Exception
|
4
6
|
include Container
|
5
|
-
|
7
|
+
|
8
|
+
attr_reader :container, :object
|
6
9
|
|
7
10
|
# number of spaces that separate the property from the value in the create_string method
|
8
11
|
TO_S_SIZE = 14
|
@@ -13,7 +16,8 @@ module Celerity
|
|
13
16
|
:cell_halign => [:align, :char, :charoff],
|
14
17
|
:cell_valign => [:valign],
|
15
18
|
:i18n => [:dir, :lang],
|
16
|
-
:event => [:onclick, :ondblclick, :onmousedown, :onmouseup, :onmouseover,
|
19
|
+
:event => [:onclick, :ondblclick, :onmousedown, :onmouseup, :onmouseover,
|
20
|
+
:onmousemove, :onmouseout, :onkeypress, :onkeydown, :onkeyup],
|
17
21
|
:sloppy => [:name, :value]
|
18
22
|
}
|
19
23
|
|
@@ -21,15 +25,18 @@ module Celerity
|
|
21
25
|
CELLVALIGN_ATTRIBUTES = HTML_401_TRANSITIONAL[:cell_valign]
|
22
26
|
BASE_ATTRIBUTES = HTML_401_TRANSITIONAL.values_at(:core, :i18n, :event, :sloppy).flatten
|
23
27
|
ATTRIBUTES = BASE_ATTRIBUTES
|
28
|
+
|
29
|
+
DEFAULT_HOW = nil
|
24
30
|
|
31
|
+
# @api internal
|
25
32
|
def initialize(container, *args)
|
26
|
-
|
33
|
+
self.container = container
|
27
34
|
|
28
35
|
case args.size
|
29
36
|
when 2
|
30
37
|
@conditions = { args[0] => args[1] }
|
31
38
|
when 1
|
32
|
-
if
|
39
|
+
if args.first.is_a? Hash
|
33
40
|
@conditions = args.first
|
34
41
|
elsif self.class::DEFAULT_HOW
|
35
42
|
@conditions = { self.class::DEFAULT_HOW => args.first }
|
@@ -41,20 +48,49 @@ module Celerity
|
|
41
48
|
end
|
42
49
|
end
|
43
50
|
|
51
|
+
# Get the parent element (experimental, avoid if possible)
|
52
|
+
# @return [Celerity::Element] subclass
|
53
|
+
def parent
|
54
|
+
assert_exists
|
55
|
+
|
56
|
+
obj = @object.getParentNode
|
57
|
+
until element_class = HtmlUnit2CelerityElement[obj.class]
|
58
|
+
return nil if obj.nil?
|
59
|
+
obj = obj.parentNode
|
60
|
+
end
|
61
|
+
|
62
|
+
element_class.new(@container, :object, obj)
|
63
|
+
end
|
64
|
+
|
65
|
+
# Sets the focus to this element.
|
66
|
+
def focus
|
67
|
+
assert_exists
|
68
|
+
@object.focus
|
69
|
+
end
|
70
|
+
|
71
|
+
# Locates the element
|
72
|
+
# @api internal
|
44
73
|
def locate
|
45
74
|
@object = ElementLocator.new(@container.object, self.class).find_by_conditions(@conditions)
|
46
75
|
end
|
47
76
|
|
77
|
+
# @return [String] A string representation of the element.
|
48
78
|
def to_s
|
49
79
|
assert_exists
|
50
80
|
create_string(@object)
|
51
81
|
end
|
52
82
|
|
83
|
+
# @param [String, #to_s] The attribute.
|
84
|
+
# @return [String] The value of the given attribute.
|
53
85
|
def attribute_value(attribute)
|
54
86
|
assert_exists
|
55
|
-
@object.getAttribute(attribute)
|
87
|
+
@object.getAttribute(attribute.to_s)
|
56
88
|
end
|
57
89
|
|
90
|
+
# Locates the element.
|
91
|
+
#
|
92
|
+
# @raise UnknownObjectException
|
93
|
+
# @api internal
|
58
94
|
def assert_exists
|
59
95
|
locate
|
60
96
|
unless @object
|
@@ -62,29 +98,40 @@ module Celerity
|
|
62
98
|
end
|
63
99
|
end
|
64
100
|
|
101
|
+
# Checks if the element exists.
|
102
|
+
# @return [true, false]
|
65
103
|
def exists?
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
false
|
71
|
-
end
|
104
|
+
assert_exists
|
105
|
+
true
|
106
|
+
rescue UnknownObjectException, UnknownFrameException
|
107
|
+
false
|
72
108
|
end
|
73
109
|
alias_method :exist?, :exists?
|
74
110
|
alias_method :exists, :exists?
|
75
111
|
|
112
|
+
# Return a text representation of the element.
|
113
|
+
# @return [String]
|
76
114
|
def text
|
77
115
|
assert_exists
|
116
|
+
|
117
|
+
# this could work, but breaks some tests atm
|
118
|
+
# @object.getTextContent.strip
|
119
|
+
|
78
120
|
@object.asText.strip
|
79
121
|
end
|
80
122
|
alias_method :innerText, :text
|
81
123
|
alias_method :inner_text, :text
|
82
124
|
|
125
|
+
# Check if the element contains the given text.
|
126
|
+
#
|
127
|
+
# @param [String, Regexp] expected_text The text to look for.
|
128
|
+
# @return [Fixnum, nil] The index of the matched text, or nil if it doesn't match.
|
83
129
|
def contains_text(expected_text)
|
84
130
|
assert_exists
|
131
|
+
|
85
132
|
case expected_text
|
86
133
|
when Regexp
|
87
|
-
text()
|
134
|
+
text() =~ expected_text
|
88
135
|
when String
|
89
136
|
text().index(expected_text)
|
90
137
|
else
|
@@ -92,25 +139,36 @@ module Celerity
|
|
92
139
|
end
|
93
140
|
end
|
94
141
|
|
142
|
+
# @return [String] The normative XML representation of the element (including children).
|
95
143
|
def to_xml
|
96
144
|
assert_exists
|
97
145
|
@object.asXml
|
98
146
|
end
|
99
|
-
alias_method :asXml,
|
147
|
+
alias_method :asXml, :to_xml
|
100
148
|
alias_method :as_xml, :to_xml
|
101
|
-
alias_method :html,
|
149
|
+
alias_method :html, :to_xml
|
102
150
|
|
103
|
-
#
|
104
|
-
def
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
151
|
+
# @return [String] A string representation of the element's attributes.
|
152
|
+
def attribute_string
|
153
|
+
assert_exists
|
154
|
+
|
155
|
+
result = ''
|
156
|
+
iterator = @object.getAttributeEntriesIterator
|
157
|
+
|
158
|
+
while iterator.hasNext
|
159
|
+
attribute = iterator.next
|
160
|
+
result << "#{attribute.getName}=\"#{attribute.getHtmlValue.to_s}\" "
|
112
161
|
end
|
162
|
+
|
163
|
+
result
|
164
|
+
end
|
113
165
|
|
166
|
+
# Dynamically get element attributes.
|
167
|
+
# @return [String] The resulting attribute.
|
168
|
+
# @raise NoMethodError If the element doesn't have this attribute.
|
169
|
+
def method_missing(meth, *args, &blk)
|
170
|
+
meth = selector_to_attribute(meth)
|
171
|
+
|
114
172
|
if self.class::ATTRIBUTES.include?(meth)
|
115
173
|
assert_exists
|
116
174
|
@object.getAttributeValue(meth.to_s)
|
@@ -119,30 +177,28 @@ module Celerity
|
|
119
177
|
super
|
120
178
|
end
|
121
179
|
end
|
122
|
-
|
123
|
-
def
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
while iterator.hasNext
|
128
|
-
attribute = iterator.next
|
129
|
-
n += "#{attribute.getName}=\"#{attribute.getHtmlValue.to_s}\" "
|
130
|
-
end
|
131
|
-
return n
|
180
|
+
|
181
|
+
def respond_to?(meth, include_private = false)
|
182
|
+
meth = selector_to_attribute(meth)
|
183
|
+
return true if self.class::ATTRIBUTES.include?(meth)
|
184
|
+
super
|
132
185
|
end
|
133
186
|
|
134
187
|
private
|
135
188
|
|
136
189
|
def create_string(element)
|
137
|
-
|
138
|
-
|
190
|
+
ret = []
|
191
|
+
ret << "tag:".ljust(TO_S_SIZE) + element.getTagName unless element.getTagName.empty?
|
192
|
+
|
139
193
|
iterator = element.getAttributeEntriesIterator
|
140
194
|
while iterator.hasNext
|
141
195
|
attribute = iterator.next
|
142
|
-
|
196
|
+
ret << " #{attribute.getName}:".ljust(TO_S_SIZE+2) + attribute.getHtmlValue.to_s
|
143
197
|
end
|
144
|
-
|
145
|
-
|
198
|
+
|
199
|
+
ret << " text:".ljust(TO_S_SIZE+2) + element.asText unless element.asText.empty?
|
200
|
+
|
201
|
+
ret.join("\n")
|
146
202
|
end
|
147
203
|
|
148
204
|
def identifier_string
|
@@ -154,5 +210,14 @@ module Celerity
|
|
154
210
|
end
|
155
211
|
end
|
156
212
|
|
213
|
+
def selector_to_attribute(meth)
|
214
|
+
case meth
|
215
|
+
when :class_name then :class
|
216
|
+
when :caption then :value
|
217
|
+
when :url then :href
|
218
|
+
else meth
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
157
222
|
end # Element
|
158
223
|
end # Celerity
|