multisax 0.0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +40 -0
- data/LICENSE.txt +40 -0
- data/README.rdoc +19 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/lib/multisax.rb +187 -0
- data/multisax.gemspec +72 -0
- data/spec/multisax_spec.rb +52 -0
- data/spec/spec_helper.rb +12 -0
- metadata +169 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4fb0d3fd03da64d11c56b3dfe51a240f6a5720f1
|
4
|
+
data.tar.gz: 95c0c0d1227491f78ed8f1ca9c74e858d61fc95d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 97e5f3dfc333da5a5b06444c76be6d59206beeae2fc04f5bfdc8fed6bb29d7f90125916e707b2bfc2e10587685aec49de7a3c41c6833e234ffa2359a7c6aaea7
|
7
|
+
data.tar.gz: 30f6f2b3fa30931aef06c58d3ccdd884b5219389bf35102c214872b3bfbdbb42ee899b52b7027e845f43a0e8896271885f4e289f4b35ce19c3a3790757038125
|
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem 'rake'
|
4
|
+
gem 'libxml-ruby', :require=>nil
|
5
|
+
gem 'nokogiri', :require=>nil
|
6
|
+
gem 'ox', :require=>nil
|
7
|
+
|
8
|
+
# Add dependencies to develop your gem here.
|
9
|
+
# Include everything needed to run rake, tests, features, etc.
|
10
|
+
group :development do
|
11
|
+
gem "rspec", ">= 2.8.0"
|
12
|
+
gem "rdoc", ">= 3.12"
|
13
|
+
gem "bundler", ">= 1.0.0"
|
14
|
+
gem "jeweler", ">= 1.8.4"
|
15
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.2.4)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.8.4)
|
7
|
+
bundler (~> 1.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
rdoc
|
11
|
+
json (1.8.0)
|
12
|
+
libxml-ruby (2.6.0)
|
13
|
+
mini_portile (0.5.0)
|
14
|
+
nokogiri (1.6.0)
|
15
|
+
mini_portile (~> 0.5.0)
|
16
|
+
ox (2.0.3)
|
17
|
+
rake (10.0.4)
|
18
|
+
rdoc (4.0.1)
|
19
|
+
json (~> 1.4)
|
20
|
+
rspec (2.13.0)
|
21
|
+
rspec-core (~> 2.13.0)
|
22
|
+
rspec-expectations (~> 2.13.0)
|
23
|
+
rspec-mocks (~> 2.13.0)
|
24
|
+
rspec-core (2.13.1)
|
25
|
+
rspec-expectations (2.13.0)
|
26
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
27
|
+
rspec-mocks (2.13.1)
|
28
|
+
|
29
|
+
PLATFORMS
|
30
|
+
ruby
|
31
|
+
|
32
|
+
DEPENDENCIES
|
33
|
+
bundler (>= 1.0.0)
|
34
|
+
jeweler (>= 1.8.4)
|
35
|
+
libxml-ruby
|
36
|
+
nokogiri
|
37
|
+
ox
|
38
|
+
rake
|
39
|
+
rdoc (>= 3.12)
|
40
|
+
rspec (>= 2.8.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
Copyright (c) 2013, cielavenir
|
2
|
+
|
3
|
+
All rights reserved.
|
4
|
+
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
7
|
+
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
9
|
+
list of conditions and the following disclaimer.
|
10
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
this list of conditions and the following disclaimer in the documentation
|
12
|
+
and/or other materials provided with the distribution.
|
13
|
+
|
14
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
15
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
16
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
17
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
18
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
19
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
20
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
21
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
22
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
23
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
24
|
+
|
25
|
+
A part of Nokogiri source code is cited to convert Nokogiri::XML::SAX::Document into module.
|
26
|
+
|
27
|
+
Copyright © 2008 - 2012: Aaron Patterson, Mike Dalessio, Charles Nutter, Sergio Arbeo, Patrick Mahoney, Yoko Harada
|
28
|
+
|
29
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
30
|
+
|
31
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
32
|
+
|
33
|
+
THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
34
|
+
|
35
|
+
Note: MultiSAX shouldn't load any copyleft libraries.
|
36
|
+
|
37
|
+
Ruby (REXML): 2-clause BSD License (or Artistic License)
|
38
|
+
Nokogiri: MIT License
|
39
|
+
libxml-ruby: MIT License
|
40
|
+
Ox: 3-clause BSD License
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= multisax
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to multisax
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2013 cielavenir. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
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'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = 'multisax'
|
18
|
+
gem.homepage = 'http://github.com/cielavenir/multisax'
|
19
|
+
gem.license = '2-clause BSDL'
|
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
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
require 'multisax'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
version = MultiSAX::VERSION
|
45
|
+
|
46
|
+
rdoc.rdoc_dir = 'rdoc'
|
47
|
+
rdoc.title = "multisax #{version}"
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0.1
|
data/lib/multisax.rb
ADDED
@@ -0,0 +1,187 @@
|
|
1
|
+
#MultiSAX: Ruby Gem to handle multiple SAX libraries
|
2
|
+
#Copyright (c) 2013, T. Yamada All rights reserved under 2-clause BSDL.
|
3
|
+
#Check LICENSE terms.
|
4
|
+
#Note: MIT License is also applicable if that compresses LICENSE file.
|
5
|
+
|
6
|
+
module MultiSAX
|
7
|
+
VERSION='0.0.0.1'
|
8
|
+
|
9
|
+
class Sax
|
10
|
+
@@parser=nil
|
11
|
+
@@saxmodule=nil
|
12
|
+
def self.open(*list)
|
13
|
+
return @@parser if @@parser
|
14
|
+
list=[:ox,:libxml,:nokogiri,:rexmlstream,:rexmlsax2] if list.size==0
|
15
|
+
list=list.first if list.first.is_a?(Array)
|
16
|
+
list.each{|e_module|
|
17
|
+
case e_module
|
18
|
+
when :ox
|
19
|
+
begin
|
20
|
+
require 'ox'
|
21
|
+
require 'stringio' #this should be official module.
|
22
|
+
rescue LoadError;next end
|
23
|
+
@@parser=e_module
|
24
|
+
methods=Ox::Sax.private_instance_methods(false)-Class.private_instance_methods(false)
|
25
|
+
methods-=[:value,:attr_value]
|
26
|
+
@@saxmodule=Module.new{
|
27
|
+
methods.each{|e|define_method(e){|*a|}}
|
28
|
+
}
|
29
|
+
break
|
30
|
+
when :libxml
|
31
|
+
begin
|
32
|
+
require 'libxml'
|
33
|
+
rescue LoadError;next end
|
34
|
+
@@parser=e_module;break
|
35
|
+
when :nokogiri
|
36
|
+
begin
|
37
|
+
require 'nokogiri'
|
38
|
+
rescue LoadError;next end
|
39
|
+
@@parser=e_module
|
40
|
+
methods=Nokogiri::XML::SAX::Document.instance_methods(false)-Class.instance_methods(false)
|
41
|
+
methods-=[:start_element_namespace,:end_element_namespace]
|
42
|
+
@@saxmodule=Module.new{
|
43
|
+
methods.each{|e|define_method(e){|*a|}}
|
44
|
+
}
|
45
|
+
break
|
46
|
+
when :rexmlstream
|
47
|
+
begin
|
48
|
+
require 'rexml/document'
|
49
|
+
require 'rexml/parsers/streamparser'
|
50
|
+
require 'rexml/streamlistener'
|
51
|
+
rescue LoadError;next end
|
52
|
+
@@parser=e_module;break
|
53
|
+
when :rexmlsax2
|
54
|
+
begin
|
55
|
+
require 'rexml/document'
|
56
|
+
require 'rexml/parsers/sax2parser'
|
57
|
+
require 'rexml/sax2listener'
|
58
|
+
rescue LoadError;next end
|
59
|
+
@@parser=e_module;break
|
60
|
+
end
|
61
|
+
}
|
62
|
+
return @@parser
|
63
|
+
end
|
64
|
+
def self.reset() @@parser=nil;@@saxmodule=nil end
|
65
|
+
|
66
|
+
#def initialize(listener)
|
67
|
+
def self.parse(body,listener)
|
68
|
+
#self.class.open if !@@parser
|
69
|
+
self.open if !@@parser
|
70
|
+
raise "Failed to open SAX library. REXML, which is official Ruby module, might be also corrupted." if !@@parser
|
71
|
+
@listener=listener
|
72
|
+
|
73
|
+
#Here comes method mapping.
|
74
|
+
case @@parser
|
75
|
+
when :ox
|
76
|
+
@listener.instance_eval{
|
77
|
+
extend @@saxmodule
|
78
|
+
@saxwrapper_attr=[:xmldecl]
|
79
|
+
def start_element(tag)
|
80
|
+
@saxwrapper_tag=tag
|
81
|
+
@saxwrapper_attr=[]
|
82
|
+
end
|
83
|
+
def attr(name,str)
|
84
|
+
@saxwrapper_attr<<[name,str]
|
85
|
+
end
|
86
|
+
#alias :attr_value :attr
|
87
|
+
def attrs_done
|
88
|
+
if @saxwrapper_attr.first==:xmldecl
|
89
|
+
@saxwrapper_attr.shift
|
90
|
+
version=@saxwrapper_attr.assoc(:version)
|
91
|
+
version&&=version[1]
|
92
|
+
encoding=@saxwrapper_attr.assoc(:encoding)
|
93
|
+
encoding&&=encoding[1]
|
94
|
+
standalone=@saxwrapper_attr.assoc(:standalone)
|
95
|
+
standalone&&=standalone[1]
|
96
|
+
sax_xmldecl(version,encoding,standalone)
|
97
|
+
else
|
98
|
+
sax_tag_start(@saxwrapper_tag.to_s,@saxwrapper_attr)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
def end_element(tag) sax_tag_end(tag.to_s) end
|
102
|
+
alias :cdata :sax_cdata
|
103
|
+
alias :text :sax_text
|
104
|
+
#alias :value :sax_text
|
105
|
+
alias :comment :sax_comment
|
106
|
+
}
|
107
|
+
when :libxml
|
108
|
+
@listener.instance_eval{
|
109
|
+
extend LibXML::XML::SaxParser::Callbacks
|
110
|
+
alias :on_start_element :sax_tag_start
|
111
|
+
alias :on_end_element :sax_tag_end
|
112
|
+
alias :on_cdata_block :sax_cdata
|
113
|
+
alias :on_characters :sax_text
|
114
|
+
alias :on_comment :sax_comment
|
115
|
+
#alias :xmldecl :sax_xmldecl
|
116
|
+
}
|
117
|
+
when :nokogiri
|
118
|
+
@listener.instance_eval{
|
119
|
+
extend @@saxmodule
|
120
|
+
alias :start_element_namespace :sax_start_element_namespace
|
121
|
+
alias :start_element :sax_tag_start
|
122
|
+
alias :end_element_namespace :sax_end_element_namespace
|
123
|
+
alias :end_element :sax_tag_end
|
124
|
+
alias :cdata_block :sax_cdata
|
125
|
+
alias :characters :sax_text
|
126
|
+
alias :comment :sax_comment
|
127
|
+
alias :xmldecl :sax_xmldecl
|
128
|
+
}
|
129
|
+
when :rexmlstream
|
130
|
+
@listener.instance_eval{
|
131
|
+
extend REXML::StreamListener
|
132
|
+
alias :tag_start :sax_tag_start
|
133
|
+
alias :tag_end :sax_tag_end
|
134
|
+
alias :cdata :sax_cdata
|
135
|
+
alias :text :sax_text
|
136
|
+
alias :comment :sax_comment
|
137
|
+
alias :xmldecl :sax_xmldecl
|
138
|
+
}
|
139
|
+
when :rexmlsax2
|
140
|
+
@listener.instance_eval{
|
141
|
+
extend REXML::SAX2Listener
|
142
|
+
def start_element(uri,tag,qname,attrs) sax_tag_start(tag,attrs) end
|
143
|
+
def end_element(uri,tag,qname) sax_tag_end(tag) end
|
144
|
+
alias :cdata :sax_cdata
|
145
|
+
alias :characters :sax_text
|
146
|
+
alias :comment :sax_comment
|
147
|
+
alias :xmldecl :sax_xmldecl
|
148
|
+
}
|
149
|
+
end
|
150
|
+
#end
|
151
|
+
#def parse(body)
|
152
|
+
#Here comes parsing mapping.
|
153
|
+
case @@parser
|
154
|
+
when :ox then Ox.sax_parse(@listener,StringIO.new(body),:convert_special=>true)
|
155
|
+
when :libxml then parser=LibXML::XML::SaxParser.string(body);parser.callbacks=@listener;parser.parse
|
156
|
+
when :nokogiri then parser=Nokogiri::XML::SAX::Parser.new(@listener);parser.parse(body)
|
157
|
+
when :rexmlstream then REXML::Parsers::StreamParser.new(body,@listener).parse
|
158
|
+
when :rexmlsax2 then parser=REXML::Parsers::SAX2Parser.new(body);parser.listen(@listener);parser.parse
|
159
|
+
end
|
160
|
+
@listener
|
161
|
+
end
|
162
|
+
attr_reader :parser
|
163
|
+
end
|
164
|
+
module Callbacks
|
165
|
+
# https://github.com/sparklemotion/nokogiri/blob/master/lib/nokogiri/xml/sax/document.rb
|
166
|
+
def sax_start_element_namespace name, attrs = [], prefix = nil, uri = nil, ns = []
|
167
|
+
# Deal with SAX v1 interface
|
168
|
+
name = [prefix, name].compact.join(':')
|
169
|
+
attributes = ns.map { |ns_prefix,ns_uri|
|
170
|
+
[['xmlns', ns_prefix].compact.join(':'), ns_uri]
|
171
|
+
} + attrs.map { |attr|
|
172
|
+
[[attr.prefix, attr.localname].compact.join(':'), attr.value]
|
173
|
+
}
|
174
|
+
sax_tag_start name, attributes
|
175
|
+
end
|
176
|
+
def sax_end_element_namespace name, prefix = nil, uri = nil
|
177
|
+
# Deal with SAX v1 interface
|
178
|
+
sax_tag_end [prefix, name].compact.join(':')
|
179
|
+
end
|
180
|
+
def sax_tag_start(tag,attr) end
|
181
|
+
def sax_tag_end(tag) end
|
182
|
+
def sax_comment(text) end
|
183
|
+
def sax_cdata(text) end
|
184
|
+
def sax_text(text) end
|
185
|
+
def sax_xmldecl(version,encoding,standalone) end
|
186
|
+
end
|
187
|
+
end
|
data/multisax.gemspec
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "multisax"
|
8
|
+
s.version = "0.0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["cielavenir"]
|
12
|
+
s.date = "2013-06-14"
|
13
|
+
s.description = "Ruby Gem to handle multiple SAX libraries: ox/libxml/nokogiri/rexml"
|
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
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"lib/multisax.rb",
|
29
|
+
"multisax.gemspec",
|
30
|
+
"spec/multisax_spec.rb",
|
31
|
+
"spec/spec_helper.rb"
|
32
|
+
]
|
33
|
+
s.homepage = "http://github.com/cielavenir/multisax"
|
34
|
+
s.licenses = ["2-clause BSDL"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubygems_version = "2.0.0"
|
37
|
+
s.summary = "Ruby Gem to handle multiple SAX libraries"
|
38
|
+
|
39
|
+
if s.respond_to? :specification_version then
|
40
|
+
s.specification_version = 4
|
41
|
+
|
42
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
43
|
+
s.add_runtime_dependency(%q<rake>, [">= 0"])
|
44
|
+
s.add_runtime_dependency(%q<libxml-ruby>, [">= 0"])
|
45
|
+
s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
|
46
|
+
s.add_runtime_dependency(%q<ox>, [">= 0"])
|
47
|
+
s.add_development_dependency(%q<rspec>, [">= 2.8.0"])
|
48
|
+
s.add_development_dependency(%q<rdoc>, [">= 3.12"])
|
49
|
+
s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
|
50
|
+
s.add_development_dependency(%q<jeweler>, [">= 1.8.4"])
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
53
|
+
s.add_dependency(%q<libxml-ruby>, [">= 0"])
|
54
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
55
|
+
s.add_dependency(%q<ox>, [">= 0"])
|
56
|
+
s.add_dependency(%q<rspec>, [">= 2.8.0"])
|
57
|
+
s.add_dependency(%q<rdoc>, [">= 3.12"])
|
58
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
59
|
+
s.add_dependency(%q<jeweler>, [">= 1.8.4"])
|
60
|
+
end
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
63
|
+
s.add_dependency(%q<libxml-ruby>, [">= 0"])
|
64
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
65
|
+
s.add_dependency(%q<ox>, [">= 0"])
|
66
|
+
s.add_dependency(%q<rspec>, [">= 2.8.0"])
|
67
|
+
s.add_dependency(%q<rdoc>, [">= 3.12"])
|
68
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
69
|
+
s.add_dependency(%q<jeweler>, [">= 1.8.4"])
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
class MultiSAXTester
|
4
|
+
include MultiSAX::Callbacks
|
5
|
+
def initialize
|
6
|
+
@result=[]
|
7
|
+
end
|
8
|
+
def sax_tag_start(tag,attrs)
|
9
|
+
@result<<tag
|
10
|
+
end
|
11
|
+
def sax_tag_end(tag)
|
12
|
+
@result<<tag
|
13
|
+
end
|
14
|
+
def sax_text(text)
|
15
|
+
text.strip!
|
16
|
+
@result<<text if text.size>0
|
17
|
+
end
|
18
|
+
attr_reader :result
|
19
|
+
end
|
20
|
+
input_xml=<<"EOM"
|
21
|
+
<?xml version="1.0" encoding="utf-8"?>
|
22
|
+
<hello><sax>world</sax></hello>
|
23
|
+
EOM
|
24
|
+
answer=['hello','sax','world','sax','hello']
|
25
|
+
|
26
|
+
describe "Multisax" do
|
27
|
+
it "rexmlstream" do
|
28
|
+
MultiSAX::Sax.reset
|
29
|
+
MultiSAX::Sax.open(:rexmlstream)
|
30
|
+
MultiSAX::Sax.parse(input_xml,MultiSAXTester.new).result.should eq answer
|
31
|
+
end
|
32
|
+
it "rexmlsax2" do
|
33
|
+
MultiSAX::Sax.reset
|
34
|
+
MultiSAX::Sax.open(:rexmlsax2)
|
35
|
+
MultiSAX::Sax.parse(input_xml,MultiSAXTester.new).result.should eq answer
|
36
|
+
end
|
37
|
+
it "ox" do
|
38
|
+
MultiSAX::Sax.reset
|
39
|
+
MultiSAX::Sax.open(:ox)
|
40
|
+
MultiSAX::Sax.parse(input_xml,MultiSAXTester.new).result.should eq answer
|
41
|
+
end
|
42
|
+
it "libxml" do
|
43
|
+
MultiSAX::Sax.reset
|
44
|
+
MultiSAX::Sax.open(:libxml)
|
45
|
+
MultiSAX::Sax.parse(input_xml,MultiSAXTester.new).result.should eq answer
|
46
|
+
end
|
47
|
+
it "nokogiri" do
|
48
|
+
MultiSAX::Sax.reset
|
49
|
+
MultiSAX::Sax.open(:nokogiri)
|
50
|
+
MultiSAX::Sax.parse(input_xml,MultiSAXTester.new).result.should eq answer
|
51
|
+
end
|
52
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'multisax'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: multisax
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- cielavenir
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: libxml-ruby
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: nokogiri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: ox
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.8.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.8.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rdoc
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.12'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.12'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: bundler
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.0.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.0.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: jeweler
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.8.4
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.8.4
|
125
|
+
description: 'Ruby Gem to handle multiple SAX libraries: ox/libxml/nokogiri/rexml'
|
126
|
+
email: cielartisan@gmail.com
|
127
|
+
executables: []
|
128
|
+
extensions: []
|
129
|
+
extra_rdoc_files:
|
130
|
+
- LICENSE.txt
|
131
|
+
- README.rdoc
|
132
|
+
files:
|
133
|
+
- .document
|
134
|
+
- .rspec
|
135
|
+
- Gemfile
|
136
|
+
- Gemfile.lock
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.rdoc
|
139
|
+
- Rakefile
|
140
|
+
- VERSION
|
141
|
+
- lib/multisax.rb
|
142
|
+
- multisax.gemspec
|
143
|
+
- spec/multisax_spec.rb
|
144
|
+
- spec/spec_helper.rb
|
145
|
+
homepage: http://github.com/cielavenir/multisax
|
146
|
+
licenses:
|
147
|
+
- 2-clause BSDL
|
148
|
+
metadata: {}
|
149
|
+
post_install_message:
|
150
|
+
rdoc_options: []
|
151
|
+
require_paths:
|
152
|
+
- lib
|
153
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
|
+
requirements:
|
160
|
+
- - '>='
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
requirements: []
|
164
|
+
rubyforge_project:
|
165
|
+
rubygems_version: 2.0.0
|
166
|
+
signing_key:
|
167
|
+
specification_version: 4
|
168
|
+
summary: Ruby Gem to handle multiple SAX libraries
|
169
|
+
test_files: []
|