eim_xml 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,4 +1,6 @@
1
1
  load "Rakefile.utirake"
2
+ VER = "0.0.4"
3
+
2
4
  UtiRake.setup do
3
5
  rdoc do |t|
4
6
  t.title = "Easy IMplemented XML"
@@ -13,6 +15,7 @@ UtiRake.setup do
13
15
  s.email = "hiraku@hinet.mydns.jp"
14
16
  s.homepage = "http://eimxml.rubyforge.org/"
15
17
  s.rubyforge_project = "eimxml"
18
+ s.version = VER
16
19
  end
17
20
 
18
21
  publish("eimxml", "hiraku")
@@ -5,12 +5,13 @@
5
5
 
6
6
  require "rake/clean"
7
7
  require "rake/testtask"
8
- require "rake/rdoctask"
9
- require "rake/gempackagetask"
8
+ require "rdoc/task"
10
9
  require "rake/contrib/rubyforgepublisher"
11
10
  require "rubygems/package_task"
12
11
 
13
12
  class UtiRake
13
+ include Rake::DSL
14
+
14
15
  def self.setup(opt={}, &proc)
15
16
  ur = new
16
17
  ur.setup(opt, &proc)
@@ -23,12 +24,19 @@ class UtiRake
23
24
  def setup(opt={}, &proc)
24
25
  @opt = opt
25
26
  directory "external"
26
- CLOBBER << "external" << "coverage" << "coverage.spec" << "coverage.cuke" << "doc"
27
+ CLEAN << "coverage" << "coverage.spec" << "coverage.cuke" << "doc"
28
+ CLOBBER << "external"
27
29
 
28
30
  instance_eval(&proc) if proc
29
31
 
30
32
  if need_spec?
31
- require "spec/rake/spectask"
33
+ begin
34
+ @rspec2_flg = false
35
+ require "rspec/core/rake_task"
36
+ @rspec2_flg = true
37
+ rescue LoadError
38
+ require "spec/rake/spectask"
39
+ end
32
40
  define_spec_task
33
41
  end
34
42
 
@@ -44,6 +52,12 @@ class UtiRake
44
52
  define_alias_task if @alias_task
45
53
  end
46
54
 
55
+ def rspec2?; @rspec2_flg; end
56
+
57
+ def spec_task
58
+ rspec2? ? RSpec::Core::RakeTask : Spec::Rake::SpecTask
59
+ end
60
+
47
61
  def need_spec?
48
62
  File.directory?("spec")
49
63
  end
@@ -160,22 +174,21 @@ class UtiRake
160
174
  spec = Gem::Specification.new do |s|
161
175
  s.platform = Gem::Platform::RUBY
162
176
  s.files = FileList["Rakefile*", "lib/**/*", "spec/**/*"]
163
- s.version = ENV["VER"] || "0.0.0.noversion"
177
+ s.version = "0.0.0.noversion"
164
178
  gemspec_proc.call(s) if gemspec_proc
165
179
  end
166
180
 
167
181
  gem = Gem::PackageTask.new(spec) do |t|
168
182
  t.need_tar_gz = true
169
- t.need_zip = true
170
183
  package_proc.call(t) if package_proc
171
184
  end
172
185
 
173
- task "utirake:gem" do
186
+ task "utirake:copy_for_package" do
174
187
  mv "Rakefile.utirake", "Rakefile.utirake_#{$$}"
175
- symlink "external/utirake/utirake.rb", "Rakefile.utirake"
188
+ cp "external/utirake/utirake.rb", "Rakefile.utirake"
176
189
  end
177
190
 
178
- file "#{gem.package_dir}/#{gem.gem_spec.file_name}" => "utirake:gem"
191
+ file gem.package_dir_path => "utirake:copy_for_package"
179
192
 
180
193
  task :gem do
181
194
  rm "Rakefile.utirake"
@@ -185,7 +198,7 @@ class UtiRake
185
198
 
186
199
  def publish(project_name, user_id)
187
200
  task :publish => "rdoc" do
188
- yield if block_given
201
+ yield if block_given?
189
202
  Rake::RubyForgePublisher.new(project_name, user_id).upload
190
203
  end
191
204
  end
@@ -197,8 +210,15 @@ class UtiRake
197
210
  end
198
211
 
199
212
  def set_spec_opts(spec)
