fabulator-xml 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +9 -0
- data/README.rdoc +61 -0
- data/Rakefile +30 -0
- data/lib/fabulator/xml.rb +2 -0
- data/lib/fabulator/xml/actions.rb +76 -0
- data/lib/fabulator/xml/version.rb +16 -0
- data/test/test_fabulator-xml.rb +11 -0
- data/test/test_helper.rb +3 -0
- metadata +113 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
= fabulator-xml
|
2
|
+
|
3
|
+
* http://github.com/jgsmith/ruby-fabulator-xml
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
XML functions and types for the Fabulator engine.
|
8
|
+
|
9
|
+
Namespace: http://dh.tamu.edu/ns/fabulator/xml/1.0#
|
10
|
+
|
11
|
+
== FEATURES/PROBLEMS:
|
12
|
+
|
13
|
+
* function to run an XPath query against an XML document
|
14
|
+
|
15
|
+
* XML document data type
|
16
|
+
* XML node data type
|
17
|
+
|
18
|
+
== SYNOPSIS:
|
19
|
+
|
20
|
+
=== In Ruby
|
21
|
+
|
22
|
+
require 'fabulator'
|
23
|
+
require 'fabulator/xml'
|
24
|
+
|
25
|
+
=== In Fabulator expressions
|
26
|
+
|
27
|
+
x:path($xml-document, "/xpath")
|
28
|
+
x:document($string)
|
29
|
+
|
30
|
+
== REQUIREMENTS:
|
31
|
+
|
32
|
+
The XML extensions depend on the Ruby libxml libraries at
|
33
|
+
<http://libxml.rubyforge.org/>. If the ruby-fabulator project is already
|
34
|
+
installed, then the libxml libraries are installed as well.
|
35
|
+
|
36
|
+
== INSTALL:
|
37
|
+
|
38
|
+
* sudo gem install
|
39
|
+
|
40
|
+
== LICENSE:
|
41
|
+
|
42
|
+
Copyright (c) 2010 Texas A&M University
|
43
|
+
|
44
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
45
|
+
a copy of this software and associated documentation files (the
|
46
|
+
'Software'), to deal in the Software without restriction, including
|
47
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
48
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
49
|
+
permit persons to whom the Software is furnished to do so, subject to
|
50
|
+
the following conditions:
|
51
|
+
|
52
|
+
The above copyright notice and this permission notice shall be
|
53
|
+
included in all copies or substantial portions of the Software.
|
54
|
+
|
55
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
56
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
57
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
58
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
59
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
60
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
61
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
$: << File.expand_path(File.dirname(__FILE__))+'/lib'
|
2
|
+
$: << File.expand_path(File.dirname(__FILE__))+'/../fabulator/lib'
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
gem 'hoe', '>= 2.1.0'
|
6
|
+
require 'hoe'
|
7
|
+
require 'fileutils'
|
8
|
+
require 'fabulator'
|
9
|
+
require './lib/fabulator/xml'
|
10
|
+
|
11
|
+
Hoe.plugin :newgem
|
12
|
+
# Hoe.plugin :website
|
13
|
+
Hoe.plugin :cucumberfeatures
|
14
|
+
|
15
|
+
# Generate all the Rake tasks
|
16
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
17
|
+
$hoe = Hoe.spec 'fabulator-xml' do
|
18
|
+
self.version = Fabulator::Xml::VERSION::STRING
|
19
|
+
self.developer 'James Smith', 'jgsmith@tamu.edu'
|
20
|
+
self.rubyforge_name = self.name # TODO this is default value
|
21
|
+
# self.extra_deps = [['activesupport','>= 2.0.2']]
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'newgem/tasks'
|
26
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
27
|
+
|
28
|
+
# TODO - want other tests/tasks run by default? Add them to the list
|
29
|
+
# remove_task :default
|
30
|
+
# task :default => [:spec, :features]
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'xml/libxml'
|
2
|
+
|
3
|
+
module Fabulator
|
4
|
+
XML_NS = "http://dh.tamu.edu/ns/fabulator/xml/1.0#"
|
5
|
+
module Xml
|
6
|
+
module Actions
|
7
|
+
class Lib
|
8
|
+
include Fabulator::ActionLib
|
9
|
+
|
10
|
+
register_namespace XML_NS
|
11
|
+
|
12
|
+
register_type 'document', {
|
13
|
+
:to => [
|
14
|
+
{ :type => [ FAB_NS, 'string' ],
|
15
|
+
:weight => 1.0,
|
16
|
+
:convert => lambda { |x| x.anon_node(x.value.to_s, [ FAB_NS, 'string' ]) }
|
17
|
+
}
|
18
|
+
],
|
19
|
+
:from => [
|
20
|
+
{ :type => [ FAB_NS, 'string' ],
|
21
|
+
:weight => 1.0,
|
22
|
+
:convert => lambda { |x| (x.anon_node(LibXML::XML::Document.string(x.value), [ XML_NS, 'document' ]) rescue nil) }
|
23
|
+
}
|
24
|
+
]
|
25
|
+
}
|
26
|
+
|
27
|
+
register_type 'node', {
|
28
|
+
:to => [
|
29
|
+
{ :type => [ FAB_NS, 'string' ],
|
30
|
+
:weight => 1.0,
|
31
|
+
:convert => lambda { |x|
|
32
|
+
x.anon_node(
|
33
|
+
(
|
34
|
+
x.value.is_a?(LibXML::XML::Node) ? x.value.content :
|
35
|
+
x.value.is_a?(LibXML::XML::Attr) ? x.value.value :
|
36
|
+
x.value.to_s
|
37
|
+
), [ FAB_NS, 'string' ]
|
38
|
+
)
|
39
|
+
}
|
40
|
+
}
|
41
|
+
]
|
42
|
+
}
|
43
|
+
|
44
|
+
function 'parse-string', [ XML_NS, 'document' ] do |ctx, args|
|
45
|
+
args[0].collect { |a|
|
46
|
+
(ctx.root.anon_node(LibXML::XML::Document.string(a.to_s), [ XML_NS, 'document' ]) rescue nil)
|
47
|
+
} - [ nil ]
|
48
|
+
end
|
49
|
+
|
50
|
+
function 'path', [ XML_NS, 'node' ] do |ctx, args|
|
51
|
+
xpath_ns = [ ]
|
52
|
+
ctx.each_namespace do |p,h|
|
53
|
+
xpath_ns << "#{p}:#{h}"
|
54
|
+
end
|
55
|
+
res = [ ]
|
56
|
+
nodes = [ ]
|
57
|
+
args[0].each { |a|
|
58
|
+
args[1].each{ |x|
|
59
|
+
nodes = nodes + (a.to([XML_NS,'document']).value.find(x.to_s, xpath_ns).to_a rescue [])
|
60
|
+
}
|
61
|
+
}
|
62
|
+
# return nodes - [ nil ]
|
63
|
+
nodes.each {|ob|
|
64
|
+
if !ob.nil?
|
65
|
+
ob.each { |node|
|
66
|
+
res << ctx.root.anon_node(node, [ XML_NS, 'node' ])
|
67
|
+
}
|
68
|
+
end
|
69
|
+
}
|
70
|
+
res - [ nil ]
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Fabulator
|
2
|
+
module Xml
|
3
|
+
module VERSION
|
4
|
+
unless defined? MAJOR
|
5
|
+
MAJOR = 0
|
6
|
+
MINOR = 0
|
7
|
+
TINY = 1
|
8
|
+
PRE = nil
|
9
|
+
|
10
|
+
STRING = [MAJOR,MINOR,TINY].compact.join('.') + (PRE.nil? ? '' : PRE)
|
11
|
+
|
12
|
+
SUMMARY = "fabulator-xml #{STRING}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fabulator-xml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- James Smith
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-08-07 00:00:00 +00:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rubyforge
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 7
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 0
|
33
|
+
- 4
|
34
|
+
version: 2.0.4
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: hoe
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 21
|
46
|
+
segments:
|
47
|
+
- 2
|
48
|
+
- 6
|
49
|
+
- 1
|
50
|
+
version: 2.6.1
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
53
|
+
description: |-
|
54
|
+
XML functions and types for the Fabulator engine.
|
55
|
+
|
56
|
+
Namespace: http://dh.tamu.edu/ns/fabulator/xml/1.0#
|
57
|
+
email:
|
58
|
+
- jgsmith@tamu.edu
|
59
|
+
executables: []
|
60
|
+
|
61
|
+
extensions: []
|
62
|
+
|
63
|
+
extra_rdoc_files:
|
64
|
+
- History.txt
|
65
|
+
- Manifest.txt
|
66
|
+
files:
|
67
|
+
- History.txt
|
68
|
+
- Manifest.txt
|
69
|
+
- README.rdoc
|
70
|
+
- Rakefile
|
71
|
+
- lib/fabulator/xml.rb
|
72
|
+
- lib/fabulator/xml/actions.rb
|
73
|
+
- lib/fabulator/xml/version.rb
|
74
|
+
- test/test_fabulator-xml.rb
|
75
|
+
- test/test_helper.rb
|
76
|
+
has_rdoc: true
|
77
|
+
homepage: http://github.com/jgsmith/ruby-fabulator-xml
|
78
|
+
licenses: []
|
79
|
+
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options:
|
82
|
+
- --main
|
83
|
+
- README.rdoc
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
hash: 3
|
92
|
+
segments:
|
93
|
+
- 0
|
94
|
+
version: "0"
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
hash: 3
|
101
|
+
segments:
|
102
|
+
- 0
|
103
|
+
version: "0"
|
104
|
+
requirements: []
|
105
|
+
|
106
|
+
rubyforge_project: fabulator-xml
|
107
|
+
rubygems_version: 1.3.7
|
108
|
+
signing_key:
|
109
|
+
specification_version: 3
|
110
|
+
summary: XML functions and types for the Fabulator engine
|
111
|
+
test_files:
|
112
|
+
- test/test_fabulator-xml.rb
|
113
|
+
- test/test_helper.rb
|