xx 0.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,11 @@
1
1
  unless defined? $__xx_rb__
2
-
3
2
  require "rexml/document"
4
3
 
5
-
6
4
  module XX
7
5
  #--{{{
8
- VERSION = "0.1.0"
6
+ VERSION = "2.0.0"
7
+
8
+ def self.version() VERSION end
9
9
 
10
10
  %w(
11
11
  CRAZY_LIKE_A_HELL
@@ -19,11 +19,13 @@ module XX
19
19
  attr "doc"
20
20
  attr "stack"
21
21
  attr "size"
22
+ attr_accessor "xmldecl"
22
23
 
23
24
  def initialize *a, &b
24
25
  #--{{{
25
26
  @doc = ::REXML::Document::new *a, &b
26
27
  @stack = [@doc]
28
+ @xmldecl = nil
27
29
  @size = 0
28
30
  #--}}}
29
31
  end
@@ -51,17 +53,23 @@ module XX
51
53
  end
52
54
  def to_str port = ""
53
55
  #--{{{
54
- @doc.write port, indent=-1, transitive=false, ie_hack=true
55
- port
56
+ xmldecl ? ugly(port) : pretty(port)
56
57
  #--}}}
57
58
  end
58
59
  alias_method "to_s", "to_str"
59
- def pretty port = ''
60
+ def pretty port = ""
60
61
  #--{{{
61
62
  @doc.write port, indent=2, transitive=false, ie_hack=true
62
63
  port
63
64
  #--}}}
64
65
  end
66
+ def ugly port = ''
67
+ #--{{{
68
+ @doc.write port, indent=-1, transitive=false, ie_hack=true
69
+ port
70
+ #--}}}
71
+ end
72
+ alias_method "compact", "ugly"
65
73
  def create element
66
74
  #--{{{
67
75
  push element
@@ -173,66 +181,33 @@ module XX
173
181
 
174
182
  module InstanceMethods
175
183
  #--{{{
176
- def method_missing m, *a, &b
184
+ def _ tag_name, *a, &b
177
185
  #--{{{
178
- m = m.to_s
186
+ hashes, nothashes = a.partition{|x| Hash === x}
179
187
 
180
- tag_method, tag_name = xx_class::xx_tag_method_name m
181
-
182
- c_method_missing = xx_class::xx_config_for "method_missing", xx_which
183
- c_tags = xx_class::xx_config_for "tags", xx_which
184
-
185
- pat =
186
- case c_method_missing
187
- when ::XX::CRAZY_LIKE_A_HELL
188
- %r/.*/
189
- when ::XX::PERMISSIVE
190
- %r/_$/o
191
- when ::XX::STRICT
192
- %r/_$/o
193
- else
194
- super
195
- end
196
-
197
- super unless m =~ pat
198
-
199
- if c_method_missing == ::XX::STRICT
200
- super unless c_tags.include? tag_name
201
- end
202
-
203
- ret, defined = nil
188
+ doc = xx_doc
189
+ element = ::REXML::Element::new "#{ tag_name }"
204
190
 
205
- begin
206
- xx_class::xx_define_tmp_method tag_method
207
- xx_class::xx_define_tag_method tag_method, tag_name
208
- ret = send tag_method, *a, &b
209
- defined = true
210
- ensure
211
- xx_class::xx_remove_tag_method tag_method unless defined
212
- end
191
+ hashes.each{|h| h.each{|k,v| element.add_attribute k.to_s, v}}
192
+ nothashes.each{|nh| element << ::REXML::Text::new(nh.to_s)}
213
193
 
214
- ret
194
+ doc.create element, &b
215
195
  #--}}}
216
196
  end
217
- def xx_tag_ tag_name, *a, &b
197
+ alias_method "xx_tag" , "_"
198
+ alias_method "__" , "_"
199
+ alias_method "g__" , "_"
200
+ def method_missing m, *a, &b
218
201
  #--{{{
219
- tag_method, tag_name = xx_class::xx_tag_method_name tag_name
202
+ m = m.to_s
220
203
 
221
- ret, defined = nil
204
+ tag_name = m.sub! %r/_+$/, ''
222
205
 
223
- begin
224
- xx_class::xx_define_tmp_method tag_method
225
- xx_class::xx_define_tag_method tag_method, tag_name
226
- ret = send tag_method, *a, &b
227
- defined = true
228
- ensure
229
- xx_class::xx_remove_tag_method tag_method unless defined
230
- end
206
+ super unless tag_name
231
207
 
232
- ret
208
+ __ tag_name, *a, &b
233
209
  #--}}}
234
210
  end
235
- alias_method "g_", "xx_tag_"
236
211
  def xx_which *argv
237
212
  #--{{{
238
213
  @xx_which = nil unless defined? @xx_which
@@ -256,7 +231,6 @@ module XX
256
231
  ddoc = doc.doc
257
232
  begin
258
233
  @xx_docs.push doc
259
- b.call doc if b
260
234
 
261
235
  doctype = xx_config_for "doctype", xx_which
262
236
  if doctype
@@ -273,9 +247,12 @@ module XX
273
247
  xmldecl = ::REXML::XMLDecl::new xmldecl unless
274
248
  ::REXML::XMLDecl === xmldecl
275
249
  ddoc << xmldecl
250
+ doc.xmldecl = ::REXML::XMLDecl
276
251
  end
277
252
  end
278
253
 
254
+ b.call doc if b
255
+
279
256
  return doc
280
257
  ensure
281
258
  @xx_docs.pop
@@ -303,8 +280,7 @@ module XX
303
280
  doc.create text, &b
304
281
  #--}}}
305
282
  end
306
- alias_method "text_", "xx_text_"
307
- alias_method "t_", "xx_text_"
283
+ alias_method "t__", "xx_text_"
308
284
  def xx_markup_ *objects, &b
309
285
  #--{{{
310
286
  doc = xx_doc
@@ -322,7 +298,7 @@ module XX
322
298
  ret
323
299
  #--}}}
324
300
  end
325
- alias_method "x_", "xx_markup_"
301
+ alias_method "x__", "xx_markup_"
326
302
  def xx_any_ *objects, &b
327
303
  #--{{{
328
304
  doc = xx_doc
@@ -340,8 +316,8 @@ module XX
340
316
  doc.create text, &b
341
317
  #--}}}
342
318
  end
343
- alias_method "h_", "xx_any_"
344
- alias_method "x_", "xx_any_" # supplant for now
319
+ alias_method "h__", "xx_any_"
320
+ alias_method "x__", "xx_any_" # supplant for now
345
321
  def xx_cdata_ *objects, &b
346
322
  #--{{{
347
323
  doc = xx_doc
@@ -355,7 +331,7 @@ module XX
355
331
  doc.create cdata, &b
356
332
  #--}}}
357
333
  end
358
- alias_method "c_", "xx_cdata_"
334
+ alias_method "c__", "xx_cdata_"
359
335
  def xx_parse_attributes string
360
336
  #--{{{
361
337
  string = string.to_s
@@ -364,7 +340,7 @@ module XX
364
340
  xx_parse_yaml_attributes(tokens.join(','))
365
341
  #--}}}
366
342
  end
367
- alias_method "att_", "xx_parse_attributes"
343
+ alias_method "a__", "xx_parse_attributes"
368
344
  def xx_parse_yaml_attributes string
369
345
  #--{{{
370
346
  require "yaml"
@@ -376,8 +352,7 @@ module XX
376
352
  obj
377
353
  #--}}}
378
354
  end
379
- alias_method "at_", "xx_parse_yaml_attributes"
380
- alias_method "yat_", "xx_parse_yaml_attributes"
355
+ alias_method "y__", "xx_parse_yaml_attributes"
381
356
  def xx_class
382
357
  #--{{{
383
358
  @xx_class ||= self.class
@@ -444,7 +419,7 @@ module XX
444
419
  def xx_define_tag_method tag_method, tag_name = nil
445
420
  #--{{{
446
421
  tag_method = tag_method.to_s
447
- tag_name ||= tag_method.gsub %r/_+$/, ""
422
+ tag_name ||= tag_method.sub(%r/_$/, '')
448
423
 
449
424
  module_eval <<-code
450
425
  def #{ tag_method } *a, &b
@@ -557,6 +532,7 @@ module XX
557
532
  end
558
533
  #--}}}
559
534
  end
535
+ alias_method "xhtml__", "xhtml_"
560
536
 
561
537
  module Strict
562
538
  #--{{{
@@ -578,6 +554,7 @@ module XX
578
554
  super(which, *a, &b)
579
555
  #--}}}
580
556
  end
557
+ alias_method "xhtml__", "xhtml_"
581
558
  #--}}}
582
559
  end
583
560
 
@@ -590,6 +567,7 @@ module XX
590
567
  super(which, *a, &b)
591
568
  #--}}}
592
569
  end
570
+ alias_method "xhtml__", "xhtml_"
593
571
  #--}}}
594
572
  end
595
573
  #--}}}
@@ -605,6 +583,7 @@ module XX
605
583
  xx_which(which){ xx_with_doc_in_effect *a, &b }
606
584
  #--}}}
607
585
  end
586
+ alias_method "html4__", "html4_"
608
587
 
609
588
  module Strict
610
589
  #--{{{
@@ -625,6 +604,7 @@ module XX
625
604
  super(which, *a, &b)
626
605
  #--}}}
627
606
  end
607
+ alias_method "html4__", "html4_"
628
608
  #--}}}
629
609
  end
630
610
 
@@ -637,6 +617,7 @@ module XX
637
617
  super(which, *a, &b)
638
618
  #--}}}
639
619
  end
620
+ alias_method "html4__", "html4_"
640
621
  #--}}}
641
622
  end
642
623
  #--}}}
@@ -653,6 +634,7 @@ module XX
653
634
  xx_which(XML){ xx_with_doc_in_effect *a, &b }
654
635
  #--}}}
655
636
  end
637
+ alias_method "xml__", "xml_"
656
638
  #--}}}
657
639
  end
658
640
  #--}}}
data/lib/xx.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  unless defined? $__xx_rb__
2
-
3
2
  require "rexml/document"
4
3
 
5
-
6
4
  module XX
7
5
  #--{{{
8
- VERSION = "0.1.0"
6
+ VERSION = "2.0.0"
7
+
8
+ def self.version() VERSION end
9
9
 
10
10
  %w(
11
11
  CRAZY_LIKE_A_HELL
@@ -19,11 +19,13 @@ module XX
19
19
  attr "doc"
20
20
  attr "stack"
21
21
  attr "size"
22
+ attr_accessor "xmldecl"
22
23
 
23
24
  def initialize *a, &b
24
25
  #--{{{
25
26
  @doc = ::REXML::Document::new *a, &b
26
27
  @stack = [@doc]
28
+ @xmldecl = nil
27
29
  @size = 0
28
30
  #--}}}
29
31
  end
@@ -51,17 +53,23 @@ module XX
51
53
  end
52
54
  def to_str port = ""
53
55
  #--{{{
54
- @doc.write port, indent=-1, transitive=false, ie_hack=true
55
- port
56
+ xmldecl ? ugly(port) : pretty(port)
56
57
  #--}}}
57
58
  end
58
59
  alias_method "to_s", "to_str"
59
- def pretty port = ''
60
+ def pretty port = ""
60
61
  #--{{{
61
62
  @doc.write port, indent=2, transitive=false, ie_hack=true
62
63
  port
63
64
  #--}}}
64
65
  end
66
+ def ugly port = ''
67
+ #--{{{
68
+ @doc.write port, indent=-1, transitive=false, ie_hack=true
69
+ port
70
+ #--}}}
71
+ end
72
+ alias_method "compact", "ugly"
65
73
  def create element
66
74
  #--{{{
67
75
  push element
@@ -173,66 +181,33 @@ module XX
173
181
 
174
182
  module InstanceMethods
175
183
  #--{{{
176
- def method_missing m, *a, &b
184
+ def _ tag_name, *a, &b
177
185
  #--{{{
178
- m = m.to_s
186
+ hashes, nothashes = a.partition{|x| Hash === x}
179
187
 
180
- tag_method, tag_name = xx_class::xx_tag_method_name m
181
-
182
- c_method_missing = xx_class::xx_config_for "method_missing", xx_which
183
- c_tags = xx_class::xx_config_for "tags", xx_which
184
-
185
- pat =
186
- case c_method_missing
187
- when ::XX::CRAZY_LIKE_A_HELL
188
- %r/.*/
189
- when ::XX::PERMISSIVE
190
- %r/_$/o
191
- when ::XX::STRICT
192
- %r/_$/o
193
- else
194
- super
195
- end
196
-
197
- super unless m =~ pat
198
-
199
- if c_method_missing == ::XX::STRICT
200
- super unless c_tags.include? tag_name
201
- end
202
-
203
- ret, defined = nil
188
+ doc = xx_doc
189
+ element = ::REXML::Element::new "#{ tag_name }"
204
190
 
205
- begin
206
- xx_class::xx_define_tmp_method tag_method
207
- xx_class::xx_define_tag_method tag_method, tag_name
208
- ret = send tag_method, *a, &b
209
- defined = true
210
- ensure
211
- xx_class::xx_remove_tag_method tag_method unless defined
212
- end
191
+ hashes.each{|h| h.each{|k,v| element.add_attribute k.to_s, v}}
192
+ nothashes.each{|nh| element << ::REXML::Text::new(nh.to_s)}
213
193
 
214
- ret
194
+ doc.create element, &b
215
195
  #--}}}
216
196
  end
217
- def xx_tag_ tag_name, *a, &b
197
+ alias_method "xx_tag" , "_"
198
+ alias_method "__" , "_"
199
+ alias_method "g__" , "_"
200
+ def method_missing m, *a, &b
218
201
  #--{{{
219
- tag_method, tag_name = xx_class::xx_tag_method_name tag_name
202
+ m = m.to_s
220
203
 
221
- ret, defined = nil
204
+ tag_name = m.sub! %r/_+$/, ''
222
205
 
223
- begin
224
- xx_class::xx_define_tmp_method tag_method
225
- xx_class::xx_define_tag_method tag_method, tag_name
226
- ret = send tag_method, *a, &b
227
- defined = true
228
- ensure
229
- xx_class::xx_remove_tag_method tag_method unless defined
230
- end
206
+ super unless tag_name
231
207
 
232
- ret
208
+ __ tag_name, *a, &b
233
209
  #--}}}
234
210
  end
235
- alias_method "g_", "xx_tag_"
236
211
  def xx_which *argv
237
212
  #--{{{
238
213
  @xx_which = nil unless defined? @xx_which
@@ -256,7 +231,6 @@ module XX
256
231
  ddoc = doc.doc
257
232
  begin
258
233
  @xx_docs.push doc
259
- b.call doc if b
260
234
 
261
235
  doctype = xx_config_for "doctype", xx_which
262
236
  if doctype
@@ -273,9 +247,12 @@ module XX
273
247
  xmldecl = ::REXML::XMLDecl::new xmldecl unless
274
248
  ::REXML::XMLDecl === xmldecl
275
249
  ddoc << xmldecl
250
+ doc.xmldecl = ::REXML::XMLDecl
276
251
  end
277
252
  end
278
253
 
254
+ b.call doc if b
255
+
279
256
  return doc
280
257
  ensure
281
258
  @xx_docs.pop
@@ -303,8 +280,7 @@ module XX
303
280
  doc.create text, &b
304
281
  #--}}}
305
282
  end
306
- alias_method "text_", "xx_text_"
307
- alias_method "t_", "xx_text_"
283
+ alias_method "t__", "xx_text_"
308
284
  def xx_markup_ *objects, &b
309
285
  #--{{{
310
286
  doc = xx_doc
@@ -322,7 +298,7 @@ module XX
322
298
  ret
323
299
  #--}}}
324
300
  end
325
- alias_method "x_", "xx_markup_"
301
+ alias_method "x__", "xx_markup_"
326
302
  def xx_any_ *objects, &b
327
303
  #--{{{
328
304
  doc = xx_doc
@@ -340,8 +316,8 @@ module XX
340
316
  doc.create text, &b
341
317
  #--}}}
342
318
  end
343
- alias_method "h_", "xx_any_"
344
- alias_method "x_", "xx_any_" # supplant for now
319
+ alias_method "h__", "xx_any_"
320
+ alias_method "x__", "xx_any_" # supplant for now
345
321
  def xx_cdata_ *objects, &b
346
322
  #--{{{
347
323
  doc = xx_doc
@@ -355,7 +331,7 @@ module XX
355
331
  doc.create cdata, &b
356
332
  #--}}}
357
333
  end
358
- alias_method "c_", "xx_cdata_"
334
+ alias_method "c__", "xx_cdata_"
359
335
  def xx_parse_attributes string
360
336
  #--{{{
361
337
  string = string.to_s
@@ -364,7 +340,7 @@ module XX
364
340
  xx_parse_yaml_attributes(tokens.join(','))
365
341
  #--}}}
366
342
  end
367
- alias_method "att_", "xx_parse_attributes"
343
+ alias_method "a__", "xx_parse_attributes"
368
344
  def xx_parse_yaml_attributes string
369
345
  #--{{{
370
346
  require "yaml"
@@ -376,8 +352,7 @@ module XX
376
352
  obj
377
353
  #--}}}
378
354
  end
379
- alias_method "at_", "xx_parse_yaml_attributes"
380
- alias_method "yat_", "xx_parse_yaml_attributes"
355
+ alias_method "y__", "xx_parse_yaml_attributes"
381
356
  def xx_class
382
357
  #--{{{
383
358
  @xx_class ||= self.class
@@ -444,7 +419,7 @@ module XX
444
419
  def xx_define_tag_method tag_method, tag_name = nil
445
420
  #--{{{
446
421
  tag_method = tag_method.to_s
447
- tag_name ||= tag_method.gsub %r/_+$/, ""
422
+ tag_name ||= tag_method.sub(%r/_$/, '')
448
423
 
449
424
  module_eval <<-code
450
425
  def #{ tag_method } *a, &b
@@ -557,6 +532,7 @@ module XX
557
532
  end
558
533
  #--}}}
559
534
  end
535
+ alias_method "xhtml__", "xhtml_"
560
536
 
561
537
  module Strict
562
538
  #--{{{
@@ -578,6 +554,7 @@ module XX
578
554
  super(which, *a, &b)
579
555
  #--}}}
580
556
  end
557
+ alias_method "xhtml__", "xhtml_"
581
558
  #--}}}
582
559
  end
583
560
 
@@ -590,6 +567,7 @@ module XX
590
567
  super(which, *a, &b)
591
568
  #--}}}
592
569
  end
570
+ alias_method "xhtml__", "xhtml_"
593
571
  #--}}}
594
572
  end
595
573
  #--}}}
@@ -605,6 +583,7 @@ module XX
605
583
  xx_which(which){ xx_with_doc_in_effect *a, &b }
606
584
  #--}}}
607
585
  end
586
+ alias_method "html4__", "html4_"
608
587
 
609
588
  module Strict
610
589
  #--{{{
@@ -625,6 +604,7 @@ module XX
625
604
  super(which, *a, &b)
626
605
  #--}}}
627
606
  end
607
+ alias_method "html4__", "html4_"
628
608
  #--}}}
629
609
  end
630
610
 
@@ -637,6 +617,7 @@ module XX
637
617
  super(which, *a, &b)
638
618
  #--}}}
639
619
  end
620
+ alias_method "html4__", "html4_"
640
621
  #--}}}
641
622
  end
642
623
  #--}}}
@@ -653,6 +634,7 @@ module XX
653
634
  xx_which(XML){ xx_with_doc_in_effect *a, &b }
654
635
  #--}}}
655
636
  end
637
+ alias_method "xml__", "xml_"
656
638
  #--}}}
657
639
  end
658
640
  #--}}}
data/test/xx.rb CHANGED
@@ -14,9 +14,9 @@ require 'test/unit'
14
14
  glob = File::join libdir, "*{.rb,.so}"
15
15
  Dir[glob].each{|f| require(File::expand_path(f))}
16
16
  #
17
- # find sample and expected dirs
17
+ # find samples and expected dirs
18
18
  #
19
- sampledir = File::expand_path(File::join(dirname, File::join("..", "sample")))
19
+ sampledir = File::expand_path(File::join(dirname, File::join("..", "samples")))
20
20
  expecteddir = File::join sampledir, "expected"
21
21
  #
22
22
  # this tests everything in samples/* and compares against samples/expected/*
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.11
2
+ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: xx
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.0
7
- date: 2006-01-24 00:00:00 -07:00
6
+ version: 2.0.0
7
+ date: 2007-02-16 00:00:00 -07:00
8
8
  summary: xx
9
9
  require_paths:
10
10
  - lib
@@ -25,10 +25,11 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
25
25
  platform: ruby
26
26
  signing_key:
27
27
  cert_chain:
28
+ post_install_message:
28
29
  authors:
29
30
  - Ara T. Howard
30
31
  files:
31
- - lib/xx-0.1.0.rb
32
+ - lib/xx-2.0.0.rb
32
33
  - lib/xx.rb
33
34
  test_files:
34
35
  - test/xx.rb