200
- spec.spec_opts << "-c"
201
- spec.libs << "." << "./lib" << "./external/lib"
213
+ spec.verbose = false
214
+ if rspec2?
215
+ spec.rspec_opts ||= []
216
+ spec.rspec_opts << "-c"
217
+ spec.rspec_opts << "-I" << "." << "-I" << "./lib" << "-I" << "./external/lib"
218
+ else
219
+ spec.spec_opts << "-c"
220
+ spec.libs << "." << "./lib" << "./external/lib"
221
+ end
202
222
  end
203
223
 
204
224
  def define_spec_task
@@ -206,8 +226,12 @@ class UtiRake
206
226
  namespace :spec do
207
227
  spec_files.each do |f|
208
228
  desc ""
209
- Spec::Rake::SpecTask.new(:apart) do |s|
210
- s.spec_files = FileList[f]
229
+ spec_task.new(:apart) do |s|
230
+ if rspec2?
231
+ s.pattern = f
232
+ else
233
+ s.spec_files = FileList[f]
234
+ end
211
235
  set_spec_opts(s)
212
236
  spec_proc.call(s) if spec_proc
213
237
  end
@@ -215,27 +239,36 @@ class UtiRake
215
239
  task(:apart).comment = "Run all specs separately"
216
240
 
217
241
  desc "Run all specs in a lump"
218
- Spec::Rake::SpecTask.new(:lump) do |s|
219
- s.spec_files = spec_files
242
+ spec_task.new(:lump) do |s|
243
+ s.spec_files = spec_files unless rspec2?
220
244
  set_spec_opts(s)
221
245
  spec_proc.call(s) if spec_proc
222
246
  end
223
247
 
224
248
  desc "Run all specs to profile"
225
- Spec::Rake::SpecTask.new(:profile) do |s|
249
+ spec_task.new(:profile) do |s|
226
250
  set_spec_opts(s)
227
- s.spec_opts << "-f" << "profile"
251
+ if rspec2?
252
+ s.rspec_opts << "-p"
253
+ else
254
+ s.spec_opts << "-f" << "profile"
255
+ end
228
256
  end
229
257
 
