multisax 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/CHANGELOG.rdoc +8 -0
- data/Gemfile +2 -4
- data/Gemfile.lock +15 -25
- data/Rakefile +8 -27
- data/lib/multisax.rb +82 -58
- data/multisax.gemspec +20 -54
- data/spec/multisax_spec.rb +58 -25
- data/spec/spec_helper.rb +3 -3
- metadata +30 -55
- data/.document +0 -5
- data/.rspec +0 -1
- data/VERSION +0 -1
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: faccd217b395949d18f4b29ac75f185a7f1976bb
|
4
|
+
data.tar.gz: 24ecac5d9f3042ac03326efcb378886410d37edb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1e091e45e62d7c0f41015949dd97a196f37b604cc700e5a1d039a07d8e73b9e710f39c42342d3171f7f89edd150069312b6e3da021964212ffe65b0c48ff79aa
|
7
|
+
data.tar.gz: 4cbbdb6fd438fbcfb5ddf62216d5b1269798835e1f8cd0ec75e5d7902290285934ec668177c35f0fa564922bb2de19c21241e8b8ec4e45b74fd89c3225156e69
|
data/.gitignore
ADDED
data/CHANGELOG.rdoc
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
= ChangeLog
|
2
2
|
|
3
|
+
== 0.0.2 (2013 Nov 13)
|
4
|
+
- Now you can create an instance of MultiSAX::SAX.
|
5
|
+
- Please note that passed class to MultiSAX is still modified directly.
|
6
|
+
- So only MultiSAX::SAX instances are thread-safe.
|
7
|
+
- MultiSAX::Sax is now an instance of MultiSAX::SAX (this is backward-compatible).
|
8
|
+
- You can specify :nokogirihtml explicitly to parse HTML.
|
9
|
+
- Fixed attrs with Ox (now String is passed, not Symbol)
|
10
|
+
|
3
11
|
== 0.0.1 (2013 Jul 8)
|
4
12
|
- Added ChangeLog.
|
5
13
|
- Added Ruby 1.8.7 support.
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,37 +1,27 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
diff-lcs (1.2.
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
rdoc (4.0.1)
|
17
|
-
json (~> 1.4)
|
18
|
-
rspec (2.13.0)
|
19
|
-
rspec-core (~> 2.13.0)
|
20
|
-
rspec-expectations (~> 2.13.0)
|
21
|
-
rspec-mocks (~> 2.13.0)
|
22
|
-
rspec-core (2.13.1)
|
23
|
-
rspec-expectations (2.13.0)
|
4
|
+
diff-lcs (1.2.5)
|
5
|
+
libxml-ruby (2.7.0)
|
6
|
+
mini_portile (0.5.2)
|
7
|
+
nokogiri (1.6.0)
|
8
|
+
mini_portile (~> 0.5.0)
|
9
|
+
ox (2.0.11)
|
10
|
+
rspec (2.14.1)
|
11
|
+
rspec-core (~> 2.14.0)
|
12
|
+
rspec-expectations (~> 2.14.0)
|
13
|
+
rspec-mocks (~> 2.14.0)
|
14
|
+
rspec-core (2.14.7)
|
15
|
+
rspec-expectations (2.14.4)
|
24
16
|
diff-lcs (>= 1.1.3, < 2.0)
|
25
|
-
rspec-mocks (2.
|
17
|
+
rspec-mocks (2.14.4)
|
26
18
|
|
27
19
|
PLATFORMS
|
28
20
|
ruby
|
29
21
|
|
30
22
|
DEPENDENCIES
|
31
|
-
bundler
|
32
|
-
jeweler (>= 1.8.4)
|
23
|
+
bundler
|
33
24
|
libxml-ruby
|
34
25
|
nokogiri
|
35
26
|
ox
|
36
|
-
|
37
|
-
rspec (>= 2.8.0)
|
27
|
+
rspec
|
data/Rakefile
CHANGED
@@ -1,29 +1,12 @@
|
|
1
|
-
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require './lib/multisax'
|
2
3
|
|
3
|
-
|
4
|
-
require 'bundler'
|
5
|
-
begin
|
6
|
-
Bundler.setup(:default, :development)
|
7
|
-
rescue Bundler::BundlerError => e
|
8
|
-
$stderr.puts e.message
|
9
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
-
exit e.status_code
|
11
|
-
end
|
12
|
-
require 'rake'
|
4
|
+
### below are copied from jeweler ###
|
13
5
|
|
14
|
-
require '
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
gem.homepage = 'http://github.com/cielavenir/multisax'
|
19
|
-
gem.license = 'Ruby License (2-clause BSDL or Artistic)'
|
20
|
-
gem.summary = 'Ruby Gem to handle multiple SAX libraries'
|
21
|
-
gem.description = 'Ruby Gem to handle multiple SAX libraries: ox/libxml/nokogiri/rexml'
|
22
|
-
gem.email = 'cielartisan@gmail.com'
|
23
|
-
gem.authors = ['cielavenir']
|
24
|
-
# dependencies defined in Gemfile
|
25
|
-
end
|
26
|
-
Jeweler::RubygemsDotOrgTasks.new
|
6
|
+
require 'rake'
|
7
|
+
# Clean up after gem building
|
8
|
+
require 'rake/clean'
|
9
|
+
CLEAN.include('pkg/*.gem')
|
27
10
|
|
28
11
|
require 'rspec/core'
|
29
12
|
require 'rspec/core/rake_task'
|
@@ -40,10 +23,8 @@ task :default => :spec
|
|
40
23
|
|
41
24
|
require 'rdoc/task'
|
42
25
|
Rake::RDocTask.new do |rdoc|
|
43
|
-
version = File.read('VERSION').chomp
|
44
|
-
|
45
26
|
rdoc.rdoc_dir = 'rdoc'
|
46
|
-
rdoc.title =
|
27
|
+
rdoc.title = 'multisax '+MultiSAX::VERSION
|
47
28
|
rdoc.main = 'README.rdoc'
|
48
29
|
rdoc.rdoc_files.include('README.*')
|
49
30
|
rdoc.rdoc_files.include('LICENSE.*')
|
data/lib/multisax.rb
CHANGED
@@ -7,21 +7,22 @@
|
|
7
7
|
# Note: MIT License is also applicable if that compresses LICENSE file.
|
8
8
|
|
9
9
|
module MultiSAX
|
10
|
-
#VERSION
|
10
|
+
# VERSION string
|
11
|
+
VERSION='0.0.2'
|
11
12
|
|
12
13
|
# The class to handle XML libraries.
|
13
|
-
class
|
14
|
-
|
15
|
-
|
14
|
+
class SAX
|
15
|
+
@parser=nil
|
16
|
+
@saxmodule=nil
|
16
17
|
# Library loader.
|
17
18
|
# Arguments are list (or Array) of libraries.
|
18
19
|
# Currently the following are supported (order by speed):
|
19
20
|
# :ox, :libxml, :nokogiri, :rexmlstream, :rexmlsax2
|
20
21
|
# If multiple selected, MultiSAX will try the libraries one by one and use the first usable one.
|
21
|
-
|
22
|
-
|
22
|
+
# For HTML, you can specify :nokogirihtml explicitly.
|
23
|
+
def open(*list)
|
24
|
+
return @parser if @parser
|
23
25
|
list=[:ox,:libxml,:nokogiri,:rexmlstream,:rexmlsax2] if list.size==0
|
24
|
-
list=list.first if list.first.is_a?(Array)
|
25
26
|
list.each{|e_module|
|
26
27
|
case e_module
|
27
28
|
when :ox
|
@@ -30,14 +31,14 @@ module MultiSAX
|
|
30
31
|
require 'ox'
|
31
32
|
require 'stringio' #this should be standard module.
|
32
33
|
rescue LoadError;next end
|
33
|
-
|
34
|
+
@parser=e_module
|
34
35
|
methods=Ox::Sax.private_instance_methods(false)-Class.private_instance_methods(false)
|
35
36
|
if methods[0].is_a?(String) #Hack for 1.8.x
|
36
37
|
methods-=['value','attr_value']
|
37
38
|
else
|
38
39
|
methods-=[:value,:attr_value]
|
39
40
|
end
|
40
|
-
|
41
|
+
@saxmodule=Module.new{
|
41
42
|
methods.each{|e|define_method(e){|*a|}}
|
42
43
|
}
|
43
44
|
break
|
@@ -45,21 +46,21 @@ module MultiSAX
|
|
45
46
|
begin
|
46
47
|
require 'libxml'
|
47
48
|
rescue LoadError;next end
|
48
|
-
|
49
|
-
when :nokogiri
|
49
|
+
@parser=e_module;break
|
50
|
+
when :nokogiri,:nokogirihtml
|
50
51
|
#nokogiri 1.5.x are supported on Ruby 1.8.7.
|
51
52
|
#next if RUBY_VERSION<'1.9'
|
52
53
|
begin
|
53
54
|
require 'nokogiri'
|
54
55
|
rescue LoadError;next end
|
55
|
-
|
56
|
+
@parser=e_module
|
56
57
|
methods=Nokogiri::XML::SAX::Document.instance_methods(false)-Class.instance_methods(false)
|
57
58
|
if methods[0].is_a?(String) #Hack for 1.8.x
|
58
59
|
methods-=['start_element_namespace','end_element_namespace']
|
59
60
|
else
|
60
61
|
methods-=[:start_element_namespace,:end_element_namespace]
|
61
62
|
end
|
62
|
-
|
63
|
+
@saxmodule=Module.new{
|
63
64
|
methods.each{|e|define_method(e){|*a|}}
|
64
65
|
}
|
65
66
|
break
|
@@ -69,55 +70,50 @@ module MultiSAX
|
|
69
70
|
require 'rexml/parsers/streamparser'
|
70
71
|
require 'rexml/streamlistener'
|
71
72
|
rescue LoadError;next end
|
72
|
-
|
73
|
+
@parser=e_module;break
|
73
74
|
when :rexmlsax2
|
74
75
|
begin
|
75
76
|
require 'rexml/document'
|
76
77
|
require 'rexml/parsers/sax2parser'
|
77
78
|
require 'rexml/sax2listener'
|
78
79
|
rescue LoadError;next end
|
79
|
-
|
80
|
+
@parser=e_module;break
|
80
81
|
end
|
81
82
|
}
|
82
|
-
return
|
83
|
+
return @parser
|
83
84
|
end
|
84
85
|
# Reset MultiSAX state so that you can re-open() another library.
|
85
|
-
def
|
86
|
+
def reset() @parser=nil;@saxmodule=nil end
|
86
87
|
# Returns which module is actually chosen.
|
87
|
-
def
|
88
|
+
def parser() @parser end
|
88
89
|
|
89
90
|
private
|
90
91
|
#(private) Patches listener to accept library-specific APIs.
|
91
|
-
def
|
92
|
-
#raise "MultiSAX::Sax open first" if
|
93
|
-
case
|
92
|
+
def method_mapping(listener)
|
93
|
+
#raise "MultiSAX::Sax open first" if !@parser
|
94
|
+
case @parser
|
94
95
|
when :ox
|
96
|
+
saxmodule=@saxmodule
|
95
97
|
listener.instance_eval{
|
96
|
-
extend
|
98
|
+
extend saxmodule
|
97
99
|
@saxwrapper_tag=nil
|
98
|
-
@saxwrapper_attr=
|
100
|
+
@saxwrapper_attr={}
|
99
101
|
def start_element(tag)
|
100
102
|
# I hope provided Listener's sax_tag_start will NOT be used elsewhere.
|
101
103
|
#alias :attrs_done :attrs_done_normal
|
102
104
|
@saxwrapper_tag=tag
|
103
|
-
@saxwrapper_attr=
|
105
|
+
@saxwrapper_attr={}
|
104
106
|
end
|
105
107
|
# These "instance methods" are actually injected to listener class using instance_eval.
|
106
108
|
# i.e. not APIs. You cannot call these methods from outside.
|
107
109
|
def attr(name,str)
|
108
|
-
@saxwrapper_attr
|
110
|
+
@saxwrapper_attr[name.to_s]=str
|
109
111
|
end
|
110
112
|
#--
|
111
113
|
#alias :attr_value :attr
|
112
114
|
#++
|
113
115
|
def attrs_done_xmldecl
|
114
|
-
version
|
115
|
-
version&&=version[1]
|
116
|
-
encoding=@saxwrapper_attr.assoc(:encoding)
|
117
|
-
encoding&&=encoding[1]
|
118
|
-
standalone=@saxwrapper_attr.assoc(:standalone)
|
119
|
-
standalone&&=standalone[1]
|
120
|
-
sax_xmldecl(version,encoding,standalone)
|
116
|
+
sax_xmldecl(@saxwrapper_attr['version'],@saxwrapper_attr['encoding'],@saxwrapper_attr['standalone'])
|
121
117
|
end
|
122
118
|
def attrs_done_normal
|
123
119
|
sax_tag_start(@saxwrapper_tag.to_s,@saxwrapper_attr)
|
@@ -144,9 +140,10 @@ module MultiSAX
|
|
144
140
|
alias :on_comment :sax_comment
|
145
141
|
#alias :xmldecl :sax_xmldecl
|
146
142
|
}
|
147
|
-
when :nokogiri
|
143
|
+
when :nokogiri,:nokogirihtml
|
144
|
+
saxmodule=@saxmodule
|
148
145
|
listener.instance_eval{
|
149
|
-
extend
|
146
|
+
extend saxmodule
|
150
147
|
alias :start_element_namespace :sax_start_element_namespace
|
151
148
|
alias :start_element :sax_tag_start
|
152
149
|
alias :end_element_namespace :sax_end_element_namespace
|
@@ -187,37 +184,39 @@ module MultiSAX
|
|
187
184
|
# From 0.0.1, source can be IO as well as String.
|
188
185
|
# SAX's listeners are usually modified destructively.
|
189
186
|
# So instances shouldn't be provided.
|
190
|
-
def
|
191
|
-
|
192
|
-
raise "Failed to open SAX library. REXML, which is a standard Ruby module, might be also corrupted." if
|
187
|
+
def parse(source,listener)
|
188
|
+
open if !@parser
|
189
|
+
raise "Failed to open SAX library. REXML, which is a standard Ruby module, might be also corrupted." if !@parser
|
193
190
|
@listener=listener
|
194
|
-
|
191
|
+
method_mapping(@listener)
|
195
192
|
if source.is_a?(String)
|
196
|
-
case
|
197
|
-
when :ox
|
198
|
-
when :libxml
|
199
|
-
when :nokogiri
|
200
|
-
when :
|
201
|
-
when :
|
193
|
+
case @parser
|
194
|
+
when :ox then Ox.sax_parse(@listener,StringIO.new(source),:convert_special=>true)
|
195
|
+
when :libxml then parser=LibXML::XML::SaxParser.string(source);parser.callbacks=@listener;parser.parse
|
196
|
+
when :nokogiri then parser=Nokogiri::XML::SAX::Parser.new(@listener);parser.parse(source)
|
197
|
+
when :nokogirihtml then parser=Nokogiri::HTML::SAX::Parser.new(@listener);parser.parse(source)
|
198
|
+
when :rexmlstream then REXML::Parsers::StreamParser.new(source,@listener).parse
|
199
|
+
when :rexmlsax2 then parser=REXML::Parsers::SAX2Parser.new(source);parser.listen(@listener);parser.parse
|
202
200
|
end
|
203
201
|
else
|
204
|
-
case
|
205
|
-
when :ox
|
206
|
-
when :libxml
|
207
|
-
when :nokogiri
|
208
|
-
when :
|
209
|
-
when :
|
202
|
+
case @parser
|
203
|
+
when :ox then Ox.sax_parse(@listener,source,:convert_special=>true)
|
204
|
+
when :libxml then parser=LibXML::XML::SaxParser.io(source);parser.callbacks=@listener;parser.parse
|
205
|
+
when :nokogiri then parser=Nokogiri::XML::SAX::Parser.new(@listener);parser.parse(source)
|
206
|
+
when :nokogirihtml then parser=Nokogiri::HTML::SAX::Parser.new(@listener);parser.parse(source)
|
207
|
+
when :rexmlstream then REXML::Parsers::StreamParser.new(source,@listener).parse
|
208
|
+
when :rexmlsax2 then parser=REXML::Parsers::SAX2Parser.new(source);parser.listen(@listener);parser.parse
|
210
209
|
end
|
211
210
|
end
|
212
211
|
@listener
|
213
212
|
end
|
214
213
|
|
215
214
|
# Parses file as XML. Error handling might be changed in the future.
|
216
|
-
def
|
215
|
+
def parsefile(filename,listener)
|
217
216
|
#begin
|
218
217
|
return nil unless FileTest::readable?(filename)
|
219
218
|
File.open(filename,'rb'){|f|
|
220
|
-
|
219
|
+
parse(f,listener)
|
221
220
|
}
|
222
221
|
#rescue
|
223
222
|
# return nil
|
@@ -226,30 +225,55 @@ module MultiSAX
|
|
226
225
|
end
|
227
226
|
end
|
228
227
|
|
228
|
+
# This class provides singleton interface to MultiSAX::SAX.
|
229
|
+
class Sax
|
230
|
+
@@multisax_singleton=SAX.new
|
231
|
+
# MultiSAX::SAX#open
|
232
|
+
def self.open(*list) @@multisax_singleton.open(*list) end
|
233
|
+
# MultiSAX::SAX#reset
|
234
|
+
def self.reset() @@multisax_singleton.reset() end
|
235
|
+
# MultiSAX::SAX#parser
|
236
|
+
def self.parser() @@multisax_singleton.parser() end
|
237
|
+
# MultiSAX::SAX#parse
|
238
|
+
def self.parse(source,listener) @@multisax_singleton.parse(source,listener) end
|
239
|
+
# MultiSAX::SAX#parsefile
|
240
|
+
def self.parsefile(filename,listener) @@multisax_singleton.parsefile(filename,listener) end
|
241
|
+
end
|
242
|
+
|
229
243
|
# MultiSAX callbacks.
|
230
|
-
# MultiSAX::
|
244
|
+
# MultiSAX::SAX listener should include this module.
|
231
245
|
module Callbacks
|
232
246
|
# Cited from Nokogiri to convert Nokogiri::XML::SAX::Document into module.
|
233
247
|
# https://github.com/sparklemotion/nokogiri/blob/master/lib/nokogiri/xml/sax/document.rb
|
234
248
|
def sax_start_element_namespace name, attrs = [], prefix = nil, uri = nil, ns = []
|
235
249
|
# Deal with SAX v1 interface
|
236
250
|
name = [prefix, name].compact.join(':')
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
[[
|
251
|
+
# modified in 0.0.2
|
252
|
+
attributes = {}
|
253
|
+
ns.each{|ns_prefix,ns_uri|
|
254
|
+
attributes[['xmlns', ns_prefix].compact.join(':')]=ns_uri
|
255
|
+
}
|
256
|
+
attrs.each{|attr|
|
257
|
+
attributes[[attr.prefix, attr.localname].compact.join(':')]=attr.value
|
241
258
|
}
|
242
259
|
sax_tag_start name, attributes
|
243
260
|
end
|
261
|
+
# Cited from Nokogiri
|
244
262
|
def sax_end_element_namespace name, prefix = nil, uri = nil
|
245
263
|
# Deal with SAX v1 interface
|
246
264
|
sax_tag_end [prefix, name].compact.join(':')
|
247
265
|
end
|
248
|
-
|
266
|
+
# Start of tag
|
267
|
+
def sax_tag_start(tag,attrs) end
|
268
|
+
# End of tag
|
249
269
|
def sax_tag_end(tag) end
|
270
|
+
# Comment
|
250
271
|
def sax_comment(text) end
|
272
|
+
# CDATA
|
251
273
|
def sax_cdata(text) end
|
274
|
+
# Text
|
252
275
|
def sax_text(text) end
|
276
|
+
# XML declaration (not available if parser is :libxml)
|
253
277
|
def sax_xmldecl(version,encoding,standalone) end
|
254
278
|
end
|
255
279
|
end
|
data/multisax.gemspec
CHANGED
@@ -1,61 +1,27 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# coding: utf-8
|
2
|
+
require './lib/multisax'
|
5
3
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "multisax"
|
6
|
+
spec.version = MultiSAX::VERSION
|
7
|
+
spec.authors = ["cielavenir"]
|
8
|
+
spec.email = ["cielartisan@gmail.com"]
|
9
|
+
spec.description = "Ruby Gem to handle multiple SAX libraries: ox/libxml/nokogiri/rexml"
|
10
|
+
spec.summary = "Ruby Gem to handle multiple SAX libraries"
|
11
|
+
spec.homepage = "http://github.com/cielavenir/multisax"
|
12
|
+
spec.license = "Ruby License (2-clause BSDL or Artistic)"
|
9
13
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
s.email = "cielartisan@gmail.com"
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE.txt",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
21
|
-
".rspec",
|
22
|
-
"CHANGELOG.rdoc",
|
23
|
-
"Gemfile",
|
24
|
-
"Gemfile.lock",
|
14
|
+
spec.files = `git ls-files`.split($/)
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.extra_rdoc_files = [
|
25
18
|
"LICENSE.txt",
|
26
19
|
"README.rdoc",
|
27
|
-
|
28
|
-
"VERSION",
|
29
|
-
"lib/multisax.rb",
|
30
|
-
"multisax.gemspec",
|
31
|
-
"spec/multisax_spec.rb",
|
32
|
-
"spec/spec_helper.rb"
|
20
|
+
"CHANGELOG.rdoc",
|
33
21
|
]
|
34
|
-
|
35
|
-
s.licenses = ["Ruby License (2-clause BSDL or Artistic)"]
|
36
|
-
s.require_paths = ["lib"]
|
37
|
-
s.rubygems_version = "1.8.25"
|
38
|
-
s.summary = "Ruby Gem to handle multiple SAX libraries"
|
22
|
+
spec.require_paths = ["lib"]
|
39
23
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
44
|
-
s.add_development_dependency(%q<rspec>, [">= 2.8.0"])
|
45
|
-
s.add_development_dependency(%q<rdoc>, [">= 3.12"])
|
46
|
-
s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
|
47
|
-
s.add_development_dependency(%q<jeweler>, [">= 1.8.4"])
|
48
|
-
else
|
49
|
-
s.add_dependency(%q<rspec>, [">= 2.8.0"])
|
50
|
-
s.add_dependency(%q<rdoc>, [">= 3.12"])
|
51
|
-
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
52
|
-
s.add_dependency(%q<jeweler>, [">= 1.8.4"])
|
53
|
-
end
|
54
|
-
else
|
55
|
-
s.add_dependency(%q<rspec>, [">= 2.8.0"])
|
56
|
-
s.add_dependency(%q<rdoc>, [">= 3.12"])
|
57
|
-
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
58
|
-
s.add_dependency(%q<jeweler>, [">= 1.8.4"])
|
59
|
-
end
|
24
|
+
spec.add_development_dependency "bundler"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rspec"
|
60
27
|
end
|
61
|
-
|
data/spec/multisax_spec.rb
CHANGED
@@ -4,9 +4,11 @@ class MultiSAXTester
|
|
4
4
|
include MultiSAX::Callbacks
|
5
5
|
def initialize
|
6
6
|
@result=[]
|
7
|
+
@attrib=nil
|
7
8
|
end
|
8
9
|
def sax_tag_start(tag,attrs)
|
9
10
|
@result<<tag
|
11
|
+
@attrib=attrs['foo'] if tag=='sax'
|
10
12
|
end
|
11
13
|
def sax_tag_end(tag)
|
12
14
|
@result<<tag
|
@@ -15,13 +17,14 @@ class MultiSAXTester
|
|
15
17
|
text.strip!
|
16
18
|
@result<<text if text.size>0
|
17
19
|
end
|
18
|
-
|
19
|
-
|
20
|
-
|
20
|
+
def sax_xmldecl(version,encoding,standalone)
|
21
|
+
@xmlencoding=encoding
|
22
|
+
end
|
23
|
+
attr_reader :result,:attrib,:xmlencoding
|
21
24
|
end
|
22
25
|
input_xml=<<"EOM"
|
23
|
-
<?xml version="1.0" encoding="
|
24
|
-
<hello><sax>world</sax></hello>
|
26
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
27
|
+
<hello><sax foo="bar">world</sax></hello>
|
25
28
|
EOM
|
26
29
|
answer=['hello','sax','world','sax','hello']
|
27
30
|
|
@@ -30,67 +33,97 @@ describe "MultiSAX::Sax.parse (String)" do
|
|
30
33
|
MultiSAX::Sax.reset
|
31
34
|
MultiSAX::Sax.open(:unknown).should be_false
|
32
35
|
end
|
33
|
-
it ":rexmlstream" do
|
36
|
+
it "uses :rexmlstream" do
|
34
37
|
MultiSAX::Sax.reset
|
35
38
|
MultiSAX::Sax.open(:rexmlstream)
|
36
39
|
MultiSAX::Sax.parser.should eq :rexmlstream
|
37
|
-
MultiSAX::Sax.parse(input_xml,MultiSAXTester.new)
|
40
|
+
listener=MultiSAX::Sax.parse(input_xml,MultiSAXTester.new)
|
41
|
+
listener.result.should eq answer
|
42
|
+
listener.attrib.should eq 'bar'
|
43
|
+
listener.xmlencoding.should eq 'UTF-8'
|
38
44
|
end
|
39
|
-
it ":rexmlsax2" do
|
45
|
+
it "uses :rexmlsax2" do
|
40
46
|
MultiSAX::Sax.reset
|
41
47
|
MultiSAX::Sax.open(:rexmlsax2)
|
42
48
|
MultiSAX::Sax.parser.should eq :rexmlsax2
|
43
|
-
MultiSAX::Sax.parse(input_xml,MultiSAXTester.new)
|
49
|
+
listener=MultiSAX::Sax.parse(input_xml,MultiSAXTester.new)
|
50
|
+
listener.result.should eq answer
|
51
|
+
listener.attrib.should eq 'bar'
|
52
|
+
listener.xmlencoding.should eq 'UTF-8'
|
44
53
|
end
|
45
|
-
it ":ox" do
|
54
|
+
it "uses :ox" do
|
46
55
|
MultiSAX::Sax.reset
|
47
56
|
MultiSAX::Sax.open(:ox)
|
48
57
|
MultiSAX::Sax.parser.should eq :ox
|
49
|
-
MultiSAX::Sax.parse(input_xml,MultiSAXTester.new)
|
58
|
+
listener=MultiSAX::Sax.parse(input_xml,MultiSAXTester.new)
|
59
|
+
listener.result.should eq answer
|
60
|
+
listener.attrib.should eq 'bar'
|
61
|
+
listener.xmlencoding.should eq 'UTF-8'
|
50
62
|
end
|
51
|
-
it ":libxml" do
|
63
|
+
it "uses :libxml" do
|
52
64
|
MultiSAX::Sax.reset
|
53
65
|
MultiSAX::Sax.open(:libxml)
|
54
66
|
MultiSAX::Sax.parser.should eq :libxml
|
55
|
-
MultiSAX::Sax.parse(input_xml,MultiSAXTester.new)
|
67
|
+
listener=MultiSAX::Sax.parse(input_xml,MultiSAXTester.new)
|
68
|
+
listener.result.should eq answer
|
69
|
+
listener.attrib.should eq 'bar'
|
70
|
+
#listener.xmlencoding.should eq 'UTF-8'
|
56
71
|
end
|
57
|
-
it ":nokogiri" do
|
72
|
+
it "uses :nokogiri" do
|
58
73
|
MultiSAX::Sax.reset
|
59
74
|
MultiSAX::Sax.open(:nokogiri)
|
60
75
|
MultiSAX::Sax.parser.should eq :nokogiri
|
61
|
-
MultiSAX::Sax.parse(input_xml,MultiSAXTester.new)
|
76
|
+
listener=MultiSAX::Sax.parse(input_xml,MultiSAXTester.new)
|
77
|
+
listener.result.should eq answer
|
78
|
+
listener.attrib.should eq 'bar'
|
79
|
+
listener.xmlencoding.should eq 'UTF-8'
|
62
80
|
end
|
63
81
|
end
|
64
82
|
|
65
83
|
describe "MultiSAX::Sax.parse (IO)" do
|
66
|
-
it ":rexmlstream" do
|
84
|
+
it "uses :rexmlstream" do
|
67
85
|
MultiSAX::Sax.reset
|
68
86
|
MultiSAX::Sax.open(:rexmlstream)
|
69
87
|
MultiSAX::Sax.parser.should eq :rexmlstream
|
70
|
-
MultiSAX::Sax.parse(StringIO.new(input_xml),MultiSAXTester.new)
|
88
|
+
listener=MultiSAX::Sax.parse(StringIO.new(input_xml),MultiSAXTester.new)
|
89
|
+
listener.result.should eq answer
|
90
|
+
listener.attrib.should eq 'bar'
|
91
|
+
listener.xmlencoding.should eq 'UTF-8'
|
71
92
|
end
|
72
|
-
it ":rexmlsax2" do
|
93
|
+
it "uses :rexmlsax2" do
|
73
94
|
MultiSAX::Sax.reset
|
74
95
|
MultiSAX::Sax.open(:rexmlsax2)
|
75
96
|
MultiSAX::Sax.parser.should eq :rexmlsax2
|
76
|
-
MultiSAX::Sax.parse(StringIO.new(input_xml),MultiSAXTester.new)
|
97
|
+
listener=MultiSAX::Sax.parse(StringIO.new(input_xml),MultiSAXTester.new)
|
98
|
+
listener.result.should eq answer
|
99
|
+
listener.attrib.should eq 'bar'
|
100
|
+
listener.xmlencoding.should eq 'UTF-8'
|
77
101
|
end
|
78
|
-
it ":ox" do
|
102
|
+
it "uses :ox" do
|
79
103
|
MultiSAX::Sax.reset
|
80
104
|
MultiSAX::Sax.open(:ox)
|
81
105
|
MultiSAX::Sax.parser.should eq :ox
|
82
|
-
MultiSAX::Sax.parse(StringIO.new(input_xml),MultiSAXTester.new)
|
106
|
+
listener=MultiSAX::Sax.parse(StringIO.new(input_xml),MultiSAXTester.new)
|
107
|
+
listener.result.should eq answer
|
108
|
+
listener.attrib.should eq 'bar'
|
109
|
+
listener.xmlencoding.should eq 'UTF-8'
|
83
110
|
end
|
84
|
-
it ":libxml" do
|
111
|
+
it "uses :libxml" do
|
85
112
|
MultiSAX::Sax.reset
|
86
113
|
MultiSAX::Sax.open(:libxml)
|
87
114
|
MultiSAX::Sax.parser.should eq :libxml
|
88
|
-
MultiSAX::Sax.parse(StringIO.new(input_xml),MultiSAXTester.new)
|
115
|
+
listener=MultiSAX::Sax.parse(StringIO.new(input_xml),MultiSAXTester.new)
|
116
|
+
listener.result.should eq answer
|
117
|
+
listener.attrib.should eq 'bar'
|
118
|
+
#listener.xmlencoding.should eq 'UTF-8'
|
89
119
|
end
|
90
|
-
it ":nokogiri" do
|
120
|
+
it "uses :nokogiri" do
|
91
121
|
MultiSAX::Sax.reset
|
92
122
|
MultiSAX::Sax.open(:nokogiri)
|
93
123
|
MultiSAX::Sax.parser.should eq :nokogiri
|
94
|
-
MultiSAX::Sax.parse(StringIO.new(input_xml),MultiSAXTester.new)
|
124
|
+
listener=MultiSAX::Sax.parse(StringIO.new(input_xml),MultiSAXTester.new)
|
125
|
+
listener.result.should eq answer
|
126
|
+
listener.attrib.should eq 'bar'
|
127
|
+
listener.xmlencoding.should eq 'UTF-8'
|
95
128
|
end
|
96
129
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,97 +1,74 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multisax
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- cielavenir
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-11-13 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ! '>='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: 2.8.0
|
22
|
-
type: :development
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ! '>='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 2.8.0
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: rdoc
|
14
|
+
name: bundler
|
32
15
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
16
|
requirements:
|
35
|
-
- -
|
17
|
+
- - '>='
|
36
18
|
- !ruby/object:Gem::Version
|
37
|
-
version: '
|
19
|
+
version: '0'
|
38
20
|
type: :development
|
39
21
|
prerelease: false
|
40
22
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
23
|
requirements:
|
43
|
-
- -
|
24
|
+
- - '>='
|
44
25
|
- !ruby/object:Gem::Version
|
45
|
-
version: '
|
26
|
+
version: '0'
|
46
27
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
28
|
+
name: rake
|
48
29
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
30
|
requirements:
|
51
|
-
- -
|
31
|
+
- - '>='
|
52
32
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
33
|
+
version: '0'
|
54
34
|
type: :development
|
55
35
|
prerelease: false
|
56
36
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
37
|
requirements:
|
59
|
-
- -
|
38
|
+
- - '>='
|
60
39
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
40
|
+
version: '0'
|
62
41
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
42
|
+
name: rspec
|
64
43
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
44
|
requirements:
|
67
|
-
- -
|
45
|
+
- - '>='
|
68
46
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
47
|
+
version: '0'
|
70
48
|
type: :development
|
71
49
|
prerelease: false
|
72
50
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
51
|
requirements:
|
75
|
-
- -
|
52
|
+
- - '>='
|
76
53
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
78
|
-
description:
|
79
|
-
email:
|
54
|
+
version: '0'
|
55
|
+
description: 'Ruby Gem to handle multiple SAX libraries: ox/libxml/nokogiri/rexml'
|
56
|
+
email:
|
57
|
+
- cielartisan@gmail.com
|
80
58
|
executables: []
|
81
59
|
extensions: []
|
82
60
|
extra_rdoc_files:
|
83
61
|
- LICENSE.txt
|
84
62
|
- README.rdoc
|
63
|
+
- CHANGELOG.rdoc
|
85
64
|
files:
|
86
|
-
- .
|
87
|
-
- .rspec
|
65
|
+
- .gitignore
|
88
66
|
- CHANGELOG.rdoc
|
89
67
|
- Gemfile
|
90
68
|
- Gemfile.lock
|
91
69
|
- LICENSE.txt
|
92
70
|
- README.rdoc
|
93
71
|
- Rakefile
|
94
|
-
- VERSION
|
95
72
|
- lib/multisax.rb
|
96
73
|
- multisax.gemspec
|
97
74
|
- spec/multisax_spec.rb
|
@@ -99,29 +76,27 @@ files:
|
|
99
76
|
homepage: http://github.com/cielavenir/multisax
|
100
77
|
licenses:
|
101
78
|
- Ruby License (2-clause BSDL or Artistic)
|
79
|
+
metadata: {}
|
102
80
|
post_install_message:
|
103
81
|
rdoc_options: []
|
104
82
|
require_paths:
|
105
83
|
- lib
|
106
84
|
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
-
none: false
|
108
85
|
requirements:
|
109
|
-
- -
|
86
|
+
- - '>='
|
110
87
|
- !ruby/object:Gem::Version
|
111
88
|
version: '0'
|
112
|
-
segments:
|
113
|
-
- 0
|
114
|
-
hash: 3842720625323194338
|
115
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
-
none: false
|
117
90
|
requirements:
|
118
|
-
- -
|
91
|
+
- - '>='
|
119
92
|
- !ruby/object:Gem::Version
|
120
93
|
version: '0'
|
121
94
|
requirements: []
|
122
95
|
rubyforge_project:
|
123
|
-
rubygems_version:
|
96
|
+
rubygems_version: 2.0.3
|
124
97
|
signing_key:
|
125
|
-
specification_version:
|
98
|
+
specification_version: 4
|
126
99
|
summary: Ruby Gem to handle multiple SAX libraries
|
127
|
-
test_files:
|
100
|
+
test_files:
|
101
|
+
- spec/multisax_spec.rb
|
102
|
+
- spec/spec_helper.rb
|
data/.document
DELETED
data/.rspec
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.0.1
|