Skip to content

Commit

Permalink
Finish 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Jul 25, 2017
2 parents 84c83f7 + e336a35 commit 8185bd4
Show file tree
Hide file tree
Showing 26 changed files with 200 additions and 29 deletions.
21 changes: 8 additions & 13 deletions .travis.yml
Expand Up @@ -4,20 +4,15 @@ script: "bundle exec rspec spec"
env:
- CI=true
rvm:
- 2.0
- 2.1
- 2.2.4
- 2.3.0
- jruby-9.0.4.0
- rbx-2
gemfile:
- Gemfile
- Gemfile-pure
env:
global:
- CI=true
- 2.2
- 2.3
- 2.4
- jruby-9
- rbx-3
cache: bundler
sudo: false
matrix:
allow_failures:
- rvm: rbx-2
- rvm: jruby-9
- rvm: rbx-3
dist: trusty
3 changes: 1 addition & 2 deletions Gemfile
Expand Up @@ -15,13 +15,12 @@ group :development do
gem 'rdf-turtle', github: "ruby-rdf/rdf-turtle", branch: "develop"
gem 'rdf-vocab', github: "ruby-rdf/rdf-vocab", branch: "develop"
gem "rdf-xsd", github: "ruby-rdf/rdf-xsd", branch: "develop"
gem 'sxp', github: "gkellogg/sxp-ruby", branch: "develop"
gem 'sxp', github: "dryruby/sxp.rb", branch: "develop"

gem "equivalent-xml"
end

group :debug do
gem "wirble"
gem "ruby-debug", platforms: :jruby
gem "byebug", platform: :mri
end
Expand Down
3 changes: 1 addition & 2 deletions Gemfile-pure
Expand Up @@ -15,13 +15,12 @@ group :development do
gem 'rdf-turtle', github: "ruby-rdf/rdf-turtle", branch: "develop"
gem 'rdf-vocab', github: "ruby-rdf/rdf-vocab", branch: "develop"
gem "rdf-xsd", github: "ruby-rdf/rdf-xsd", branch: "develop"
gem 'sxp', github: "gkellogg/sxp-ruby", branch: "develop"
gem 'sxp', github: "dryruby/sxp.rb", branch: "develop"

gem "equivalent-xml"
end

group :debug do
gem "wirble"
gem "ruby-debug", platforms: :jruby
gem "byebug", platform: :mri
end
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -18,7 +18,7 @@ Install with `gem install rdf-rdfxml`

