Skip to content

Commit 0443f47

Browse files
committed
Release 1.1.2.
* Use updated ref_count logic from rdf-rdfa. * Override rdf-rdfa preprocessing for RDF/XML semantics in managing prefixes.
2 parents dc7805f + e283f19 commit 0443f47

6 files changed

Lines changed: 68 additions & 17 deletions

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.1
1+
1.1.2

lib/rdf/rdfxml/writer.rb

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,13 +307,26 @@ def prefix_attrs
307307
# Perform any preprocessing of statements required
308308
# @return [ignored]
309309
def preprocess
310+
# Load defined prefixes
311+
(@options[:prefixes] || {}).each_pair do |k, v|
312+
@uri_to_prefix[v.to_s] = k
313+
end
314+
@options[:prefixes] = {} # Will define actual used when matched
315+
316+
prefix(:rdf, RDF.to_uri)
317+
@uri_to_prefix[RDF.to_uri.to_s] = :rdf
318+
if base_uri || @options[:lang]
319+
prefix(:xml, RDF::XML)
320+
@uri_to_prefix[RDF::XML.to_s] = :xml
321+
end
322+
310323
if @options[:default_namespace]
324+
@uri_to_prefix[@options[:default_namespace]] = nil
311325
prefix(nil, @options[:default_namespace])
312326
end
313-
314-
super
315-
prefix(:rdf, RDF.to_uri)
316-
prefix(:xml, RDF::XML) if base_uri || @options[:lang]
327+
328+
# Process each statement to establish CURIEs and Terms
329+
@graph.each {|statement| preprocess_statement(statement)}
317330
end
318331

319332
##

lib/rdf/rdfxml/writer/haml_templates.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Writer
3030
- (types.unshift(first_type); first_type = nil) if first_type && (first_type.include?('/') || first_type.start_with?('_:'))
3131
- first_type ||= get_qname(RDF.Description)
3232
- first_type = first_type[1..-1] if first_type.to_s.start_with?(":")
33-
- attr_props = attr_props.merge(get_qname(RDF.nodeID) => subject.id) if subject.node? && ref_count(subject) > 1
33+
- attr_props = attr_props.merge(get_qname(RDF.nodeID) => subject.id) if subject.node? && ref_count(subject) >= 1
3434
- attr_props = attr_props.merge(get_qname(RDF.about) => relativize(subject)) if subject.uri?
3535
- haml_tag(first_type, attr_props) do
3636
- types.each do |type|

rdf-rdfxml.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ Gem::Specification.new do |gem|
2323
gem.required_ruby_version = '>= 1.9.3'
2424
gem.requirements = []
2525

26-
gem.add_runtime_dependency 'rdf', '~> 1.1'
27-
gem.add_runtime_dependency 'rdf-rdfa', '~> 1.1'
26+
gem.add_runtime_dependency 'rdf', '~> 1.1', '>= 1.1.6'
27+
gem.add_runtime_dependency 'rdf-rdfa', '~> 1.1', '>= 1.1.4.1'
2828
gem.add_runtime_dependency 'rdf-xsd', '~> 1.1'
2929

3030
#gem.add_development_dependency 'nokogiri' , '>= 1.6.1' # conditionally done in Gemfile

spec/matchers.rb

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
require 'rspec/matchers'
22

