excemel 1.0.2-java → 1.1.0-java

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,10 +1,9 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem 'blankslate', '~>2.1.2.4'
3
+ gem 'blankslate', '~> 3.1.2'
4
4
 
5
5
  group :development do
6
- gem "bundler", "~> 1.0.0"
7
- gem "jeweler", "~> 1.6.2"
8
- gem "rcov", ">= 0"
6
+ gem "bundler"
7
+ gem "simplecov"
9
8
  gem "rdoc", ">= 3.7"
10
9
  end
data/History.txt CHANGED
@@ -13,4 +13,10 @@
13
13
 
14
14
  == 1.0.2
15
15
 
16
- - added the ability to remove attributes by passing nil as a value
16
+ - added the ability to remove attributes by passing nil as a value
17
+
18
+ == 1.1.0
19
+
20
+ - upped XOM version to 1.2.9
21
+ - upgraded blankslate dependency
22
+ - tested with jruby 1.7.3
data/Manifest.txt CHANGED
@@ -7,4 +7,4 @@ lib/excemel.rb
7
7
  lib/excemel/excemel.rb
8
8
  lib/module/lang.rb
9
9
  lib/module/xom.rb
10
- lib/java/xom-1.2.7.jar
10
+ lib/java/xom-1.2.9.jar
@@ -1,4 +1,6 @@
1
- == Project: Excemel
1
+ # Excemel: Better XML for JRuby
2
+
3
+ [![Code Climate](https://codeclimate.com/github/integrallis/excemel.png)](https://codeclimate.com/github/integrallis/excemel)
2
4
 
3
5
  Excemel is a Ruby DSL for Elliotte Rusty Harold's XOM XML library. It is based
4
6
  on Jim Weirich's Builder. Excemel brings to JRuby the expressiveness and
@@ -9,15 +11,15 @@ Excemel extends the semantics of Builder with methods to navigate the
9
11
  in memory XML document with XPath and exposing some of the powerful XML
10
12
  manipulation capabilities of XOM.
11
13
 
12
- == Usage
14
+ ## Usage
13
15
 
14
16
  See usage examples under /examples directory of this distribution
15
17
 
16
- == Contact
18
+ ## Contact
17
19
 
18
- Author:: Brian Sam-Bodden
19
- Email:: bsbodden@integrallis.com
20
- Home Page:: http://integrallis.com
21
- License:: MIT Licence (http://www.opensource.org/licenses/mit-license.html)
20
+ * Author:: Brian Sam-Bodden
21
+ * Email:: bsbodden@integrallis.com
22
+ * Home Page:: http://integrallis.com
23
+ * License:: MIT Licence (http://www.opensource.org/licenses/mit-license.html)
22
24
 
23
25
 
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  #--
4
- # Copyright &169;2001-2008 Integrallis Software, LLC.
4
+ # Copyright &169;2001-2013 Integrallis Software, LLC.
5
5
  # All Rights Reserved.
6
6
  #
7
7
  # Permission is granted for use, copying, modification, distribution,
@@ -26,24 +26,6 @@ require 'rake'
26
26
 
27
27
  # --------------------------------------------------------------------
28
28
 
29
- require 'jeweler'
30
- Jeweler::Tasks.new do |gem|
31
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
32
- gem.name = "excemel"
33
- gem.homepage = "http://github.com/bsbodden/excemel"
34
- gem.license = "MIT"
35
- gem.summary = "JRuby DSL for XOM"
36
- gem.description = "JRuby DSL for XML Building and Manipulation with XPath & XQuery"
37
- gem.email = "bsbodden@integrallis.com"
38
- gem.authors = ["Brian Sam-Bodden"]
39
- gem.platform = "java"
40
- gem.files = FileList["History.txt", "Manifest.txt", "README.rdoc", "Gemfile", "Rakefile", "LICENSE", "lib/**/*.rb", "lib/java/*.jar"]
41
- # dependencies defined in Gemfile
42
- end
43
- Jeweler::RubygemsDotOrgTasks.new
44
-
45
- # --------------------------------------------------------------------
46
-
47
29
  require 'rake/testtask'
48
30
  Rake::TestTask.new(:test) do |test|
49
31
  test.libs << 'lib' << 'test'
@@ -53,12 +35,10 @@ end
53
35
 
54
36
  # --------------------------------------------------------------------
55
37
 
56
- require 'rcov/rcovtask'
57
- Rcov::RcovTask.new do |test|
58
- test.libs << 'test'
59
- test.pattern = 'test/**/test_*.rb'
60
- test.verbose = true
61
- test.rcov_opts << '--exclude "gems/*"'
38
+ require 'simplecov'
39
+ SimpleCov.command_name 'Unit Tests'
40
+ SimpleCov.start do
41
+ add_group "source", "lib"
62
42
  end
63
43
 
64
44
  task :default => :test
@@ -1,5 +1,3 @@
1
- #!/usr/bin/env ruby
2
-
3
1
  #--
4
2
  # Copyright &169;2001-2008 Integrallis Software, LLC.
5
3
  # All Rights Reserved.
@@ -23,7 +21,7 @@
23
21
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
23
  #++
26
-
24
+
27
25
  require 'rubygems'
28
26
  require 'blankslate'
29
27
  require 'java'
@@ -45,43 +43,11 @@ module Excemel
45
43
  # :resolve_includes => true|false replaces xi:include elements by the content they refer to
46
44
  # :namespace => provides a namespace prefix to the elements
47
45
  def initialize(options)
48
- # extract options
49
- validate = options[:validate] ? options[:validate] : false
50
- root = options[:root]
51
- xml = options[:xml]
52
- url = options[:url]
53
- file = options[:file]
54
- namespace = options[:namespace]
55
- resolve_includes = options[:resolve_includes] ? options[:resolve_includes] : false
56
-
57
- if root
58
- unless namespace
59
- @root = XOM::Element.new "#{root}"
60
- else
61
- @root = XOM::Element.new "#{root}", namespace
62
- prefix = root.to_s.split(":").first if root.include? ":"
63
- (@namespaces ||= {})[prefix] = namespace if prefix
64
- end
65
-
66
- @doc = XOM::Document.new @root
67
- else
68
- builder = XOM::Builder.new validate
69
- end
70
-
71
- if xml
72
- @doc = builder.build(xml, nil)
73
- elsif url
74
- @doc = builder.build url
75
- elsif file
76
- java_file = Lang::File.new file
77
- @doc = builder.build java_file
78
- end
46
+ resolve_includes = _extract_options(options, :resolve_includes, true)
79
47
 
80
- if resolve_includes
81
- @doc = XOM::XIncluder.resolve(@doc)
82
- end
83
-
84
- @root = @doc.get_root_element unless @root
48
+ _build_document(options)
49
+
50
+ @doc = XOM::XIncluder.resolve(@doc) if resolve_includes
85
51
  @target = @root
86
52
  end
87
53
 
@@ -89,39 +55,10 @@ module Excemel
89
55
  # Add XML elements (tags) based on the name of the method called on the
90
56
  # Document instance, blocks passed get processed recursively
91
57
  def method_missing(sym, *args, &block)
92
- if sym.to_s != 'class' && sym.to_s != 'to_s' && sym.to_s != 'inspect' # WTF? If I don't do this I
93
- text = nil # end up with extraneous tags
94
- attrs = nil # in the resulting document!!
95
- namespace = nil
96
- sym = "#{sym}:#{args.shift}" if args.first.kind_of?(Symbol)
97
- prefix = sym.to_s.split(":").first if sym.to_s.include? ":"
98
- args.each do |arg|
99
- case arg
100
- when Hash
101
- if arg.has_key? :namespace
102
- namespace = arg[:namespace]
103
- prefix = sym.to_s.split(":").first
104
- else
105
- attrs ||= {}
106
- attrs.merge!(arg)
107
- end
108
- else
109
- text ||= ''
110
- text << arg.to_s
111
- end
112
- end
113
-
114
- # try to get the namespace from the saved namespaces
115
- if prefix != nil && namespace.nil? && @namespaces != nil
116
- namespace = "#{@namespaces[prefix]}"
117
- end
118
-
119
- unless namespace
120
- tag = XOM::Element.new sym.to_s
121
- else
122
- tag = XOM::Element.new sym.to_s, namespace
123
- end
124
-
58
+ unless %w(class to_s inspect).include?(sym.to_s)
59
+ sym = _extract_sym(args, sym)
60
+ attrs, namespace, prefix, text = _process_args(args, sym)
61
+ tag = _build_tag(sym, namespace)
125
62
  _add_attributes(tag, attrs)
126
63
 
127
64
  if block
@@ -283,6 +220,93 @@ module Excemel
283
220
  @target = old_target
284
221
  end
285
222
 
223
+ def _build_tag(sym, namespace = nil)
224
+ unless namespace
225
+ tag = XOM::Element.new sym.to_s
226
+ else
227
+ tag = XOM::Element.new sym.to_s, namespace
228
+ end
229
+ tag
230
+ end
231
+
232
+ def _get_namespace(prefix)
233
+ @namespaces ? "#{@namespaces[prefix]}" : nil
234
+ end
235
+
236
+ def _extract_sym(args, sym)
237
+ args.first.kind_of?(Symbol) ? "#{sym}:#{args.shift}" : sym
238
+ end
239
+
240
+ def _extract_prefix(sym)
241
+ sym.to_s.include? ":" ? sym.to_s.split(":").first : nil
242
+ end
243
+
244
+ def _process_args(args, sym)
245
+ attrs, namespace, text = nil
246
+ prefix = _extract_prefix(sym)
247
+ args.each do |arg|
248
+ case arg
249
+ when Hash
250
+ if arg.has_key? :namespace
251
+ namespace = arg[:namespace]
252
+ prefix = sym.to_s.split(":").first
253
+ else
254
+ attrs ||= {}
255
+ attrs.merge!(arg)
256
+ end
257
+ else
258
+ text ||= ''
259
+ text << arg.to_s
260
+ end
261
+ end
262
+ namespace = _get_namespace(prefix) if prefix
263
+ [attrs, namespace, prefix, text]
264
+ end
265
+
266
+ def _extract_options(options, sym, boolean = false)
267
+ boolean ? (options[sym] ? options[sym] : false) : options[sym]
268
+ end
269
+
270
+ def _generate_doc_from_source(options, builder)
271
+ doc = nil
272
+ xml = _extract_options(options, :xml)
273
+ url = _extract_options(options, :url)
274
+ file = _extract_options(options, :file)
275
+
276
+ if xml
277
+ doc = builder.build(xml, nil)
278
+ elsif url
279
+ doc = builder.build url
280
+ elsif file
281
+ java_file = Lang::File.new file
282
+ doc = builder.build java_file
283
+ end
284
+
285
+ doc
286
+ end
287
+
288
+ def _build_document(options)
289
+ root = _extract_options(options, :root)
290
+ namespace = _extract_options(options, :namespace)
291
+ validate = _extract_options(options, :validate, true)
292
+
293
+ if root
294
+ _build_document_from_root(root, namespace)
295
+ else
296
+ @doc = _generate_doc_from_source(options, XOM::Builder.new(validate))
297
+ @root = @doc.get_root_element
298
+ end
299
+ end
300
+
301
+ def _build_document_from_root(root, namespace)
302
+ @root = _build_tag(root, namespace)
303
+ if namespace
304
+ prefix = root.to_s.split(":").first if root.include? ":"
305
+ (@namespaces ||= {})[prefix] = namespace if prefix
306
+ end
307
+ @doc = XOM::Document.new @root
308
+ end
309
+
286
310
  end
287
311
 
288
312
  end
data/lib/module/xom.rb CHANGED
@@ -25,7 +25,7 @@
25
25
  #++
26
26
 
27
27
  require 'java'
28
- require 'java/xom-1.2.7.jar'
28
+ require 'java/xom-1.2.9.jar'
29
29
 
30
30
  module XOM
31
31
  include_package 'nu.xom'
metadata CHANGED
@@ -1,124 +1,128 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: excemel
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 1.0.2
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.1.0
6
6
  platform: java
7
- authors:
8
- - Brian Sam-Bodden
9
- autorequire:
7
+ authors:
8
+ - Brian Sam-Bodden
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-07-20 00:00:00 -07:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
17
- name: blankslate
18
- version_requirements: &id001 !ruby/object:Gem::Requirement
19
- none: false
20
- requirements:
21
- - - ~>
22
- - !ruby/object:Gem::Version
23
- version: 2.1.2.4
24
- requirement: *id001
25
- prerelease: false
26
- type: :runtime
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- version_requirements: &id002 !ruby/object:Gem::Requirement
30
- none: false
31
- requirements:
32
- - - ~>
33
- - !ruby/object:Gem::Version
34
- version: 1.0.0
35
- requirement: *id002
36
- prerelease: false
37
- type: :development
38
- - !ruby/object:Gem::Dependency
39
- name: jeweler
40
- version_requirements: &id003 !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ~>
44
- - !ruby/object:Gem::Version
45
- version: 1.6.2
46
- requirement: *id003
47
- prerelease: false
48
- type: :development
49
- - !ruby/object:Gem::Dependency
50
- name: rcov
51
- version_requirements: &id004 !ruby/object:Gem::Requirement
52
- none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- version: "0"
57
- requirement: *id004
58
- prerelease: false
59
- type: :development
60
- - !ruby/object:Gem::Dependency
61
- name: rdoc
62
- version_requirements: &id005 !ruby/object:Gem::Requirement
63
- none: false
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- version: "3.7"
68
- requirement: *id005
69
- prerelease: false
70
- type: :development
71
- description: JRuby DSL for XML Building and Manipulation with XPath & XQuery
12
+ date: 2013-05-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: blankslate
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 3.1.2
21
+ none: false
22
+ requirement: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.1.2
27
+ none: false
28
+ prerelease: false
29
+ type: :runtime
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: !binary |-
37
+ MA==
38
+ none: false
39
+ requirement: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: !binary |-
44
+ MA==
45
+ none: false
46
+ prerelease: false
47
+ type: :development
48
+ - !ruby/object:Gem::Dependency
49
+ name: simplecov
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: !binary |-
55
+ MA==
56
+ none: false
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: !binary |-
62
+ MA==
63
+ none: false
64
+ prerelease: false
65
+ type: :development
66
+ - !ruby/object:Gem::Dependency
67
+ name: rdoc
68
+ version_requirements: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '3.7'
73
+ none: false
74
+ requirement: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '3.7'
79
+ none: false
80
+ prerelease: false
81
+ type: :development
82
+ description: JRuby DSL for XML Building and Manipulation with XPath
72
83
  email: bsbodden@integrallis.com
73
84
  executables: []
74
-
75
85
  extensions: []
76
-
77
- extra_rdoc_files:
78
- - LICENSE
79
- - README.rdoc
80
- files:
81
- - Gemfile
82
- - History.txt
83
- - LICENSE
84
- - Manifest.txt
85
- - README.rdoc
86
- - Rakefile
87
- - lib/excemel.rb
88
- - lib/excemel/excemel.rb
89
- - lib/java/xom-1.2.7.jar
90
- - lib/module/lang.rb
91
- - lib/module/xom.rb
92
- has_rdoc: true
86
+ extra_rdoc_files:
87
+ - LICENSE
88
+ - README.md
89
+ files:
90
+ - Gemfile
91
+ - History.txt
92
+ - LICENSE
93
+ - Manifest.txt
94
+ - Rakefile
95
+ - lib/excemel.rb
96
+ - lib/excemel/excemel.rb
97
+ - lib/java/xom-1.2.9.jar
98
+ - lib/module/lang.rb
99
+ - lib/module/xom.rb
100
+ - README.md
93
101
  homepage: http://github.com/bsbodden/excemel
94
- licenses:
95
- - MIT
96
- post_install_message:
102
+ licenses:
103
+ - MIT
104
+ post_install_message:
97
105
  rdoc_options: []
98
-
99
- require_paths:
100
- - lib
101
- required_ruby_version: !ruby/object:Gem::Requirement
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: !binary |-
113
+ MA==
102
114
  none: false
103
- requirements:
104
- - - ">="
105
- - !ruby/object:Gem::Version
106
- hash: 2
107
- segments:
108
- - 0
109
- version: "0"
110
- required_rubygems_version: !ruby/object:Gem::Requirement
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: !binary |-
120
+ MA==
111
121
  none: false
112
- requirements:
113
- - - ">="
114
- - !ruby/object:Gem::Version
115
- version: "0"
116
122
  requirements: []
117
-
118
- rubyforge_project:
119
- rubygems_version: 1.5.1
120
- signing_key:
123
+ rubyforge_project:
124
+ rubygems_version: 1.8.24
125
+ signing_key:
121
126
  specification_version: 3
122
127
  summary: JRuby DSL for XOM
123
128
  test_files: []
124
-