* 100% free and unencumbered [public domain](http://unlicense.org/) software.
* Implements a complete parser for [RDF/XML][].
* Compatible with Ruby >= 2.0.
* Compatible with Ruby >= 2.2.2.

## Usage:
Instantiate a parser and parse source, specifying type and base-URL
Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
2.0.0
2.1.0
5 changes: 5 additions & 0 deletions dependencyci.yml
@@ -0,0 +1,5 @@
platform:
Rubygems:
rdf-isomorphic:
tests:
unmaintained: skip
13 changes: 13 additions & 0 deletions example-files/example07.rdf
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:ex="http://example.org/stuff/1.0/">
<rdf:Description rdf:about="http://www.w3.org/TR/rdf-syntax-grammar"
dc:title="RDF/XML Syntax Specification (Revised)">
<ex:editor>
<rdf:Description ex:fullName="Dave Beckett">
<ex:homePage rdf:resource="http://purl.org/net/dajobe/" />
</rdf:Description>
</ex:editor>
</rdf:Description>
</rdf:RDF>
15 changes: 15 additions & 0 deletions example-files/example08.rdf
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<rdf:Description rdf:about="http://www.w3.org/TR/rdf-syntax-grammar">
<dc:title>RDF/XML Syntax Specification (Revised)</dc:title>
<dc:title xml:lang="en">RDF/XML Syntax Specification (Revised)</dc:title>
<dc:title xml:lang="en-US">RDF/XML Syntax Specification (Revised)</dc:title>
</rdf:Description>

<rdf:Description rdf:about="http://example.org/buecher/baum" xml:lang="de">
<dc:title>Der Baum</dc:title>
<dc:description>Das Buch ist außergewöhnlich</dc:description>
<dc:title xml:lang="en">The Tree</dc:title>
</rdf:Description>
</rdf:RDF>
11 changes: 11 additions & 0 deletions example-files/example09.rdf
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:ex="http://example.org/stuff/1.0/">
<rdf:Description rdf:about="http://example.org/item01">
<ex:prop rdf:parseType="Literal"
xmlns:a="http://example.org/a#"><a:Box required="true">
<a:widget size="10" />
<a:grommit id="23" /></a:Box>
</ex:prop>
</rdf:Description>
</rdf:RDF>
7 changes: 7 additions & 0 deletions example-files/example10.rdf
@@ -0,0 +1,7 @@
<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:ex="http://example.org/stuff/1.0/">
<rdf:Description rdf:about="http://example.org/item01">
<ex:size rdf:datatype="http://www.w3.org/2001/XMLSchema#int">123</ex:size>
</rdf:Description>
</rdf:RDF>
14 changes: 14 additions & 0 deletions example-files/example11.rdf
@@ -0,0 +1,14 @@
<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:ex="http://example.org/stuff/1.0/">
<rdf:Description rdf:about="http://www.w3.org/TR/rdf-syntax-grammar"
dc:title="RDF/XML Syntax Specification (Revised)">
<ex:editor rdf:nodeID="abc"/>
</rdf:Description>

<rdf:Description rdf:nodeID="abc"
ex:fullName="Dave Beckett">
<ex:homePage rdf:resource="http://purl.org/net/dajobe/"/>
</rdf:Description>
</rdf:RDF>
12 changes: 12 additions & 0 deletions example-files/example12.rdf
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:ex="http://example.org/stuff/1.0/">
<rdf:Description rdf:about="http://www.w3.org/TR/rdf-syntax-grammar"
dc:title="RDF/XML Syntax Specification (Revised)">
<ex:editor rdf:parseType="Resource">
<ex:fullName>Dave Beckett</ex:fullName>
<ex:homePage rdf:resource="http://purl.org/net/dajobe/"/>
</ex:editor>
</rdf:Description>
</rdf:RDF>
10 changes: 10 additions & 0 deletions example-files/example13.rdf
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:ex="http://example.org/stuff/1.0/">
<rdf:Description rdf:about="http://www.w3.org/TR/rdf-syntax-grammar"
dc:title="RDF/XML Syntax Specification (Revised)">
<ex:editor ex:fullName="Dave Beckett" />
<!-- Note the ex:homePage property has been ignored for this example -->
</rdf:Description>
</rdf:RDF>
9 changes: 9 additions & 0 deletions example-files/example14.rdf
@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:ex="http://example.org/stuff/1.0/">
<rdf:Description rdf:about="http://example.org/thing">
<rdf:type rdf:resource="http://example.org/stuff/1.0/Document"/>
<dc:title>A marvelous thing</dc:title>
</rdf:Description>
</rdf:RDF>
8 changes: 8 additions & 0 deletions example-files/example15.rdf
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:ex="http://example.org/stuff/1.0/">
<ex:Document rdf:about="http://example.org/thing">
<dc:title>A marvelous thing</dc:title>
</ex:Document>
</rdf:RDF>
8 changes: 8 additions & 0 deletions example-files/example16.rdf
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:ex="http://example.org/stuff/1.0/"
xml:base="http://example.org/here/">
<rdf:Description rdf:ID="snack">
<ex:prop rdf:resource="fruit/apple"/>
</rdf:Description>
</rdf:RDF>
8 changes: 8 additions & 0 deletions example-files/example17.rdf
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Seq rdf:about="http://example.org/favourite-fruit">
<rdf:_1 rdf:resource="http://example.org/banana"/>
<rdf:_2 rdf:resource="http://example.org/apple"/>
<rdf:_3 rdf:resource="http://example.org/pear"/>
</rdf:Seq>
</rdf:RDF>
8 changes: 8 additions & 0 deletions example-files/example18.rdf
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Seq rdf:about="http://example.org/favourite-fruit">
<rdf:li rdf:resource="http://example.org/banana"/>
<rdf:li rdf:resource="http://example.org/apple"/>
<rdf:li rdf:resource="http://example.org/pear"/>
</rdf:Seq>
</rdf:RDF>
11 changes: 11 additions & 0 deletions example-files/example19.rdf
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:ex="http://example.org/stuff/1.0/">
<rdf:Description rdf:about="http://example.org/basket">
<ex:hasFruit rdf:parseType="Collection">
<rdf:Description rdf:about="http://example.org/banana"/>
<rdf:Description rdf:about="http://example.org/apple"/>
<rdf:Description rdf:about="http://example.org/pear"/>
</ex:hasFruit>
</rdf:Description>
</rdf:RDF>
8 changes: 8 additions & 0 deletions example-files/example20.rdf
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:ex="http://example.org/stuff/1.0/"
xml:base="http://example.org/triples/">
<rdf:Description rdf:about="http://example.org/">
<ex:prop rdf:ID="triple1">blah</ex:prop>
</rdf:Description>
</rdf:RDF>
4 changes: 2 additions & 2 deletions lib/rdf/rdfxml/reader.rb
Expand Up @@ -337,8 +337,8 @@ def nodeElement(el, ec)
# Determine the content type of this property element
log_fatal "child must be a proxy not a #{child.class}" unless child.is_a?(@implementation::NodeProxy)

text_nodes = child.children.select {|e| e.text? && !e.blank?}
element_nodes = child.children.select {|c| c.element? }
text_nodes = child.children.select(&:text?)
element_nodes = child.children.select(&:element?)
add_debug(child) {"#{text_nodes.to_a.length} text nodes, #{element_nodes.to_a.length} element nodes"}

text_nodes.each do |node|
Expand Down
10 changes: 9 additions & 1 deletion lib/rdf/rdfxml/reader/nokogiri.rb
Expand Up @@ -81,6 +81,14 @@ def display_path
end
end

##
# Return true of this is a text node
#
# @return [Array<:text, :element, :attribute>]
def text?
(@node.text? || @node.cdata?) && !@node.blank?
end

##
# Return true of all child elements are text
#
Expand All @@ -104,7 +112,7 @@ def namespaces
def children
@children ||= NodeSetProxy.new(@node.children, self)
end

# Ancestors of this element, in order
def ancestors
@ancestors ||= parent ? parent.ancestors + [parent] : []
Expand Down
15 changes: 10 additions & 5 deletions lib/rdf/rdfxml/writer/haml_templates.rb
Expand Up @@ -38,7 +38,8 @@ class Writer
- if expanded_type.start_with?('_:')
- haml_tag(get_qname(RDF.type), "rdf:nodeID" => expanded_type[2..-1])
-else
- haml_tag(get_qname(RDF.type), "rdf:resource" => expanded_type)
- # FIXME: closing tag forces close tag, as :/ is not honored in 5.0.1
- haml_tag(get_qname(RDF.type), "", "rdf:resource" => expanded_type)
- predicates.each do |p|
= yield(p)
),
Expand All @@ -59,9 +60,11 @@ class Writer
- haml_tag(property, :"<", "xml:lang" => object.language, "rdf:datatype" => (object.datatype unless object.plain?)) do
= object.value.to_s.encode(xml: :text)
- elsif object.node?
- haml_tag(property, :"/", "rdf:nodeID" => object.id)
- # FIXME: closing tag forces close tag, as :/ is not honored in 5.0.1
- haml_tag(property, "", "rdf:nodeID" => object.id)
- else
- haml_tag(property, :"/", "rdf:resource" => relativize(object))
- # FIXME: closing tag forces close tag, as :/ is not honored in 5.0.1
- haml_tag(property, "", "rdf:resource" => relativize(object))
),