3-
RSpec::Matchers.define :have_xpath do |xpath, value, namespaces, trace|
3+
RSpec::Matchers.define :have_xpath do |path, value, namespaces, trace|
44
match do |actual|
55
@doc = Nokogiri::XML.parse(actual)
66
return false unless @doc.is_a?(Nokogiri::XML::Document)
77
return false unless @doc.root.is_a?(Nokogiri::XML::Element)
8-
@namespaces = @doc.namespaces.inject({}) {|memo, (k,v)| memo[k.to_s.sub(/xmlns:?/, '')] = v; memo}.
8+
namespaces = @doc.namespaces.inject({}) {|memo, (k,v)| memo[k.to_s.sub(/xmlns:?/, '')] = v; memo}.
99
merge(namespaces).
1010
merge("xhtml" => "http://www.w3.org/1999/xhtml", "xml" => "http://www.w3.org/XML/1998/namespace")
11-
@result = @doc.root.at_xpath(xpath, @namespaces) rescue false
11+
@result = @doc.root.at_xpath(path, namespaces) rescue false
1212
case value
1313
when false
1414
@result.nil?
@@ -19,14 +19,23 @@
1919
when Regexp
2020
@result.to_s =~ value
2121
else
22-
@result.to_s. == value
22+
@result.to_s == value
2323
end
2424
end
25-
25+
26+
failure_message do |actual|
27+
msg = "expected that #{path.inspect}\nwould be: #{value.inspect}"
28+
msg += "\n was: #{@result}"
29+
msg += "\nsource:" + actual
30+
msg += "\nDebug:#{Array(trace).join("\n")}" if trace
31+
msg
32+
end
33+
2634
failure_message_when_negated do |actual|
27-
msg = "expected to that #{xpath.inspect} would be #{value.inspect} in:\n" + actual.to_s
28-
msg += "was: #{@result}"
29-
msg += "\nDebug:#{trace.join("\n")}" if trace
35+
msg = "expected that #{path.inspect}\nwould not be #{value.inspect}"
36+
msg += "\nsource:" + actual
37+
msg += "\nDebug:#{Array(trace).join("\n")}" if trace
38+
msg
3039
end
3140
end
3241

spec/writer_spec.rb

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,35 @@ class FOO < RDF::Vocabulary("http://foo/"); end
629629
end
630630
end
631631

632+
describe "reported issues" do
633+
{
634+
"issue #31 no namespaces" => [
635+
%(<http://example.com/> <http://www.w3.org/1999/xhtml/vocab#license> <http://creativecommons.org/licenses/by-sa/3.0/> .),
636+
{},
637+
{
638+
"/rdf:RDF/rdf:Description/@rdf:about" => 'http://example.com/',
639+
"/rdf:RDF/rdf:Description/ns0:license/@rdf:resource" => 'http://creativecommons.org/licenses/by-sa/3.0/'
640+
}
641+
],
642+
"issue #31 with namespaces" => [
643+
%(<http://example.com/> <http://www.w3.org/1999/xhtml/vocab#license> <http://creativecommons.org/licenses/by-sa/3.0/> .),
644+
{xhv: 'http://www.w3.org/1999/xhtml/vocab#'},
645+
{
646+
"/rdf:RDF/rdf:Description/@rdf:about" => 'http://example.com/',
647+
"/rdf:RDF/rdf:Description/xhv:license/@rdf:resource" => 'http://creativecommons.org/licenses/by-sa/3.0/'
648+
}
649+
]
650+
}.each do |test, (input, prefixes, paths)|
651+
it test do
652+
@graph = RDF::Graph.new << RDF::Turtle::Reader.new(input)
653+
result = serialize(prefixes: prefixes, standard_prefixes: false)
654+
paths.each do |path, value|
655+
expect(result).to have_xpath(path, value, {}, @debug)
656+
end
657+
end
658+
end
659+
end
660+
632661
# W3C RDF/XML Test suite from https://dvcs.w3.org/hg/rdf/raw-file/default/rdf-xml/tests/
633662
describe "w3c RDF/XML tests" do
634663
require 'suite_helper'
@@ -669,7 +698,7 @@ def parse(input, options = {})
669698
# Serialize @graph to a string and compare against regexps
670699
def serialize(options = {})
671700
@debug = []
672-
result = @writer_class.buffer({:debug => @debug, :standard_prefixes => true}.merge(options)) do |writer|
701+
result = @writer_class.buffer({debug: @debug, standard_prefixes: true}.merge(options)) do |writer|
673702
writer << @graph
674703
end
675704
require 'cgi'

0 commit comments

Comments
 (0)