rdf-rdfa 0.3.4.2 → 0.3.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +0,0 @@
1
- --colour
@@ -1,46 +0,0 @@
1
- $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- $:.unshift File.dirname(__FILE__)
3
-
4
- require "bundler/setup"
5
- require 'rubygems'
6
- require 'rspec'
7
- require 'bigdecimal' # XXX Remove Me
8
- require 'rdf/rdfa'
9
- require 'rdf/spec'
10
- require 'rdf/spec/matchers'
11
- require 'rdf/isomorphic'
12
- require 'open-uri/cached'
13
- require 'matchers'
14
-
15
- # Create and maintain a cache of downloaded URIs
16
- URI_CACHE = File.expand_path(File.join(File.dirname(__FILE__), "uri-cache"))
17
- Dir.mkdir(URI_CACHE) unless File.directory?(URI_CACHE)
18
- OpenURI::Cache.class_eval { @cache_path = URI_CACHE }
19
-
20
- ::RSpec.configure do |c|
21
- c.filter_run :focus => true
22
- c.run_all_when_everything_filtered = true
23
- c.exclusion_filter = {
24
- :ruby => lambda { |version| !(RUBY_VERSION.to_s =~ /^#{version.to_s}/) },
25
- }
26
- c.include(RDF::Spec::Matchers)
27
- end
28
-
29
- TMP_DIR = File.join(File.expand_path(File.dirname(__FILE__)), "tmp")
30
-
31
- # Heuristically detect the input stream
32
- def detect_format(stream)
33
- # Got to look into the file to see
34
- if stream.is_a?(IO) || stream.is_a?(StringIO)
35
- stream.rewind
36
- string = stream.read(1000)
37
- stream.rewind
38
- else
39
- string = stream.to_s
40
- end
41
- case string
42
- when /<html/i then RDF::RDFa::Reader
43
- when /@prefix/i then RDF::N3::Reader
44
- else RDF::NTriples::Reader
45
- end
46
- end
@@ -1,97 +0,0 @@
1
- # Spira class for manipulating test-manifest style test suites.
2
- # Used for SWAP tests
3
- require 'spira'
4
- require 'rdf/n3'
5
- require 'open-uri'
6
-
7
- module Fixtures
8
- SUITE = RDF::URI("http://rdfa.digitalbazaar.com/test-suite/")
9
-
10
- class TestCase
11
- HTMLRE = Regexp.new('([0-9]{4,4})\.xhtml')
12
- TCPATHRE = Regexp.compile('\$TCPATH')
13
-
14
- HOST_LANGUAGE_VERSION_SETS = [
15
- ["xhtml1", "rdfa1.1"],
16
- ["xml1", "rdfa1.1"],
17
- ["html4", "rdfa1.1"],
18
- ["html5", "rdfa1.1"],
19
- ["xhtml5", "rdfa1.1"],
20
- ["xhtml1", "rdfa1.0"],
21
- ["svgtiny1.2", "rdfa1.0"],
22
- ["svg", "rdfa1.1"],
23
- ]
24
-
25
- class Test < RDF::Vocabulary("http://www.w3.org/2006/03/test-description#"); end
26
- class RdfaTest < RDF::Vocabulary("http://rdfa.digitalbazaar.com/vocabs/rdfa-test#"); end
27
-
28
- attr_accessor :debug
29
- include Spira::Resource
30
-
31
- type Test.TestCase
32
- property :title, :predicate => DC11.title, :type => XSD.string
33
- property :purpose, :predicate => Test.purpose, :type => XSD.string
34
- has_many :hostLanguage, :predicate => RdfaTest.hostLanguage, :type => XSD.string
35
- has_many :version, :predicate => RdfaTest.rdfaVersion, :type => XSD.string
36
- property :expected, :predicate => Test.expectedResults
37
- property :contributor, :predicate => DC11.contributor, :type => XSD.string
38
- property :reference, :predicate => Test.specificationRefference, :type => XSD.string
39
- property :classification, :predicate => Test.classification
40
- property :inputDocument, :predicate => Test.informationResourceInput
41
- property :resultDocument, :predicate => Test.informationResourceResults
42
-
43
- def self.for_specific(host_language, version, classification = nil)
44
- each do |tc|
45
- yield(tc) if tc.hostLanguage.include?(host_language) &&
46
- tc.version.include?(version) &&
47
- (classification.nil? || tc.classification == classification)
48
- end
49
- end
50
-
51
- def expectedResults
52
- RDF::Literal::Boolean.new(expected.nil? ? "true" : expected)
53
- end
54
-
55
- def name
56
- subject.to_s.split("/").last
57
- end
58
-
59
- def input(host_language, version)
60
- base = self.inputDocument.to_s.sub('test-cases/', "test-cases/#{host_language}/#{version}/")
61
- case host_language
62
- when /^xml/ then RDF::URI(base.sub(".html", ".xml"))
63
- when /^xhtml/ then RDF::URI(base.sub(".html", ".xhtml"))
64
- when /^svg/ then RDF::URI(base.sub(".html", ".svg"))
65
- else RDF::URI(base)
66
- end
67
- end
68
-
69
- def results(host_language, version)
70
- RDF::URI(self.resultDocument.to_s.sub('test-cases/', "test-cases/#{host_language}/#{version}/"))
71
- end
72
-
73
- def trace
74
- @debug.to_a.join("\n")
75
- end
76
-
77
- def inspect
78
- "[#{self.class.to_s} " + %w(
79
- title
80
- classification
81
- hostLanguage
82
- version
83
- inputDocument
84
- resultDocument
85
- ).map {|a| v = self.send(a); "#{a}='#{v}'" if v}.compact.join(", ") +
86
- "]"
87
- end
88
- end
89
-
90
- local_manifest = File.join(File.expand_path(File.dirname(__FILE__)), 'rdfa-test-suite', 'manifest.ttl')
91
- repo = if File.exist?(local_manifest)
92
- RDF::Repository.load(local_manifest, :base_uri => SUITE.join("manifest.ttl"), :format => :n3)
93
- else
94
- RDF::Repository.load(SUITE.join("manifest.ttl"), :format => :n3)
95
- end
96
- Spira.add_repository! :default, repo
97
- end
@@ -1,410 +0,0 @@
1
- $:.unshift "."
2
- require File.join(File.dirname(__FILE__), 'spec_helper')
3
- require 'rdf/spec/writer'
4
- require 'rspec/matchers'
5
-
6
- class EX < RDF::Vocabulary("http://example/"); end
7
-
8
- describe RDF::RDFa::Writer do
9
- before(:each) do
10
- @graph = RDF::Graph.new
11
- end
12
-
13
- context "generic" do
14
- before(:each) do
15
- @writer = RDF::RDFa::Writer.new(StringIO.new)
16
- end
17
- #it_should_behave_like RDF_Writer # This seems to have broken sometime before 2011-07-07
18
- end
19
-
20
- describe "#buffer" do
21
- context "prefix definitions" do
22
- subject do
23
- @graph << [EX.a, RDF::DC.title, "foo"]
24
- serialize(:prefixes => {:dc => "http://purl.org/dc/terms/"})
25
- end
26
-
27
- specify { subject.should have_xpath("/xhtml:html/@prefix", %r(dc: http://purl.org/dc/terms/))}
28
- specify { subject.should have_xpath("/xhtml:html/@prefix", %r(ex: http://example/))}
29
- specify { subject.should_not have_xpath("/xhtml:html/@prefix", %r(bibo:))}
30
- end
31
-
32
- context "plain literal" do
33
- subject do
34
- @graph << [EX.a, EX.b, "foo"]
35
- serialize(:haml_options => {:ugly => false})
36
- end
37
-
38
- {
39
- "/xhtml:html/xhtml:body/xhtml:div/@about" => "ex:a",
40
- "//xhtml:div[@class='property']/xhtml:span[@property]/@property" => "ex:b",
41
- "//xhtml:div[@class='property']/xhtml:span[@property]/text()" => "foo",
42
- }.each do |path, value|
43
- it "returns #{value.inspect} for xpath #{path}" do
44
- subject.should have_xpath(path, value)
45
- end
46
- end
47
- end
48
-
49
- context "dc:title" do
50
- subject do
51
- @graph << [EX.a, RDF::DC.title, "foo"]
52
- serialize(:prefixes => {:dc => RDF::DC.to_s})
53
- end
54
-
55
- {
56
- "/xhtml:html/xhtml:head/xhtml:title/text()" => "foo",
57
- "/xhtml:html/xhtml:body/xhtml:div/@about" => "ex:a",
58
- "/xhtml:html/xhtml:body/xhtml:div/xhtml:h1/@property" => "dc:title",
59
- "/xhtml:html/xhtml:body/xhtml:div/xhtml:h1/text()" => "foo",
60
- }.each do |path, value|
61
- it "returns #{value.inspect} for xpath #{path}" do
62
- subject.should have_xpath(path, value)
63
- end
64
- end
65
- end
66
-
67
- context "typed resources" do
68
- context "typed resource" do
69
- subject do
70
- @graph << [EX.a, RDF.type, EX.Type]
71
- serialize(:haml_options => {:ugly => false})
72
- end
73
-
74
- {
75
- "/xhtml:html/xhtml:body/xhtml:div/@about" => "ex:a",
76
- "/xhtml:html/xhtml:body/xhtml:div/@typeof" => "ex:Type",
77
- }.each do |path, value|
78
- it "returns #{value.inspect} for xpath #{path}" do
79
- subject.should have_xpath(path, value)
80
- end
81
- end
82
- end
83
-
84
- context "resource with two types" do
85
- subject do
86
- @graph << [EX.a, RDF.type, EX.t1]
87
- @graph << [EX.a, RDF.type, EX.t2]
88
- serialize(:haml_options => {:ugly => false})
89
- end
90
-
91
- {
92
- "/xhtml:html/xhtml:body/xhtml:div/@about" => "ex:a",
93
- "/xhtml:html/xhtml:body/xhtml:div/@typeof" => "ex:t1 ex:t2",
94
- }.each do |path, value|
95
- it "returns #{value.inspect} for xpath #{path}" do
96
- subject.should have_xpath(path, value)
97
- end
98
- end
99
- end
100
-
101
- context "type template" do
102
- subject do
103
- @graph << [EX.a, RDF.type, EX.Type]
104
- serialize(:haml => RDF::RDFa::Writer::MIN_HAML.merge({
105
- EX.Type => {
106
- :subject => %q(
107
- %span
108
- type-specific subject
109
- )
110
- }
111
- }))
112
- end
113
-
114
- {
115
- "/xhtml:html/xhtml:body/xhtml:span/text()" => /type-specific subject/,
116
- }.each do |path, value|
117
- it "returns #{value.inspect} for xpath #{path}" do
118
- subject.should have_xpath(path, value)
119
- end
120
- end
121
- end
122
- end
123
-
124
- context "languaged tagged literals" do
125
- context "literal with language and no default language" do
126
- subject do
127
- @graph << [EX.a, RDF::DC.title, RDF::Literal("foo", :language => :en)]
128
- serialize(:prefixes => {:dc => "http://purl.org/dc/terms/"})
129
- end
130
-
131
- {
132
- "/xhtml:html/xhtml:body/xhtml:div/xhtml:h1/@property" => "dc:title",
133
- "/xhtml:html/xhtml:body/xhtml:div/xhtml:h1/@lang" => "en",
134
- }.each do |path, value|
135
- it "returns #{value.inspect} for xpath #{path}" do
136
- subject.should have_xpath(path, value)
137
- end
138
- end
139
- end
140
-
141
- context "literal with language and same default language" do
142
- subject do
143
- @graph << [EX.a, RDF::DC.title, RDF::Literal("foo", :language => :en)]
144
- serialize(:lang => :en)
145
- end
146
-
147
- {
148
- "/xhtml:html/@lang" => "en",
149
- "/xhtml:html/xhtml:body/xhtml:div/xhtml:h1/@lang" => false,
150
- }.each do |path, value|
151
- it "returns #{value.inspect} for xpath #{path}" do
152
- subject.should have_xpath(path, value)
153
- end
154
- end
155
- end
156
-
157
- context "literal with language and different default language" do
158
- subject do
159
- @graph << [EX.a, RDF::DC.title, RDF::Literal("foo", :language => :en)]
160
- serialize(:lang => :de)
161
- end
162
-
163
- {
164
- "/xhtml:html/@lang" => "de",
165
- "/xhtml:html/xhtml:body/xhtml:div/xhtml:h1/@lang" => "en",
166
- }.each do |path, value|
167
- it "returns #{value.inspect} for xpath #{path}" do
168
- subject.should have_xpath(path, value)
169
- end
170
- end
171
- end
172
- end
173
-
174
- context "typed literals" do
175
- describe "xsd:date" do
176
- subject do
177
- @graph << [EX.a, EX.b, RDF::Literal::Date.new("2011-03-18")]
178
- serialize(:haml_options => {:ugly => false})
179
- end
180
-
181
- {
182
- "//xhtml:span[@property]/@property" => "ex:b",
183
- "//xhtml:span[@property]/@datatype" => "xsd:date",
184
- "//xhtml:span[@property]/@content" => "2011-03-18",
185
- "//xhtml:span[@property]/text()" => "Friday, 18 March 2011",
186
- }.each do |path, value|
187
- it "returns #{value.inspect} for xpath #{path}" do
188
- subject.should have_xpath(path, value)
189
- end
190
- end
191
- end
192
-
193
- context "xsd:time" do
194
- subject do
195
- @graph << [EX.a, EX.b, RDF::Literal::Time.new("12:34:56")]
196
- serialize(:haml_options => {:ugly => false})
197
- end
198
-
199
- {
200
- "//xhtml:span[@property]/@property" => "ex:b",
201
- "//xhtml:span[@property]/@datatype" => "xsd:time",
202
- "//xhtml:span[@property]/@content" => "12:34:56",
203
- "//xhtml:span[@property]/text()" => /12:34:56/,
204
- }.each do |path, value|
205
- it "returns #{value.inspect} for xpath #{path}" do
206
- subject.should have_xpath(path, value)
207
- end
208
- end
209
- end
210
-
211
- context "xsd:dateTime" do
212
- subject do
213
- @graph << [EX.a, EX.b, RDF::Literal::DateTime.new("2011-03-18T12:34:56")]
214
- serialize(:haml_options => {:ugly => false})
215
- end
216
-
217
- {
218
- "//xhtml:span[@property]/@property" => "ex:b",
219
- "//xhtml:span[@property]/@datatype" => "xsd:dateTime",
220
- "//xhtml:span[@property]/@content" => "2011-03-18T12:34:56",
221
- "//xhtml:span[@property]/text()" => /12:34:56 \w+ on Friday, 18 March 2011/,
222
- }.each do |path, value|
223
- it "returns #{value.inspect} for xpath #{path}" do
224
- subject.should have_xpath(path, value)
225
- end
226
- end
227
- end
228
-
229
- context "rdf:XMLLiteral" do
230
- subject do
231
- @graph << [EX.a, EX.b, RDF::Literal::XML.new("E = mc<sup>2</sup>: The Most Urgent Problem of Our Time")]
232
- serialize(:haml_options => {:ugly => false})
233
- end
234
-
235
- {
236
- "//xhtml:span[@property]/@property" => "ex:b",
237
- "//xhtml:span[@property]/@datatype" => "rdf:XMLLiteral",
238
- "//xhtml:span[@property]" => %r(<span [^>]+>E = mc<sup>2</sup>: The Most Urgent Problem of Our Time<\/span>),
239
- }.each do |path, value|
240
- it "returns #{value.inspect} for xpath #{path}" do
241
- subject.should have_xpath(path, value)
242
- end
243
- end
244
- end
245
-
246
- context "xsd:string" do
247
- subject do
248
- @graph << [EX.a, EX.b, RDF::Literal.new("Albert Einstein", :datatype => RDF::XSD.string)]
249
- serialize(:haml_options => {:ugly => false})
250
- end
251
-
252
- {
253
- "//xhtml:span[@property]/@property" => "ex:b",
254
- "//xhtml:span[@property]/@datatype" => "xsd:string",
255
- "//xhtml:span[@property]/text()" => "Albert Einstein",
256
- }.each do |path, value|
257
- it "returns #{value.inspect} for xpath #{path}" do
258
- subject.should have_xpath(path, value)
259
- end
260
- end
261
- end
262
-
263
- context "unknown" do
264
- subject do
265
- @graph << [EX.a, EX.b, RDF::Literal.new("Albert Einstein", :datatype => EX.unknown)]
266
- serialize(:haml_options => {:ugly => false})
267
- end
268
-
269
- {
270
- "//xhtml:span[@property]/@property" => "ex:b",
271
- "//xhtml:span[@property]/@datatype" => "ex:unknown",
272
- "//xhtml:span[@property]/text()" => "Albert Einstein",
273
- }.each do |path, value|
274
- it "returns #{value.inspect} for xpath #{path}" do
275
- subject.should have_xpath(path, value)
276
- end
277
- end
278
- end
279
- end
280
-
281
- context "multi-valued literals" do
282
- subject do
283
- @graph << [EX.a, EX.b, "c"]
284
- @graph << [EX.a, EX.b, "d"]
285
- serialize(:haml_options => {:ugly => false})
286
- end
287
-
288
- {
289
- "//xhtml:ul/@property" => "ex:b",
290
- "//xhtml:ul/xhtml:li[1]/text()" => "c",
291
- "//xhtml:ul/xhtml:li[2]/text()" => "d",
292
- }.each do |path, value|
293
- it "returns #{value.inspect} for xpath #{path}" do
294
- subject.should have_xpath(path, value)
295
- end
296
- end
297
- end
298
-
299
- context "resource objects" do
300
- subject do
301
- @graph << [EX.a, EX.b, EX.c]
302
- serialize(:haml_options => {:ugly => false})
303
- end
304
-
305
- {
306
- "//xhtml:div/@about" => "ex:a",
307
- "//xhtml:a/@rel" => "ex:b",
308
- "//xhtml:a/@href" => EX.c.to_s,
309
- }.each do |path, value|
310
- it "returns #{value.inspect} for xpath #{path}" do
311
- subject.should have_xpath(path, value)
312
- end
313
- end
314
- end
315
-
316
- context "multi-valued resource objects" do
317
- subject do
318
- @graph << [EX.a, EX.b, EX.c]
319
- @graph << [EX.a, EX.b, EX.d]
320
- serialize(:haml_options => {:ugly => false})
321
- end
322
-
323
- {
324
- "//xhtml:div/@about" => "ex:a",
325
- "//xhtml:ul/@rel" => "ex:b",
326
- "//xhtml:ul/xhtml:li[1]/xhtml:a/@href" => EX.c.to_s,
327
- "//xhtml:ul/xhtml:li[2]/xhtml:a/@href" => EX.d.to_s,
328
- }.each do |path, value|
329
- it "returns #{value.inspect} for xpath #{path}" do
330
- subject.should have_xpath(path, value)
331
- end
332
- end
333
- end
334
-
335
- context "included resource definitions" do
336
- subject do
337
- @graph << [EX.a, EX.b, EX.c]
338
- @graph << [EX.c, EX.d, EX.e]
339
- serialize(:haml_options => {:ugly => false})
340
- end
341
-
342
- {
343
- "/xhtml:html/xhtml:body/xhtml:div/@about" => "ex:a",
344
- "//xhtml:div[@about='ex:a']/xhtml:div[@class='property']/xhtml:div[@rel]/@rel" => "ex:b",
345
- "//xhtml:div[@rel]/@resource" => "ex:c",
346
- "//xhtml:div[@rel]/xhtml:div[@class='property']/xhtml:a/@href" => EX.e.to_s,
347
- "//xhtml:div[@rel]/xhtml:div[@class='property']/xhtml:a/@rel" => "ex:d",
348
- }.each do |path, value|
349
- it "returns #{value.inspect} for xpath #{path}" do
350
- subject.should have_xpath(path, value)
351
- end
352
- end
353
- end
354
-
355
- # W3C Test suite from http://www.w3.org/2006/07/SWD/RDFa/testsuite/
356
- describe "w3c xhtml testcases" do
357
- require 'test_helper'
358
-
359
- # Generate with each template set
360
- RDF::RDFa::Writer::HAML_TEMPLATES.each do |name, template|
361
- context "Using #{name} template" do
362
- Fixtures::TestCase.for_specific("xhtml1", "rdfa1.1", Fixtures::TestCase::Test.required) do |t|
363
- next if t.name == "0212" # XMLLiteral equivalence
364
- specify "test #{t.name}: #{t.title}" do
365
- begin
366
- input = t.input("xhtml1", "rdfa1.1")
367
- @graph = RDF::Graph.load(t.input("xhtml1", "rdfa1.1"))
368
- result = serialize(:haml => template, :haml_options => {:ugly => false})
369
- graph2 = parse(result, :format => :rdfa)
370
- # Need to put this in to avoid problems with added markup
371
- statements = graph2.query(:object => RDF::URI("http://rdf.kellogg-assoc.com/css/distiller.css")).to_a
372
- statements.each {|st| graph2.delete(st)}
373
- graph2.should be_equivalent_graph(@graph, :trace => @debug.unshift(result).join("\n"))
374
- rescue RSpec::Expectations::ExpectationNotMetError => e
375
- if %w(0198).include?(t.name) || result =~ /XMLLiteral/m
376
- pending("XMLLiteral canonicalization not implemented yet")
377
- else
378
- raise
379
- end
380
- end
381
- end
382
- end
383
- end
384
- end
385
- end
386
- end
387
-
388
- require 'rdf/n3'
389
- def parse(input, options = {})
390
- reader_class = RDF::Reader.for(options[:format]) if options[:format]
391
- reader_class ||= options.fetch(:reader, RDF::Reader.for(detect_format(input)))
392
-
393
- graph = RDF::Graph.new
394
- reader_class.new(input, options).each do |statement|
395
- graph << statement
396
- end
397
- graph
398
- end
399
-
400
- # Serialize @graph to a string and compare against regexps
401
- def serialize(options = {})
402
- @debug = []
403
- result = RDF::RDFa::Writer.buffer({:debug => @debug, :standard_prefixes => true}.merge(options)) do |writer|
404
- writer << @graph
405
- end
406
- require 'cgi'
407
- puts CGI.escapeHTML(result) if $verbose
408
- result
409
- end
410
- end