# Outpust for a list
Expand All @@ -75,9 +78,11 @@ class Writer
- if recurse && res = yield(object)
= res
- elsif object.node?
- haml_tag(get_qname(RDF.Description), :"/", "rdf:nodeID" => (object.id if ref_count(object) > 1))
- # FIXME: closing tag forces close tag, as :/ is not honored in 5.0.1
- haml_tag(get_qname(RDF.Description), "", "rdf:nodeID" => (object.id if ref_count(object) > 1))
- else
- haml_tag(get_qname(RDF.Description), :"/", "rdf:about" => relativize(object))
- # FIXME: closing tag forces close tag, as :/ is not honored in 5.0.1
- haml_tag(get_qname(RDF.Description), "", "rdf:about" => relativize(object))
),
}
HAML_TEMPLATES = {base: BASE_HAML}
Expand Down
2 changes: 1 addition & 1 deletion rdf-rdfxml.gemspec
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |gem|
gem.require_paths = %w(lib)
gem.has_rdoc = false

gem.required_ruby_version = '>= 2.0'
gem.required_ruby_version = '>= 2.2.2'
gem.requirements = []

gem.add_runtime_dependency 'rdf', '~> 2.0'
Expand Down
18 changes: 18 additions & 0 deletions spec/reader_spec.rb
Expand Up @@ -202,6 +202,24 @@
expect(graph).to be_equivalent_graph(expected, logger: logger)
end

it "reads text from CDATA" do
sampledoc = %(<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>
<rdf:Property rdf:about="http://www.w3.org/ns/oa#annotationService">
<rdfs:comment><![CDATA[Text]]></rdfs:comment>
</rdf:Property>
</rdf:RDF>)
expected = %(
<http://www.w3.org/ns/oa#annotationService> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/1999/02/22-rdf-syntax-ns#Property> .
<http://www.w3.org/ns/oa#annotationService> <http://www.w3.org/2000/01/rdf-schema#comment> "Text" .
)
graph = parse(sampledoc, validate: true)
expect(graph).to be_equivalent_graph(expected, logger: logger)
end

context :exceptions do
it "should raise an error if rdf:aboutEach is used, as per the negative parser test rdfms-abouteach-error001 (rdf:aboutEach attribute)" do
sampledoc = %q(<?xml version="1.0" ?>
Expand Down
2 changes: 1 addition & 1 deletion spec/writer_spec.rb
Expand Up @@ -691,9 +691,9 @@ class FOO < RDF::Vocabulary("http://foo/"); end
m.entries.each do |t|
next unless t.positive_test? && t.evaluate?
# Literal serialization adds namespace definitions
next if t.subject =~ /rdfms-xml-literal-namespaces|xml-canon/

specify "#{t.name}" do
pending if t.name == 'xml-canon-test001'
unless defined?(::Nokogiri)
pending("XML-C14XL") if t.name == "xml-canon-test001"
end
Expand Down

0 comments on commit 8185bd4

Please sign in to comment.