chemicals 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,14 @@
1
+ module ChemicalsSpecHelper
2
+
3
+ EXAMPLES = YAML.load(IO.read File.expand_path('../examples.yml', __FILE__))
4
+
5
+ def self.test_example name
6
+ returns = [Chemicals::Template.new(EXAMPLES[name.to_s]['template']), EXAMPLES[name.to_s]['raw']]
7
+ returns << EXAMPLES[name.to_s]['raw_render'] if EXAMPLES[name.to_s]['raw_render']
8
+ return *returns
9
+ end
10
+
11
+ def self.format xml
12
+ Nokogiri::XML(xml) { |c| c.noblanks }.root.to_xml
13
+ end
14
+ end
@@ -0,0 +1,517 @@
1
+ chinese:
2
+ template:
3
+ <message>@</message>
4
+
5
+ raw:
6
+ <message>你好世界</message>
7
+
8
+ simple_text:
9
+ template:
10
+ <person>@</person>
11
+
12
+ raw:
13
+ <person>John Doe</person>
14
+
15
+ simple_text_alias:
16
+ template:
17
+ <person>name</person>
18
+
19
+ raw:
20
+ <person>John Doe</person>
21
+
22
+
23
+ skip_text_node:
24
+ template:
25
+ <name xmlns:ch='http://piesync.com/xml/chemicals' ch:as='name'>
26
+ <first-name></first-name>
27
+ <last-name>last_name</last-name>
28
+ </name>
29
+
30
+ raw:
31
+ <name>
32
+ <first-name>John</first-name>
33
+ <last-name>Doe</last-name>
34
+ </name>
35
+
36
+ simple_attributes:
37
+ template:
38
+ <person xmlns:ch='http://piesync.com/xml/chemicals' name='full_name'/>
39
+ raw:
40
+ <person name="John Doe"/>
41
+
42
+ ignore_attribute:
43
+ template:
44
+ <person xmlns:ch='http://piesync.com/xml/chemicals' />
45
+ raw:
46
+ <person name='John Doe'/>
47
+
48
+ text_attributes:
49
+ template:
50
+ <person xmlns:ch='http://piesync.com/xml/chemicals' age='age'>name</person>
51
+ raw:
52
+ <person age='24'>John Doe</person>
53
+
54
+ simple_element_alias:
55
+ template:
56
+ <person xmlns:ch='http://piesync.com/xml/chemicals' ch:as='individual'>@</person>
57
+
58
+ raw:
59
+ <person>John Doe</person>
60
+
61
+ skip_element:
62
+ template:
63
+ <person xmlns:ch='http://piesync.com/xml/chemicals' ch:as='individual'>
64
+ <name>@</name>
65
+ </person>
66
+
67
+ raw:
68
+ <person>
69
+ <name>John Doe</name>
70
+ </person>
71
+
72
+ empty_collection:
73
+ template:
74
+ <person xmlns:ch='http://piesync.com/xml/chemicals'>
75
+ <emails>
76
+ <email ch:as='emails' ch:mode='collect'>@</email>
77
+ </emails>
78
+ </person>
79
+
80
+ raw:
81
+ <person>
82
+ <emails>
83
+ </emails>
84
+ </person>
85
+
86
+ simple_collection:
87
+ template:
88
+ <person xmlns:ch='http://piesync.com/xml/chemicals'>
89
+ <emails>
90
+ <email ch:as='emails' ch:mode='collect'>@</email>
91
+ </emails>
92
+ </person>
93
+
94
+ raw:
95
+ <person>
96
+ <emails>
97
+ <email>john.doe@gmail.com</email>
98
+ <email>john@acme.com</email>
99
+ </emails>
100
+ </person>
101
+
102
+ multiple_collections:
103
+ template:
104
+ <person xmlns:ch='http://piesync.com/xml/chemicals' ch:as='contact'>
105
+ <emails>
106
+ <email ch:mode='collect' ch:as='emails'>@</email>
107
+ </emails>
108
+ <phone-numbers>
109
+ <number ch:mode='collect' ch:as='phone_numbers'>@</number>
110
+ </phone-numbers>
111
+ </person>
112
+
113
+ raw:
114
+ <person>
115
+ <emails>
116
+ <email>john.doe@gmail.com</email>
117
+ <email>john@acme.com</email>
118
+ </emails>
119
+ <phone-numbers>
120
+ <number>1</number>
121
+ <number>2</number>
122
+ </phone-numbers>
123
+ </person>
124
+
125
+ mixed_collection:
126
+ template:
127
+ <person xmlns:ch='http://piesync.com/xml/chemicals' ch:as='contact'>
128
+ <email ch:as='emails' ch:mode='collect'>@</email>
129
+ <name>name</name>
130
+ </person>
131
+ raw:
132
+ <person>
133
+ <email>john.doe@gmail.com</email>
134
+ <email>john@acme.com</email>
135
+ <name>John Doe</name>
136
+ </person>
137
+
138
+ mixed_collections:
139
+ template:
140
+ <person xmlns:ch='http://piesync.com/xml/chemicals' ch:as='contact'>
141
+ <email label='label' ch:as='emails' ch:mode='collect'>address</email>
142
+ <phone ch:as='phones' ch:mode='collect'>@</phone>
143
+ <address ch:as='addresses' ch:mode='collect'>@</address>
144
+ <name>name</name>
145
+ </person>
146
+ raw:
147
+ <person>
148
+ <email label='work'>john.doe@gmail.com</email>
149
+ <email>john@acme.com</email>
150
+ <phone>1</phone>
151
+ <name>John Doe</name>
152
+ </person>
153
+
154
+ mixed_collections_extreme:
155
+ template:
156
+ <people xmlns:ch='http://piesync.com/xml/chemicals'>
157
+ <person ch:mode='collect'>
158
+ <email label='label' ch:as='emails' ch:mode='collect'>address</email>
159
+ <phone ch:as='phones' ch:mode='collect'>@</phone>
160
+ <address ch:as='addresses' ch:mode='collect' country='country' code='country_code'>
161
+ <street>street</street>
162
+ <number>housenumber</number>
163
+ </address>
164
+ <name>name</name>
165
+ </person>
166
+ </people>
167
+ raw:
168
+ <people>
169
+ <person>
170
+ <email label='work'>john.doe@gmail.com</email>
171
+ <email>john@acme.com</email>
172
+ <phone>1</phone>
173
+ <name>John Doe</name>
174
+ </person>
175
+ <person>
176
+ <phone>1</phone>
177
+ <phone>2</phone>
178
+ <phone>3</phone>
179
+ <address country='Belgium' code='BE'>
180
+ <street>Désiré Van Monckhovenstraat</street>
181
+ <number>123</number>
182
+ </address>
183
+ </person>
184
+ </people>
185
+
186
+ mixed_elements_text:
187
+ template:
188
+ <people xmlns:ch='http://piesync.com/xml/chemicals'>
189
+ <person ch:mode='collect'>
190
+ <name ch:as='name'>
191
+ <first>given</first>
192
+ <last>family</last>
193
+ </name>
194
+ <emails>
195
+ <email ch:mode='collect' ch:as='emails'>@</email>
196
+ </emails>
197
+ <phone-numbers>
198
+ <number ch:mode='collect' ch:as='phones'>
199
+ <country>country</country>
200
+ <number>
201
+ <legacy>number</legacy>
202
+ </number>
203
+ </number>
204
+ </phone-numbers>
205
+ </person>
206
+ </people>
207
+ raw:
208
+ <people>
209
+ <person>
210
+ <name>
211
+ <first>John</first>
212
+ <last>Doe</last>
213
+ </name>
214
+ <emails>
215
+ <email>john.doe@gmail.com</email>
216
+ <email>john@acme.com</email>
217
+ </emails>
218
+ <phone-numbers>
219
+ <number>
220
+ <country>Belgium</country>
221
+ <number>
222
+ <legacy>1</legacy>
223
+ </number>
224
+ <useless>Hey</useless>
225
+ </number>
226
+ <number>
227
+ <country>USA</country>
228
+ <number>
229
+ <legacy>2</legacy>
230
+ </number>
231
+ </number>
232
+ </phone-numbers>
233
+ </person>
234
+ <person>
235
+ <name>
236
+ <first>Jane</first>
237
+ </name>
238
+ <emails>
239
+ <email>jane.doe@gmail.com</email>
240
+ </emails>
241
+ <useless>Hey</useless>
242
+ </person>
243
+ </people>
244
+ raw_render:
245
+ <people>
246
+ <person>
247
+ <name>
248
+ <first>John</first>
249
+ <last>Doe</last>
250
+ </name>
251
+ <emails>
252
+ <email>john.doe@gmail.com</email>
253
+ <email>john@acme.com</email>
254
+ </emails>
255
+ <phone-numbers>
256
+ <number>
257
+ <country>Belgium</country>
258
+ <number>
259
+ <legacy>1</legacy>
260
+ </number>
261
+ </number>
262
+ <number>
263
+ <country>USA</country>
264
+ <number>
265
+ <legacy>2</legacy>
266
+ </number>
267
+ </number>
268
+ </phone-numbers>
269
+ </person>
270
+ <person>
271
+ <name>
272
+ <first>Jane</first>
273
+ </name>
274
+ <emails>
275
+ <email>jane.doe@gmail.com</email>
276
+ </emails>
277
+ </person>
278
+ </people>
279
+
280
+ mixed_elements_text_attributes:
281
+ template:
282
+ <people xmlns:ch='http://piesync.com/xml/chemicals'>
283
+ <person ch:mode='collect'>
284
+ <name ch:as='name'>
285
+ <first>given</first>
286
+ <last>family</last>
287
+ </name>
288
+ <emails>
289
+ <email ch:mode='collect' ch:as='emails' type='label'>address</email>
290
+ </emails>
291
+ <phone-numbers>
292
+ <number ch:mode='collect' ch:as='phones'>
293
+ <country>country</country>
294
+ <number>
295
+ <legacy system='system'>number</legacy>
296
+ </number>
297
+ </number>
298
+ </phone-numbers>
299
+ </person>
300
+ </people>
301
+ raw:
302
+ <people>
303
+ <person>
304
+ <name>
305
+ <first>John</first>
306
+ <last>Doe</last>
307
+ </name>
308
+ <emails useless='hey'>
309
+ <email type='home'>john.doe@gmail.com</email>
310
+ <email>john@acme.com</email>
311
+ </emails>
312
+ <phone-numbers>
313
+ <number>
314
+ <country>Belgium</country>
315
+ <number>
316
+ <legacy system='sap'>1</legacy>
317
+ </number>
318
+ <useless>Hey</useless>
319
+ </number>
320
+ <number>
321
+ <country>USA</country>
322
+ <number>
323
+ <legacy>2</legacy>
324
+ </number>
325
+ </number>
326
+ </phone-numbers>
327
+ </person>
328
+ <person>
329
+ <name>
330
+ <first>Jane</first>
331
+ </name>
332
+ <emails>
333
+ <email type='work'>jane.doe@gmail.com</email>
334
+ </emails>
335
+ <useless>Hey</useless>
336
+ </person>
337
+ </people>
338
+ raw_render:
339
+ <people>
340
+ <person>
341
+ <name>
342
+ <first>John</first>
343
+ <last>Doe</last>
344
+ </name>
345
+ <emails>
346
+ <email type='home'>john.doe@gmail.com</email>
347
+ <email>john@acme.com</email>
348
+ </emails>
349
+ <phone-numbers>
350
+ <number>
351
+ <country>Belgium</country>
352
+ <number>
353
+ <legacy system='sap'>1</legacy>
354
+ </number>
355
+ </number>
356
+ <number>
357
+ <country>USA</country>
358
+ <number>
359
+ <legacy>2</legacy>
360
+ </number>
361
+ </number>
362
+ </phone-numbers>
363
+ </person>
364
+ <person>
365
+ <name>
366
+ <first>Jane</first>
367
+ </name>
368
+ <emails>
369
+ <email type='work'>jane.doe@gmail.com</email>
370
+ </emails>
371
+ </person>
372
+ </people>
373
+
374
+ namespaces:
375
+ template:
376
+ <name xmlns:ch='http://piesync.com/xml/chemicals'
377
+ xmlns:test='http://piesync.com/xml/test'
378
+ xmlns:test2='http://piesync.com/xml/test2' ch:as='name'
379
+ test2:age='age'>
380
+ <test:first-name>first_name</test:first-name>
381
+ <test:last-name>last_name</test:last-name>
382
+ </name>
383
+
384
+ raw:
385
+ <name xmlns:test='http://piesync.com/xml/test' xmlns:test2='http://piesync.com/xml/test2'
386
+ test2:age='24'>
387
+ <test:first-name>John</test:first-name>
388
+ <test:last-name>Doe</test:last-name>
389
+ </name>
390
+
391
+ default_namespaces:
392
+ template:
393
+ <test:name xmlns:ch='http://piesync.com/xml/chemicals'
394
+ xmlns:test='http://piesync.com/xml/test'
395
+ xmlns:test2='http://piesync.com/xml/test2' ch:as='name'
396
+ test2:age='age'>
397
+ <test:first-name test2:length='lds'>first_name</test:first-name>
398
+ <test:last-name>last_name</test:last-name>
399
+ <test2:company test2:name='title'>company</test2:company>
400
+ </test:name>
401
+
402
+ raw:
403
+ <name xmlns='http://piesync.com/xml/test' xmlns:test2='http://piesync.com/xml/test2'
404
+ test2:age='24'>
405
+ <last-name>Doe</last-name>
406
+ <first-name>John</first-name>
407
+ <test2:company test2:name='CEO'>PieSync</test2:company>
408
+ </name>
409
+
410
+ multiple_default_namespaces:
411
+ template:
412
+ <test:name xmlns:ch='http://piesync.com/xml/chemicals'
413
+ xmlns:test='http://piesync.com/xml/test'
414
+ xmlns:test2='http://piesync.com/xml/test2' ch:as='name'
415
+ age='age'>
416
+ <test:first-name test2:length='lds'>first_name</test:first-name>
417
+ <test:last-name>last_name</test:last-name>
418
+ <test2:company test2:name='title'>
419
+ <test2:name>company</test2:name>
420
+ <test2:title>title</test2:title>
421
+ </test2:company>
422
+ </test:name>
423
+
424
+ raw:
425
+ <name xmlns='http://piesync.com/xml/test' age='24'>
426
+ <last-name>Doe</last-name>
427
+ <first-name>John</first-name>
428
+ <company xmlns='http://piesync.com/xml/test2'>
429
+ <name>PieSync</name>
430
+ <title>CEO</title>
431
+ </company>
432
+ </name>
433
+
434
+ sudden_namespaces:
435
+ template:
436
+ <name xmlns:ch='http://piesync.com/xml/chemicals'
437
+ xmlns:test='http://piesync.com/xml/test'
438
+ xmlns:test2='http://piesync.com/xml/test2'
439
+ xmlns:sudden='http://piesync.com/xml/sudden'
440
+ ch:as='name'
441
+ test2:age='age'>
442
+ <test:first-name>first_name</test:first-name>
443
+ <test:last-name>last_name</test:last-name>
444
+ <sudden:gender>gender</sudden:gender>
445
+ </name>
446
+
447
+ raw:
448
+ <name xmlns:test='http://piesync.com/xml/test' xmlns:test2='http://piesync.com/xml/test2'
449
+ test2:age='24'>
450
+ <test:first-name>John</test:first-name>
451
+ <test:last-name>Doe</test:last-name>
452
+ <sudden:gender xmlns:sudden='http://piesync.com/xml/sudden'>male</sudden:gender>
453
+ </name>
454
+
455
+ different_prefix_names:
456
+ template:
457
+ <name xmlns:ch='http://piesync.com/xml/chemicals'
458
+ xmlns:a='http://piesync.com/xml/test'
459
+ xmlns:b='http://piesync.com/xml/test2' ch:as='name'
460
+ b:age='age'>
461
+ <a:first-name>first_name</a:first-name>
462
+ <a:last-name>last_name</a:last-name>
463
+ </name>
464
+
465
+ raw:
466
+ <name xmlns:test='http://piesync.com/xml/test' xmlns:test2='http://piesync.com/xml/test2'
467
+ test2:age='24'>
468
+ <test:first-name>John</test:first-name>
469
+ <test:last-name>Doe</test:last-name>
470
+ </name>
471
+
472
+ preserve_empty_attributes:
473
+ template:
474
+ <person xmlns:ch='http://piesync.com/xml/chemicals'>
475
+ <name first='first_name' last='last_name' />
476
+ </person>
477
+
478
+ raw:
479
+ <person>
480
+ <name first='' last='Doe' />
481
+ </person>
482
+
483
+ partial_template:
484
+ template:
485
+ <person ch:as='balance' xmlns:ch='http://piesync.com/xml/chemicals'>
486
+ <useful>
487
+ <balance currency='currency'>amount</balance>
488
+ <useful>
489
+ </person>
490
+
491
+ raw:
492
+ <person>
493
+ <useless>
494
+ <emails>
495
+ <email primary='true'>john.doe@acme.com</email>
496
+ <email>john.doe@gmail.com</email>
497
+ </emails
498
+ </useless>
499
+ <useful>
500
+ <balance currency='dollar'>1.000.000.000</balance>
501
+ <useful>
502
+ </person>
503
+
504
+ no_data:
505
+ template:
506
+ <atom:entry xmlns:ch='http://piesync.com/xml/chemicals' xmlns:atom='http://www.w3.org/2005/Atom' xmlns:gContact='http://schemas.google.com/contact/2008' xmlns:gd='http://schemas.google.com/g/2005' xmlns:app='http://www.w3.org/2007/app' xmlns:batch='http://schemas.google.com/gdata/batch' >
507
+ <gd:name ch:as='name'>
508
+ <gd:givenName>first_name</gd:givenName>
509
+ <gd:familyName>last_name</gd:familyName>
510
+ </gd:name>
511
+ <bla>b</bla>
512
+ </atom:entry>
513
+ raw:
514
+ <atom:entry xmlns:atom='http://www.w3.org/2005/Atom' xmlns:gContact='http://schemas.google.com/contact/2008' xmlns:gd='http://schemas.google.com/g/2005' xmlns:app='http://www.w3.org/2007/app' xmlns:batch='http://schemas.google.com/gdata/batch' >
515
+ <gd:name ch:as='name'>
516
+ </gd:name>
517
+ </atom:entry>