230
- `grep -sRn '#[[:space:]]*here[[:space:]]*$' spec`.split(/\n/).map{|l|
258
+ `grep -sRn '#[[:space:]]*here\\([[:space:]]\\|$\\)' --include='*.rb' spec`.split(/\n/).map{|l|
231
259
  next nil unless l=~/\A(.*?):(\d+):/
232
260
  [$1, $2.to_i]
233
261
  }.compact.sort{|a, b| FILE_SORT.call(a[0], b[0])}.reverse.each do |file, line|
234
262
  desc ""
235
- Spec::Rake::SpecTask.new(:here) do |s|
236
- s.spec_files = [file]
263
+ spec_task.new(:here) do |s|
237
264
  set_spec_opts(s)
238
- s.spec_opts << "-l#{line}"
265
+ if rspec2?
266
+ s.pattern = file
267
+ s.rspec_opts << "-l#{line}"
268
+ else
269
+ s.spec_files = [file]
270
+ s.spec_opts << "-l#{line}"
271
+ end
239
272
  spec_proc.call(s) if spec_proc
240
273
  end
241
274
  end
@@ -273,6 +306,8 @@ class UtiRake
273
306
  end
274
307
 
275
308
  def rcov_opts(t, aggregation)
309
+ t.rcov_opts ||= []
310
+ t.rcov_opts << "-I" << "./spec:./lib:./external/lib"
276
311
  t.rcov_opts << "--exclude" << "gems\/,features\/,external\/"
277
312
  t.rcov_opts << "--aggregate" << "coverage.data" if aggregation
278
313
  t.rcov = true
@@ -280,12 +315,17 @@ class UtiRake
280
315
 
281
316
  def define_rcov_each_task(aggregation)
282
317
  if need_spec?
283
- Spec::Rake::SpecTask.new do |t|
284
- t.spec_files = spec_files
318
+ spec_task.new do |t|
319
+ t.verbose = false
285
320
  rcov_opts(t, aggregation)
286
- set_spec_opts(t)
321
+ if rspec2?
322
+ t.rcov_opts << "-o" << "coverage.spec" unless aggregation
323
+ else
324
+ set_spec_opts(t)
325
+ t.spec_files = spec_files
326
+ t.rcov_dir = "coverage.spec" unless aggregation
327
+ end
287
328
  rcov_spec_proc.call(t) if rcov_spec_proc
288
- t.rcov_dir = "coverage.spec" unless aggregation
289
329
  end
290
330
  else
291
331
  task "spec"
@@ -16,10 +16,13 @@ module EimXML
16
16
  @preserve_space = false
17
17
  @indent_string = " "
18
18
  @indent_depth = 0
19
+ @option = opt.dup.tap{|h| [:out, :preservers].each{|k| h.delete(k)}}
19
20
  end
20
21
 
21
22
  def write(src)
22
23
  case src
24
+ when ElementWrapper
25
+ write_wrapper(src)
23
26
  when Comment
24
27
  write_comment(src)
25
28
  when Element
@@ -27,7 +30,7 @@ module EimXML
27
30
  when PCString
28
31
  write_pcstring(src)
29
32
  else
30
- write_string(src)
33
+ write_string(src.to_s)
31
34
  end
32
35
  end
33
36
 
@@ -108,5 +111,13 @@ module EimXML
108
111
  end
109
112
  write_newline
110
113
  end
114
+
115
+ def write_wrapper(wrapper)
116
+ wrapper.each(@option) do |i|
117
+ write(i)
118
+ end
119
+ end
111
120
  end
112
121
  end
122
+
123
+ require "eim_xml/formatter/element_wrapper"
@@ -0,0 +1,7 @@
1
+ class EimXML::Formatter
2
+ class ElementWrapper
3
+ def each(option, &proc)
4
+ contents(option).each(&proc)
5
+ end
6
+ end
7
+ end
@@ -31,11 +31,20 @@ module EimXML::XHTML
31
31
  end
32
32
  end
33
33
 
34
- class PreserveSpace_ < Simple_; end
34
+ class PreserveSpace_ < Base_
35
+ def initialize(name={}, attributes={})
36
+ if name.is_a?(Hash)
37
+ super(self.class.name[/.*::(.*)/, 1].downcase.to_sym, name)
38
+ else
39
+ super(name, attributes)
40
+ end
41
+ end
42
+ end
35
43
 
36
44
  class HEAD < Simple_; end
37
45
  class META < Simple_; end
38
46
  class LINK < Simple_; end
47
+ class IMG < Simple_; end
39
48
  class STYLE < PreserveSpace_; end
40
49
  class SCRIPT < PreserveSpace_; end
41
50
  class TITLE < Simple_; end
@@ -79,6 +88,9 @@ module EimXML::XHTML
79
88
  class TD < PreserveSpace_; end
80
89
  class BR < Simple_; end
81
90
  class HR < Simple_; end
91
+ class SELECT < Simple_; end
92
+ class OPTION < Simple_; end
93
+
82
94
 
83
95
  module Hn
84
96
  def self.new(level, attr={}, &proc)
@@ -96,7 +108,7 @@ module EimXML::XHTML
96
108
  end
97
109
  end
98
110
 
99
- class BUTTON < Base_
111
+ class BUTTON < PreserveSpace_
100
112
  def initialize(opt={})
101
113
  super(:button, opt)
102
114
  end
@@ -126,6 +138,12 @@ module EimXML::XHTML
126
138
  end
127
139
  end
128
140
 
141
+ class FILE < INPUT
142
+ def initialize(opt={})
143
+ super(opt.merge(:type=>:file))
144
+ end
145
+ end
146
+
129
147
  PRESERVE_SPACES = [PreserveSpace_]
130
148
  class Formatter < EimXML::Formatter
131
149
  def self.write(element, opt={})
@@ -3,6 +3,7 @@
3
3
  # Copyright (C) 2006, KURODA Hiraku <hiraku@hinet.mydns.jp>
4
4
  # You can redistribute it and/or modify it under GPL2.
5
5
 
6
+ $:.unshift "#{File.dirname(File.dirname(File.expand_path(__FILE__)))}/lib"
6
7
  require "test/unit"
7
8
  require "eim_xml/assertions"
8
9
 
@@ -4,7 +4,7 @@ require "eim_xml/dsl"
4
4
  describe EimXML::Formatter do
5
5
  describe ".write" do
6
6
  it "should return output object" do
7
- s = stub(:null_object=>true)
7
+ s = ""
8
8
  EimXML::Formatter.write(EimXML::Element.new(:e), :out=>s).should be_equal(s)
9
9
  end
10
10
 
@@ -213,3 +213,48 @@ EOT
213
213
  end
214
214
  end
215
215
  end
216
+
217
+ describe EimXML::Formatter::ElementWrapper do
218
+ before do
219
+ @out = ""
220
+ @opt = {:out=>@out, :preservers=>[], :a=>10, :b=>20}
221
+ @formatter = EimXML::Formatter.new(@opt)
222
+ @m = Module.new
223
+ class @m::Wrapper < EimXML::Formatter::ElementWrapper
224
+ def initialize(mocks)
225
+ @mocks = mocks
226
+ end
227
+
228
+ def contents(option)
229
+ @mocks
230
+ end
231
+ end
232
+ @mocks = [mock(:m1).as_null_object, mock(:m2).as_null_object]
233
+ @wrapper = @m::Wrapper.new(@mocks)
234
+ @xml = EimXML::Element.new(:e) do |e|
235
+ e << @wrapper
236
+ end
237
+ end
238
+
239
+ describe "#each" do
240
+ it "will give options from formatter" do
241
+ @wrapper.should_receive(:contents).with(:a=>10, :b=>20).and_return([])
242
+ @formatter.write(@xml)
243
+ end
244
+
245
+ it "yield result of contents" do
246
+ @mocks.each_with_index do |mock, index|
247
+ mock.should_receive(:to_s).and_return("m#{index}")
248
+ end
249
+ @formatter.write(@xml)
250
+ @out.should == "<e>\n m0\n m1\n</e>\n"
251
+ end
252
+
253
+ it "raise error when subclass of ElementWrapper is not implement #contents" do
254
+ class @m::Wrapper2 < EimXML::Formatter::ElementWrapper; end
255
+ @xml << @m::Wrapper2.new
256
+
257
+ expect{@formatter.write(@xml)}.to raise_error(NoMethodError)
258
+ end
259
+ end
260
+ end
@@ -56,6 +56,12 @@ module Module.new::M
56
56
  OpenDSL.style.should be_kind_of(STYLE)
57
57
  end
58
58
 
59
+ it "IMG" do
60
+ IMG.new.name.should == :img
61
+ XDSL.img.should be_kind_of(IMG)
62
+ OpenDSL.img.should be_kind_of(IMG)
63
+ end
64
+
59
65
  it "SCRIPT" do
60
66
  SCRIPT.new.name.should == :script
61
67
  XDSL.script.should be_kind_of(SCRIPT)
@@ -263,6 +269,10 @@ module Module.new::M
263
269
  t[:name].should == "t"
264
270
  end
265
271
 
272
+ it "BUTTON" do
273
+ BUTTON.new.should == Element.new(:button)
274
+ end
275
+
266
276
  it "INPUT" do
267
277
  INPUT.new(:type=>:test, :name=>:item, :value=>"v").should == Element.new(:input, :type=>:test, :name=>:item, :value=>"v")
268
278
  INPUT.new(:type=>"test", :name=>"item", :value=>"v").should == Element.new(:input, :type=>"test", :name=>"item", :value=>"v")
@@ -295,9 +305,9 @@ module Module.new::M
295
305
  end
296
306
 
297
307
  it "SUBMIT" do
298
- SUBMIT.new.should == Element.new(:input, :type=>:submit)
299
- SUBMIT.new(:value=>"OK").should == Element.new(:input, :type=>:submit, :value=>"OK")
300
- SUBMIT.new(:value=>"OK", :class=>"c").should == Element.new(:input, :type=>:submit, :value=>"OK", :class=>"c")
308
+ SUBMIT.new.should == Element.new(:button, :type=>:submit)
309
+ SUBMIT.new(:value=>"OK").should == Element.new(:button, :type=>:submit, :value=>"OK")
310
+ SUBMIT.new(:value=>"OK", :class=>"c").should == Element.new(:button, :type=>:submit, :value=>"OK", :class=>"c")
301
311
  opt = {:value=>"v", :name=>"n"}
302
312
  opt2 = opt.dup
303
313
  SUBMIT.new(opt2)
@@ -351,6 +361,27 @@ module Module.new::M
351
361
  t.should == PASSWORD.new(:name=>:n, :value=>:v)
352
362
  end
353
363
 
364
+ it "FILE" do
365
+ FILE.new(:name=>:foo).should == Element.new(:input, :type=>:file, :name=>:foo)
366
+ XDSL.file(:name=>:foo).should =~ FILE.new(:name=>:foo)
367
+
368
+ OpenDSL.file(:name=>:foo).should == FILE.new(:name=>:foo)
369
+ end
370
+
371
+ it "SELECT" do
372
+ SELECT.new(:name=>:foo).should == Element.new(:select, :name=>:foo)
373
+ XDSL.select(:name=>:foo).should == SELECT.new(:name=>:foo)
374
+
375
+ OpenDSL.select(:name=>:foo).should == SELECT.new(:name=>:foo)
376
+ end
377
+
378
+ it "OPTION" do
379
+ OPTION.new(:value=>:bar, :selected=>true){|e| e << "TEXT"}.should == Element.new(:option, :value=>:bar, :selected=>true){|e| e.add("TEXT")}
380
+ XDSL.option(:value=>:bar).should == OPTION.new(:value=>:bar)
381
+
382
+ OpenDSL.option(:value=>:bar).should == OPTION.new(:value=>:bar)
383
+ end
384
+
354
385
  it "BR" do
355
386
  BR.new.name.should == :br
356
387
  XDSL.br.should be_kind_of(BR)
@@ -427,6 +458,7 @@ module Module.new::M
427
458
  caption.add("c\nt")
428
459
  th.add("th\nt")
429
460
  td.add("td\nt")
461
+ button.add("button\nt")
430
462
  end
431
463
  end
432
464
 
@@ -480,6 +512,8 @@ t</caption>
480
512
  t</th>
481
513
  <td>td
482
514
  t</td>
515
+ <button>button
516
+ t</button>
483
517
  </body>
484
518
  </html>
485
519
  EOT
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eim_xml
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease: false
4
+ hash: 23
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - KURODA Hiraku
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-06 00:00:00 +09:00
19
- default_executable:
18
+ date: 2011-07-19 00:00:00 Z
20
19
  dependencies: []
21
20
 
22
21
  description:
@@ -30,21 +29,21 @@ extra_rdoc_files: []
30
29
  files:
31
30
  - Rakefile.utirake
32
31
  - Rakefile
33
- - lib/eim_xml/parser.rb
34
- - lib/eim_xml/dsl.rb
32
+ - lib/eim_xml/matcher.rb
35
33
  - lib/eim_xml/xhtml.rb
34
+ - lib/eim_xml/dsl.rb
35
+ - lib/eim_xml/parser.rb
36
+ - lib/eim_xml/formatter.rb
36
37
  - lib/eim_xml/xhtml/dsl.rb
37
38
  - lib/eim_xml/assertions.rb
38
- - lib/eim_xml/formatter.rb
39
- - lib/eim_xml/matcher.rb
39
+ - lib/eim_xml/formatter/element_wrapper.rb
40
40
  - lib/eim_xml.rb
41
- - spec/dsl_spec.rb
42
- - spec/assertions_spec.rb
43
- - spec/eim_xml_spec.rb
41
+ - spec/assertions_test.rb
44
42
  - spec/formatter_spec.rb
45
- - spec/parser_spec.rb
43
+ - spec/eim_xml_spec.rb
44
+ - spec/dsl_spec.rb
46
45
  - spec/xhtml_spec.rb
47
- has_rdoc: true
46
+ - spec/parser_spec.rb
48
47
  homepage: http://eimxml.rubyforge.org/
49
48
  licenses: []
50
49
 
@@ -65,16 +64,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
64
  required_rubygems_version: !ruby/object:Gem::Requirement
66
65
  none: false
67
66
  requirements:
68
- - - ">="
67
+ - - ">"
69
68
  - !ruby/object:Gem::Version
70
- hash: 3
69
+ hash: 25
71
70
  segments:
72
- - 0
73
- version: "0"
71
+ - 1
72
+ - 3
73
+ - 1
74
+ version: 1.3.1
74
75
  requirements: []
75
76
 
76
77
  rubyforge_project: eimxml
77
- rubygems_version: 1.3.7
78
+ rubygems_version: 1.8.5
78
79
  signing_key:
79
80
  specification_version: 3
80
81
  summary: Easy IMplemented XML