rdf-rdfa 1.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/README +5 -4
- data/VERSION +1 -1
- data/lib/rdf/rdfa/context.rb +1 -1
- data/lib/rdf/rdfa/reader.rb +42 -42
- data/lib/rdf/rdfa/vocab.rb +0 -1
- data/lib/rdf/rdfa/writer.rb +98 -38
- metadata +56 -56
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
ZjE0YjkwNTI4ZGFkOWVmZjkyY2Y1ODBkYjQ3OWRmYTUyOTI3MzdjMTg4M2Ey
|
10
|
-
ZjY0NDg0ZTEyNTU3YTQyYjZkOWEzY2VmMjY5ZDI4YWFkODI5NTlkZTE5OGRm
|
11
|
-
MGY4YWI4ZjNjNmNiYWUzZDcwMzhlZmEyNDAwM2I5YTRhMWYzODg=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
YjUyNmVjMTZkNTY0MjA3ZWQ1YTVmZGUyZjgxYWZlYWM3ZGEyZTcxZjA2ZmJh
|
14
|
-
YjMwMWEyY2YyOTE4YjFmZjI2NTBhMDNjZDY5ZjI1OTdlMDQwMTRkOGU1MzA1
|
15
|
-
OTM5YTc5OTYwNjcwOTAyMjI2OGFkNTY3OTIwYmMxYjAyY2NkZWE=
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 25263c074d89ac953e6d510f14cfc79decf2488d
|
4
|
+
data.tar.gz: 82285470e7f772da635a4def20ef9b088150d6b4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ea526b09ce230b681d1240e50516d0a30687f2192f98d8b850350648746c35f320dd41c7593d7af34ce6551299d9485d143396de3facf61c941ace1fa648b27d
|
7
|
+
data.tar.gz: c0358eb529b5401e229315a7168636912f49b8522b78773ece8f72360043e1d445d227a986048c13c06567c45fc1579c1cf6f1689963bb4975ad86ad94a206c5
|
data/README
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
This repository uses [Git Flow](https://github.com/nvie/gitflow) to mange development and release activity. All submissions _must_ be on a feature branch based on the _develop_ branch to ease staging and integration.
|
1
2
|
# RDF::RDFa reader/writer
|
2
3
|
|
3
4
|
[RDFa][RDFa 1.1 Core] parser for RDF.rb.
|
@@ -387,8 +388,8 @@ The template hash defines four Haml templates:
|
|
387
388
|
}
|
388
389
|
|
389
390
|
## Dependencies
|
390
|
-
* [Ruby](http://ruby-lang.org/) (>= 1.9
|
391
|
-
* [RDF.rb](http://rubygems.org/gems/rdf) (>= 1.
|
391
|
+
* [Ruby](http://ruby-lang.org/) (>= 1.9.3)
|
392
|
+
* [RDF.rb](http://rubygems.org/gems/rdf) (>= 1.1)
|
392
393
|
* [Haml](https://rubygems.org/gems/haml) (>= 4.0)
|
393
394
|
* [HTMLEntities](https://rubygems.org/gems/htmlentities) ('>= 4.3.1')
|
394
395
|
* Soft dependency on [Nokogiri](http://rubygems.org/gems/nokogiri) (>= 1.5.9)
|
@@ -414,7 +415,6 @@ Full documentation available on [Rubydoc.info][RDFa doc]
|
|
414
415
|
### Additional vocabularies
|
415
416
|
* {RDF::PTR}
|
416
417
|
* {RDF::RDFA}
|
417
|
-
* {RDF::XHV}
|
418
418
|
* {RDF::XML}
|
419
419
|
* {RDF::XSI}
|
420
420
|
|
@@ -438,6 +438,7 @@ Full documentation available on [Rubydoc.info][RDFa doc]
|
|
438
438
|
* [Nicholas Humfrey](http://github.com/njh) - <http://njh.me/>
|
439
439
|
|
440
440
|
## Contributing
|
441
|
+
This repository uses [Git Flow](https://github.com/nvie/gitflow) to mange development and release activity. All submissions _must_ be on a feature branch based on the _develop_ branch to ease staging and integration.
|
441
442
|
|
442
443
|
* Do your best to adhere to the existing coding conventions and idioms.
|
443
444
|
* Don't use hard tabs, and don't leave trailing whitespace on any line.
|
@@ -458,7 +459,7 @@ see <http://unlicense.org/> or the accompanying {file:UNLICENSE} file.
|
|
458
459
|
|
459
460
|
## FEEDBACK
|
460
461
|
|
461
|
-
* gregg@
|
462
|
+
* gregg@greggkellogg.net
|
462
463
|
* <http://rubygems.org/rdf-rdfa>
|
463
464
|
* <http://github.com/ruby-rdf/rdf-rdfa>
|
464
465
|
* <http://lists.w3.org/Archives/Public/public-rdf-ruby/>
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0
|
1
|
+
1.1.0
|
data/lib/rdf/rdfa/context.rb
CHANGED
@@ -92,7 +92,7 @@ module RDF::RDFa
|
|
92
92
|
context.parse(repository.query(:context => uri))
|
93
93
|
end
|
94
94
|
rescue Exception => e
|
95
|
-
raise ContextError, "Context #{uri}: #{e.message}"
|
95
|
+
raise ContextError, "Context #{uri}: #{e.message}", e.backtrace
|
96
96
|
end
|
97
97
|
|
98
98
|
# Load context into repository
|
data/lib/rdf/rdfa/reader.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
begin
|
2
|
-
raise LoadError, "not with java" if RUBY_PLATFORM == "java"
|
3
2
|
require 'nokogiri'
|
4
3
|
rescue LoadError => e
|
5
4
|
:rexml
|
@@ -290,7 +289,7 @@ module RDF::RDFa
|
|
290
289
|
@library = case options[:library]
|
291
290
|
when nil
|
292
291
|
# Use Nokogiri when available, and REXML otherwise:
|
293
|
-
|
292
|
+
defined?(::Nokogiri) ? :nokogiri : :rexml
|
294
293
|
when :nokogiri, :rexml
|
295
294
|
options[:library]
|
296
295
|
else
|
@@ -404,7 +403,7 @@ module RDF::RDFa
|
|
404
403
|
require 'rdf/microdata'
|
405
404
|
add_debug(@doc, "process microdata")
|
406
405
|
@repository << RDF::Microdata::Reader.new(@doc, options)
|
407
|
-
rescue
|
406
|
+
rescue LoadError
|
408
407
|
add_debug(@doc, "microdata detected, not processed")
|
409
408
|
end
|
410
409
|
end
|
@@ -566,15 +565,23 @@ module RDF::RDFa
|
|
566
565
|
each do |uri|
|
567
566
|
# Don't try to open ourselves!
|
568
567
|
if base_uri == uri
|
569
|
-
add_debug(root) {"load_initial_contexts: skip recursive context
|
568
|
+
add_debug(root) {"load_initial_contexts: skip recursive context #{uri.to_base}"}
|
570
569
|
next
|
571
570
|
end
|
572
571
|
|
573
572
|
old_debug = RDF::RDFa.debug?
|
574
573
|
begin
|
575
|
-
add_info(root, "load_initial_contexts: load
|
574
|
+
add_info(root, "load_initial_contexts: load #{uri.to_base}")
|
576
575
|
RDF::RDFa.debug = false
|
577
576
|
context = Context.find(uri)
|
577
|
+
|
578
|
+
# Add URI Mappings to prefixes
|
579
|
+
context.prefixes.each_pair do |prefix, value|
|
580
|
+
prefix(prefix, value)
|
581
|
+
end
|
582
|
+
yield :uri_mappings, context.prefixes unless context.prefixes.empty?
|
583
|
+
yield :term_mappings, context.terms unless context.terms.empty?
|
584
|
+
yield :default_vocabulary, context.vocabulary if context.vocabulary
|
578
585
|
rescue Exception => e
|
579
586
|
RDF::RDFa.debug = old_debug
|
580
587
|
add_error(root, e.message)
|
@@ -582,14 +589,6 @@ module RDF::RDFa
|
|
582
589
|
ensure
|
583
590
|
RDF::RDFa.debug = old_debug
|
584
591
|
end
|
585
|
-
|
586
|
-
# Add URI Mappings to prefixes
|
587
|
-
context.prefixes.each_pair do |prefix, value|
|
588
|
-
prefix(prefix, value)
|
589
|
-
end
|
590
|
-
yield :uri_mappings, context.prefixes unless context.prefixes.empty?
|
591
|
-
yield :term_mappings, context.terms unless context.terms.empty?
|
592
|
-
yield :default_vocabulary, context.vocabulary if context.vocabulary
|
593
592
|
end
|
594
593
|
end
|
595
594
|
|
@@ -614,13 +613,14 @@ module RDF::RDFa
|
|
614
613
|
next unless attr =~ /^xmlns(?:\:(.+))?/
|
615
614
|
prefix = $1
|
616
615
|
add_debug("extract_mappings") { "ns(attr): #{prefix}: #{href}"}
|
617
|
-
ns_defs[prefix] = href
|
616
|
+
ns_defs[prefix] = href
|
618
617
|
end
|
619
618
|
end
|
620
619
|
|
621
620
|
ns_defs.each do |prefix, href|
|
622
621
|
# A Conforming RDFa Processor must ignore any definition of a mapping for the '_' prefix.
|
623
622
|
next if prefix == "_"
|
623
|
+
href = uri(base_uri, href).to_s
|
624
624
|
|
625
625
|
# Downcase prefix for RDFa 1.1
|
626
626
|
pfx_lc = (@version == :"rdfa1.0" || prefix.nil?) ? prefix : prefix.downcase
|
@@ -644,17 +644,18 @@ module RDF::RDFa
|
|
644
644
|
mappings = element.attribute("prefix").to_s.strip.split(/\s+/)
|
645
645
|
while mappings.length > 0 do
|
646
646
|
prefix, uri = mappings.shift.downcase, mappings.shift
|
647
|
-
#puts "uri_mappings prefix #{prefix}
|
647
|
+
#puts "uri_mappings prefix #{prefix} #{uri.to_base}"
|
648
648
|
next unless prefix.match(/:$/)
|
649
649
|
prefix.chop!
|
650
650
|
|
651
|
-
unless prefix.match(NC_REGEXP)
|
651
|
+
unless prefix.empty? || prefix.match(NC_REGEXP)
|
652
652
|
add_error(element, "extract_mappings: Prefix #{prefix.inspect} does not match NCName production")
|
653
653
|
next
|
654
654
|
end
|
655
655
|
|
656
656
|
# A Conforming RDFa Processor must ignore any definition of a mapping for the '_' prefix.
|
657
657
|
next if prefix == "_"
|
658
|
+
uri = uri(base_uri, uri).to_s
|
658
659
|
|
659
660
|
pfx_index = prefix.to_s.empty? ? nil : prefix.to_s.to_sym
|
660
661
|
if uri_mappings.fetch(pfx_index, uri) != uri
|
@@ -1090,7 +1091,7 @@ module RDF::RDFa
|
|
1090
1091
|
when datatype && ![RDF.XMLLiteral, RDF.HTML].include?(datatype)
|
1091
1092
|
# typed literal
|
1092
1093
|
add_debug(element, "[Step 11] typed literal (#{datatype})")
|
1093
|
-
RDF::Literal.new(attrs[:
|
1094
|
+
RDF::Literal.new(attrs[:content] || attrs[:datetime] || element.inner_text.to_s, :datatype => datatype, :validate => validate?, :canonicalize => canonicalize?)
|
1094
1095
|
when @version == :"rdfa1.1"
|
1095
1096
|
case
|
1096
1097
|
when datatype == RDF.XMLLiteral
|
@@ -1144,7 +1145,7 @@ module RDF::RDFa
|
|
1144
1145
|
when element.name == 'time'
|
1145
1146
|
# HTML5 support
|
1146
1147
|
# Lexically scan value and assign appropriate type, otherwise, leave untyped
|
1147
|
-
v = (attrs[:datetime] || element.inner_text).to_s
|
1148
|
+
v = (attrs[:content] || attrs[:datetime] || element.inner_text).to_s
|
1148
1149
|
datatype = %w(Date Time DateTime Year YearMonth Duration).map {|t| RDF::Literal.const_get(t)}.detect do |dt|
|
1149
1150
|
v.match(dt::GRAMMAR)
|
1150
1151
|
end || RDF::Literal
|
@@ -1334,7 +1335,7 @@ module RDF::RDFa
|
|
1334
1335
|
# value must be ignored.
|
1335
1336
|
uri = curie_to_resource_or_bnode(element, $1, options[:uri_mappings], evaluation_context.parent_subject, restrictions)
|
1336
1337
|
if uri
|
1337
|
-
add_debug(element) {"process_uri: #{value} => safeCURIE =>
|
1338
|
+
add_debug(element) {"process_uri: #{value} => safeCURIE => #{uri.to_base}"}
|
1338
1339
|
else
|
1339
1340
|
add_warning(element, "#{value} not matched as a safeCURIE", RDF::RDFA.UnresolvedCURIE)
|
1340
1341
|
end
|
@@ -1344,7 +1345,7 @@ module RDF::RDFa
|
|
1344
1345
|
# If the value is an NCName, then it is evaluated as a term according to General Use of Terms in
|
1345
1346
|
# Attributes. Note that this step may mean that the value is to be ignored.
|
1346
1347
|
uri = process_term(element, value.to_s, options)
|
1347
|
-
add_debug(element) {"process_uri: #{value} => term =>
|
1348
|
+
add_debug(element) {"process_uri: #{value} => term => #{uri ? uri.to_base : 'nil'}"}
|
1348
1349
|
uri
|
1349
1350
|
else
|
1350
1351
|
# SafeCURIEorCURIEorIRI or TERMorCURIEorAbsIRI
|
@@ -1352,35 +1353,33 @@ module RDF::RDFa
|
|
1352
1353
|
# If it is a valid CURIE, the resulting URI is used; otherwise, the value will be processed as a URI.
|
1353
1354
|
uri = curie_to_resource_or_bnode(element, value, options[:uri_mappings], evaluation_context.parent_subject, restrictions)
|
1354
1355
|
if uri
|
1355
|
-
add_debug(element) {"process_uri: #{value} => CURIE =>
|
1356
|
+
add_debug(element) {"process_uri: #{value} => CURIE => #{uri.to_base}"}
|
1356
1357
|
elsif @version == :"rdfa1.0" && value.to_s.match(/^xml/i)
|
1357
1358
|
# Special case to not allow anything starting with XML to be treated as a URI
|
1358
1359
|
elsif restrictions.include?(:absuri) || restrictions.include?(:uri)
|
1359
|
-
|
1360
|
-
|
1361
|
-
|
1362
|
-
|
1363
|
-
|
1364
|
-
|
1365
|
-
add_warning(element, "Malformed IRI #{uri.inspect}")
|
1366
|
-
end
|
1367
|
-
else
|
1368
|
-
uri = uri(base, value)
|
1369
|
-
end
|
1370
|
-
rescue ArgumentError => e
|
1371
|
-
add_warning(element, "Malformed IRI #{value}")
|
1372
|
-
rescue RDF::ReaderError => e
|
1373
|
-
add_debug(element, e.message)
|
1374
|
-
if value.to_s =~ /^\(^\w\):/
|
1375
|
-
add_warning(element, "Undefined prefix #{$1}")
|
1376
|
-
else
|
1377
|
-
add_warning(element, "Relative URI #{value}")
|
1360
|
+
# AbsURI does not use xml:base
|
1361
|
+
if restrictions.include?(:absuri)
|
1362
|
+
uri = uri(value)
|
1363
|
+
unless uri.absolute?
|
1364
|
+
uri = nil
|
1365
|
+
add_warning(element, "Malformed IRI #{uri.inspect}")
|
1378
1366
|
end
|
1367
|
+
else
|
1368
|
+
uri = uri(base, value)
|
1379
1369
|
end
|
1380
|
-
add_debug(element) {"process_uri: #{value} => URI =>
|
1370
|
+
add_debug(element) {"process_uri: #{value} => URI => #{uri ? uri.to_base : nil}"}
|
1381
1371
|
end
|
1382
1372
|
uri
|
1383
1373
|
end
|
1374
|
+
rescue ArgumentError => e
|
1375
|
+
add_warning(element, "Malformed IRI #{value}")
|
1376
|
+
rescue RDF::ReaderError => e
|
1377
|
+
add_debug(element, e.message)
|
1378
|
+
if value.to_s =~ /^\(^\w\):/
|
1379
|
+
add_warning(element, "Undefined prefix #{$1}")
|
1380
|
+
else
|
1381
|
+
add_warning(element, "Relative URI #{value}")
|
1382
|
+
end
|
1384
1383
|
end
|
1385
1384
|
|
1386
1385
|
# [7.4.3] General Use of Terms in Attributes
|
@@ -1409,9 +1408,10 @@ module RDF::RDFa
|
|
1409
1408
|
prefix, reference = curie.to_s.split(":", 2)
|
1410
1409
|
|
1411
1410
|
# consider the bnode situation
|
1412
|
-
if prefix == "_"
|
1411
|
+
if prefix == "_"
|
1413
1412
|
# we force a non-nil name, otherwise it generates a new name
|
1414
1413
|
# As a special case, _: is also a valid reference for one specific bnode.
|
1414
|
+
raise ArgumentError, "BNode not allowed in this position" unless restrictions.include?(:bnode)
|
1415
1415
|
bnode(reference)
|
1416
1416
|
elsif curie.to_s.match(/^:/)
|
1417
1417
|
# Default prefix
|
data/lib/rdf/rdfa/vocab.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
module RDF
|
2
2
|
class PTR < Vocabulary("http://www.w3.org/2009/pointers#"); end
|
3
3
|
class RDFA < Vocabulary("http://www.w3.org/ns/rdfa#"); end
|
4
|
-
class XHV < Vocabulary("http://www.w3.org/1999/xhtml/vocab#"); end
|
5
4
|
class XML < Vocabulary("http://www.w3.org/XML/1998/namespace"); end
|
6
5
|
class XSI < Vocabulary("http://www.w3.org/2001/XMLSchema-instance"); end
|
7
6
|
end
|
data/lib/rdf/rdfa/writer.rb
CHANGED
@@ -84,6 +84,8 @@ module RDF::RDFa
|
|
84
84
|
# the prefix mappings to use
|
85
85
|
# @option options [#to_s] :base_uri (nil)
|
86
86
|
# the base URI to use when constructing relative URIs, set as html>head>base.href
|
87
|
+
# @option options [Boolean] :validate (false)
|
88
|
+
# whether to validate terms when serializing
|
87
89
|
# @option options [#to_s] :lang (nil)
|
88
90
|
# Output as root @lang attribute, and avoid generation _@lang_ where possible
|
89
91
|
# @option options [Boolean] :standard_prefixes (false)
|
@@ -135,7 +137,9 @@ module RDF::RDFa
|
|
135
137
|
# Addes a statement to be serialized
|
136
138
|
# @param [RDF::Statement] statement
|
137
139
|
# @return [void]
|
140
|
+
# @raise [RDF::WriterError] if validating and attempting to write an invalid {RDF::Term}.
|
138
141
|
def write_statement(statement)
|
142
|
+
raise RDF::WriterError, "Statement #{statement.inspect} is invalid" if validate? && statement.invalid?
|
139
143
|
@graph.insert(statement)
|
140
144
|
end
|
141
145
|
|
@@ -147,8 +151,9 @@ module RDF::RDFa
|
|
147
151
|
# @return [void]
|
148
152
|
# @raise [NotImplementedError] unless implemented in subclass
|
149
153
|
# @abstract
|
154
|
+
# @raise [RDF::WriterError] if validating and attempting to write an invalid {RDF::Term}.
|
150
155
|
def write_triple(subject, predicate, object)
|
151
|
-
|
156
|
+
write_statement Statement.new(subject, predicate, object)
|
152
157
|
end
|
153
158
|
|
154
159
|
##
|
@@ -290,18 +295,19 @@ module RDF::RDFa
|
|
290
295
|
# @param [Array<RDF::Resource>] objects
|
291
296
|
# List of objects to render. If the list contains only a single element, the :property_value template will be used. Otherwise, the :property_values template is used.
|
292
297
|
# @param [Hash{Symbol => Object}] options Rendering options passed to Haml render.
|
293
|
-
# @option options [String] haml (haml_template[:property_value], haml_template[:property_values])
|
298
|
+
# @option options [String] :haml (haml_template[:property_value], haml_template[:property_values])
|
294
299
|
# Haml template to render. Otherwise, uses `haml_template[:property_value] or haml_template[:property_values]`
|
295
300
|
# depending on the cardinality of objects.
|
296
|
-
# @yield
|
297
|
-
# Yields object.
|
301
|
+
# @yield object, inlist
|
302
|
+
# Yields object and if it is contained in a list.
|
298
303
|
# @yieldparam [RDF::Resource] object
|
304
|
+
# @yieldparam [Boolean] inlist
|
299
305
|
# @yieldreturn [String, nil]
|
300
306
|
# The block should only return a string for recursive object definitions.
|
301
307
|
# @return String
|
302
308
|
# The rendered document is returned as a string
|
303
309
|
def render_property(predicate, objects, options = {}, &block)
|
304
|
-
add_debug {"render_property(#{predicate}): #{objects.inspect}"}
|
310
|
+
add_debug {"render_property(#{predicate}): #{objects.inspect}, #{options.inspect}"}
|
305
311
|
# If there are multiple objects, and no :property_values is defined, call recursively with
|
306
312
|
# each object
|
307
313
|
|
@@ -309,25 +315,32 @@ module RDF::RDFa
|
|
309
315
|
template ||= objects.length > 1 ? haml_template[:property_values] : haml_template[:property_value]
|
310
316
|
|
311
317
|
# Separate out the objects which are lists and render separately
|
312
|
-
list_objects = objects.
|
318
|
+
list_objects = objects.reject do |o|
|
319
|
+
o == RDF.nil ||
|
320
|
+
(l = RDF::List.new(o, @graph)).invalid?
|
321
|
+
end
|
313
322
|
unless list_objects.empty?
|
314
323
|
# Render non-list objects
|
315
|
-
add_debug {"properties with lists: non-lists: #{objects - list_objects}
|
316
|
-
nl = render_property(predicate, objects - list_objects, options, &block) unless objects == list_objects
|
324
|
+
add_debug {"properties with lists: #{list_objects} non-lists: #{objects - list_objects}"}
|
325
|
+
nl = depth {render_property(predicate, objects - list_objects, options, &block)} unless objects == list_objects
|
317
326
|
return nl.to_s + list_objects.map do |object|
|
318
327
|
# Render each list as multiple properties and set :inlist to true
|
319
328
|
list = RDF::List.new(object, @graph)
|
320
329
|
list.each_statement {|st| subject_done(st.subject)}
|
321
330
|
|
322
331
|
add_debug {"list: #{list.inspect} #{list.to_a}"}
|
323
|
-
|
332
|
+
depth do
|
333
|
+
render_property(predicate, list.to_a, options.merge(:inlist => "true")) do |object|
|
334
|
+
yield(object, true) if block_given?
|
335
|
+
end
|
336
|
+
end
|
324
337
|
end.join(" ")
|
325
338
|
end
|
326
339
|
|
327
340
|
if objects.length > 1 && template.nil?
|
328
|
-
#
|
341
|
+
# If there is no property_values template, render each property using property_value template
|
329
342
|
objects.map do |object|
|
330
|
-
render_property(predicate, [object], options, &block)
|
343
|
+
depth {render_property(predicate, [object], options, &block)}
|
331
344
|
end.join(" ")
|
332
345
|
else
|
333
346
|
raise RDF::WriterError, "Missing property template" if template.nil?
|
@@ -345,9 +358,7 @@ module RDF::RDFa
|
|
345
358
|
:rel => get_curie(predicate),
|
346
359
|
:inlist => nil,
|
347
360
|
}.merge(options)
|
348
|
-
hamlify(template, options)
|
349
|
-
yield(object) if block_given?
|
350
|
-
end
|
361
|
+
hamlify(template, options, &block)
|
351
362
|
end
|
352
363
|
end
|
353
364
|
|
@@ -360,7 +371,7 @@ module RDF::RDFa
|
|
360
371
|
[XML_RDFA_CONTEXT, HTML_RDFA_CONTEXT].each do |uri|
|
361
372
|
ctx = Context.find(uri)
|
362
373
|
ctx.prefixes.each_pair do |k, v|
|
363
|
-
@uri_to_prefix[v] = k
|
374
|
+
@uri_to_prefix[v] = k unless k.to_s == "dcterms"
|
364
375
|
end
|
365
376
|
|
366
377
|
ctx.terms.each_pair do |k, v|
|
@@ -444,8 +455,8 @@ module RDF::RDFa
|
|
444
455
|
# @return [ignored]
|
445
456
|
def preprocess_statement(statement)
|
446
457
|
#add_debug {"preprocess: #{statement.inspect}"}
|
447
|
-
|
448
|
-
|
458
|
+
bump_reference(statement.subject)
|
459
|
+
bump_reference(statement.object)
|
449
460
|
@subjects[statement.subject] = true
|
450
461
|
get_curie(statement.subject)
|
451
462
|
get_curie(statement.predicate)
|
@@ -482,50 +493,76 @@ module RDF::RDFa
|
|
482
493
|
# Serialize using <li> rather than template default element
|
483
494
|
# @option options [RDF::Resource] :rel (nil)
|
484
495
|
# Optional @rel property
|
485
|
-
# @return [
|
496
|
+
# @return [String]
|
486
497
|
def subject(subject, options = {})
|
487
498
|
return if is_done?(subject)
|
488
499
|
|
489
500
|
subject_done(subject)
|
490
501
|
|
502
|
+
properties = properties_for_subject(subject)
|
503
|
+
typeof = type_of(properties.delete(RDF.type.to_s), subject)
|
504
|
+
prop_list = order_properties(properties)
|
505
|
+
|
506
|
+
add_debug {"props: #{prop_list.inspect}"}
|
507
|
+
|
508
|
+
render_opts = {:typeof => typeof, :property_values => properties}.merge(options)
|
509
|
+
|
510
|
+
render_subject_template(subject, prop_list, render_opts)
|
511
|
+
end
|
512
|
+
|
513
|
+
# @param [RDF::Resource] subject
|
514
|
+
# @return [Hash{String => Object}]
|
515
|
+
def properties_for_subject(subject)
|
491
516
|
properties = {}
|
492
517
|
@graph.query(:subject => subject) do |st|
|
493
|
-
|
494
|
-
properties[
|
518
|
+
key = st.predicate.to_s.freeze
|
519
|
+
properties[key] ||= []
|
520
|
+
properties[key] << st.object
|
495
521
|
end
|
496
|
-
|
522
|
+
properties
|
523
|
+
end
|
497
524
|
|
525
|
+
# @param [Array,NilClass] type
|
526
|
+
# @param [RDF::Resource] subject
|
527
|
+
# @return [String] string representation of the specific RDF.type uri
|
528
|
+
def type_of(type, subject)
|
498
529
|
# Find appropriate template
|
499
|
-
curie
|
530
|
+
curie = case
|
500
531
|
when subject.node?
|
501
|
-
subject.to_s if ref_count(subject)
|
532
|
+
subject.to_s if ref_count(subject) > 1
|
502
533
|
else
|
503
534
|
get_curie(subject)
|
504
535
|
end
|
505
536
|
|
506
|
-
|
507
|
-
# or any type of this subject
|
508
|
-
tmpl = find_template(subject)
|
509
|
-
|
510
|
-
typeof = Array(properties.delete(RDF.type.to_s)).map {|r| get_curie(r)}.join(" ")
|
537
|
+
typeof = Array(type).map {|r| get_curie(r)}.join(" ")
|
511
538
|
typeof = nil if typeof.empty?
|
512
539
|
|
513
540
|
# Nodes without a curie need a blank @typeof to generate a subject
|
514
541
|
typeof ||= "" unless curie
|
515
|
-
prop_list -= [RDF.type.to_s]
|
516
542
|
|
543
|
+
add_debug {"subject: #{curie.inspect}, typeof: #{typeof.inspect}" }
|
544
|
+
|
545
|
+
typeof.freeze
|
546
|
+
end
|
547
|
+
|
548
|
+
# @param [RDF::Resource] subject
|
549
|
+
# @param [Array] prop_list
|
550
|
+
# @param [Hash] render_opts
|
551
|
+
# @return [String]
|
552
|
+
def render_subject_template(subject, prop_list, render_opts)
|
553
|
+
# See if there's a template based on the sorted concatenation of all types of this subject
|
554
|
+
# or any type of this subject
|
555
|
+
tmpl = find_template(subject)
|
517
556
|
add_debug {"subject: found template #{tmpl[:identifier] || tmpl.inspect}"} if tmpl
|
518
|
-
add_debug {"subject: #{curie.inspect}, typeof: #{typeof.inspect}, props: #{prop_list.inspect}"}
|
519
557
|
|
520
558
|
# Render this subject
|
521
559
|
# If :rel is specified and :typeof is nil, use @resource instead of @about.
|
522
560
|
# Pass other options from calling context
|
523
|
-
render_opts = {:typeof => typeof}.merge(options)
|
524
561
|
with_template(tmpl) do
|
525
562
|
render_subject(subject, prop_list, render_opts) do |pred|
|
526
563
|
depth do
|
527
564
|
pred = RDF::URI(pred) if pred.is_a?(String)
|
528
|
-
values =
|
565
|
+
values = render_opts[:property_values][pred.to_s]
|
529
566
|
add_debug {"subject: #{get_curie(subject)}, pred: #{get_curie(pred)}, values: #{values.inspect}"}
|
530
567
|
predicate(pred, values)
|
531
568
|
end
|
@@ -547,10 +584,10 @@ module RDF::RDFa
|
|
547
584
|
return if objects.to_a.empty?
|
548
585
|
|
549
586
|
add_debug {"predicate: #{get_curie(predicate)}"}
|
550
|
-
render_property(predicate, objects) do |o|
|
587
|
+
render_property(predicate, objects) do |o, inlist=nil|
|
551
588
|
# Yields each object, for potential recursive definition.
|
552
589
|
# If nil is returned, a leaf is produced
|
553
|
-
depth {subject(o, :rel => get_curie(predicate), :element => (:li if objects.length > 1))} if !is_done?(o) && @subjects.include?(o)
|
590
|
+
depth {subject(o, :rel => get_curie(predicate), :inlist => inlist, :element => (:li if objects.length > 1 || inlist))} if !is_done?(o) && @subjects.include?(o)
|
554
591
|
end
|
555
592
|
end
|
556
593
|
|
@@ -567,11 +604,11 @@ module RDF::RDFa
|
|
567
604
|
# Haml rendering helper. Return language for plain literal, if there is no language, or it is the same as the document, return nil
|
568
605
|
#
|
569
606
|
# @param [RDF::Literal] literal
|
570
|
-
# @return [
|
607
|
+
# @return [Symbol, nil]
|
571
608
|
# @raise [RDF::WriterError]
|
572
609
|
def get_lang(literal)
|
573
610
|
raise RDF::WriterError, "Getting datatype CURIE for #{literal.inspect}, which must be a literal" unless literal.is_a?(RDF::Literal)
|
574
|
-
literal.language if literal.literal? && literal.language && literal.language != @lang
|
611
|
+
literal.language if literal.literal? && literal.language && literal.language.to_s != @lang.to_s
|
575
612
|
end
|
576
613
|
|
577
614
|
# Haml rendering helper. Data to be added to a @content value
|
@@ -658,7 +695,7 @@ module RDF::RDFa
|
|
658
695
|
#add_debug {"get_curie(#{resource}) => #{curie}"}
|
659
696
|
|
660
697
|
@uri_to_term_or_curie[uri] = curie
|
661
|
-
rescue
|
698
|
+
rescue ArgumentError => e
|
662
699
|
raise RDF::WriterError, "Invalid URI #{uri.inspect}: #{e.message}"
|
663
700
|
end
|
664
701
|
private
|
@@ -676,6 +713,10 @@ module RDF::RDFa
|
|
676
713
|
end
|
677
714
|
|
678
715
|
# Increase depth around a method invocation
|
716
|
+
# @yield
|
717
|
+
# Yields with no arguments
|
718
|
+
# @yieldreturn [Object] returns the result of yielding
|
719
|
+
# @return [Object]
|
679
720
|
def depth
|
680
721
|
@depth += 1
|
681
722
|
ret = yield
|
@@ -684,6 +725,11 @@ module RDF::RDFa
|
|
684
725
|
end
|
685
726
|
|
686
727
|
# Set the template to use within block
|
728
|
+
# @param [Hash{Symbol => String}] templ template to use for block evaluation; merged in with the existing template.
|
729
|
+
# @yield
|
730
|
+
# Yields with no arguments
|
731
|
+
# @yieldreturn [Object] returns the result of yielding
|
732
|
+
# @return [Object]
|
687
733
|
def with_template(templ)
|
688
734
|
if templ
|
689
735
|
new_template = @options[:haml].
|
@@ -734,15 +780,29 @@ module RDF::RDFa
|
|
734
780
|
def find_template(subject); end
|
735
781
|
|
736
782
|
# Mark a subject as done.
|
783
|
+
# @param [RDF::Resource] subject
|
784
|
+
# @return [Boolean]
|
737
785
|
def subject_done(subject)
|
738
786
|
@serialized[subject] = true
|
739
787
|
end
|
740
788
|
|
789
|
+
# Determine if the subject has been completed
|
790
|
+
# @param [RDF::Resource] subject
|
791
|
+
# @return [Boolean]
|
741
792
|
def is_done?(subject)
|
742
793
|
@serialized.include?(subject)
|
743
794
|
end
|
744
795
|
|
796
|
+
# Increase the reference count of this resource
|
797
|
+
# @param [RDF::Resource] resource
|
798
|
+
# @return [Integer] resulting reference count
|
799
|
+
def bump_reference(resource)
|
800
|
+
@references[resource] = ref_count(resource) + 1
|
801
|
+
end
|
802
|
+
|
745
803
|
# Return the number of times this node has been referenced in the object position
|
804
|
+
# @param [RDF::Node] node
|
805
|
+
# @return [Boolean]
|
746
806
|
def ref_count(node)
|
747
807
|
@references.fetch(node, 0)
|
748
808
|
end
|
@@ -756,7 +816,7 @@ module RDF::RDFa
|
|
756
816
|
message = message + yield if block_given?
|
757
817
|
msg = "#{' ' * @depth}#{message}"
|
758
818
|
STDERR.puts msg if ::RDF::RDFa.debug?
|
759
|
-
@debug << msg if @debug.is_a?(Array)
|
819
|
+
@debug << msg.force_encoding("utf-8") if @debug.is_a?(Array)
|
760
820
|
end
|
761
821
|
end
|
762
822
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdf-rdfa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregg
|
@@ -9,230 +9,230 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-11-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdf
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- -
|
18
|
+
- - '>='
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 1.0
|
20
|
+
version: 1.1.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- -
|
25
|
+
- - '>='
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 1.0
|
27
|
+
version: 1.1.0
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: haml
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- -
|
32
|
+
- - '>='
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: '4.0'
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- -
|
39
|
+
- - '>='
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '4.0'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: rdf-xsd
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- -
|
46
|
+
- - '>='
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: '1.
|
48
|
+
version: '1.1'
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- -
|
53
|
+
- - '>='
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: '1.
|
55
|
+
version: '1.1'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: htmlentities
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- -
|
60
|
+
- - '>='
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: 4.3.1
|
63
63
|
type: :runtime
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- -
|
67
|
+
- - '>='
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: 4.3.1
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: nokogiri
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- -
|
74
|
+
- - '>='
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: 1.5.9
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- -
|
81
|
+
- - '>='
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: 1.5.9
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
85
|
name: equivalent-xml
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
|
-
- -
|
88
|
+
- - '>='
|
89
89
|
- !ruby/object:Gem::Version
|
90
90
|
version: 0.3.0
|
91
91
|
type: :development
|
92
92
|
prerelease: false
|
93
93
|
version_requirements: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
|
-
- -
|
95
|
+
- - '>='
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: 0.3.0
|
98
98
|
- !ruby/object:Gem::Dependency
|
99
99
|
name: open-uri-cached
|
100
100
|
requirement: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
|
-
- -
|
102
|
+
- - '>='
|
103
103
|
- !ruby/object:Gem::Version
|
104
104
|
version: 0.0.5
|
105
105
|
type: :development
|
106
106
|
prerelease: false
|
107
107
|
version_requirements: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
|
-
- -
|
109
|
+
- - '>='
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: 0.0.5
|
112
112
|
- !ruby/object:Gem::Dependency
|
113
113
|
name: json-ld
|
114
114
|
requirement: !ruby/object:Gem::Requirement
|
115
115
|
requirements:
|
116
|
-
- -
|
116
|
+
- - '>='
|
117
117
|
- !ruby/object:Gem::Version
|
118
|
-
version:
|
118
|
+
version: '1.1'
|
119
119
|
type: :development
|
120
120
|
prerelease: false
|
121
121
|
version_requirements: !ruby/object:Gem::Requirement
|
122
122
|
requirements:
|
123
|
-
- -
|
123
|
+
- - '>='
|
124
124
|
- !ruby/object:Gem::Version
|
125
|
-
version:
|
125
|
+
version: '1.1'
|
126
126
|
- !ruby/object:Gem::Dependency
|
127
127
|
name: rspec
|
128
128
|
requirement: !ruby/object:Gem::Requirement
|
129
129
|
requirements:
|
130
|
-
- -
|
130
|
+
- - '>='
|
131
131
|
- !ruby/object:Gem::Version
|
132
132
|
version: 2.14.0
|
133
133
|
type: :development
|
134
134
|
prerelease: false
|
135
135
|
version_requirements: !ruby/object:Gem::Requirement
|
136
136
|
requirements:
|
137
|
-
- -
|
137
|
+
- - '>='
|
138
138
|
- !ruby/object:Gem::Version
|
139
139
|
version: 2.14.0
|
140
140
|
- !ruby/object:Gem::Dependency
|
141
141
|
name: rdf-microdata
|
142
142
|
requirement: !ruby/object:Gem::Requirement
|
143
143
|
requirements:
|
144
|
-
- -
|
144
|
+
- - '>='
|
145
145
|
- !ruby/object:Gem::Version
|
146
|
-
version: '
|
146
|
+
version: '1.1'
|
147
147
|
type: :development
|
148
148
|
prerelease: false
|
149
149
|
version_requirements: !ruby/object:Gem::Requirement
|
150
150
|
requirements:
|
151
|
-
- -
|
151
|
+
- - '>='
|
152
152
|
- !ruby/object:Gem::Version
|
153
|
-
version: '
|
153
|
+
version: '1.1'
|
154
154
|
- !ruby/object:Gem::Dependency
|
155
155
|
name: rdf-spec
|
156
156
|
requirement: !ruby/object:Gem::Requirement
|
157
157
|
requirements:
|
158
|
-
- -
|
158
|
+
- - '>='
|
159
159
|
- !ruby/object:Gem::Version
|
160
|
-
version: '1.
|
160
|
+
version: '1.1'
|
161
161
|
type: :development
|
162
162
|
prerelease: false
|
163
163
|
version_requirements: !ruby/object:Gem::Requirement
|
164
164
|
requirements:
|
165
|
-
- -
|
165
|
+
- - '>='
|
166
166
|
- !ruby/object:Gem::Version
|
167
|
-
version: '1.
|
167
|
+
version: '1.1'
|
168
168
|
- !ruby/object:Gem::Dependency
|
169
169
|
name: rdf-turtle
|
170
170
|
requirement: !ruby/object:Gem::Requirement
|
171
171
|
requirements:
|
172
|
-
- -
|
172
|
+
- - '>='
|
173
173
|
- !ruby/object:Gem::Version
|
174
|
-
version: '
|
174
|
+
version: '1.1'
|
175
175
|
type: :development
|
176
176
|
prerelease: false
|
177
177
|
version_requirements: !ruby/object:Gem::Requirement
|
178
178
|
requirements:
|
179
|
-
- -
|
179
|
+
- - '>='
|
180
180
|
- !ruby/object:Gem::Version
|
181
|
-
version: '
|
181
|
+
version: '1.1'
|
182
182
|
- !ruby/object:Gem::Dependency
|
183
183
|
name: rdf-rdfxml
|
184
184
|
requirement: !ruby/object:Gem::Requirement
|
185
185
|
requirements:
|
186
|
-
- -
|
186
|
+
- - '>='
|
187
187
|
- !ruby/object:Gem::Version
|
188
|
-
version: '
|
188
|
+
version: '1.1'
|
189
189
|
type: :development
|
190
190
|
prerelease: false
|
191
191
|
version_requirements: !ruby/object:Gem::Requirement
|
192
192
|
requirements:
|
193
|
-
- -
|
193
|
+
- - '>='
|
194
194
|
- !ruby/object:Gem::Version
|
195
|
-
version: '
|
195
|
+
version: '1.1'
|
196
196
|
- !ruby/object:Gem::Dependency
|
197
197
|
name: rdf-isomorphic
|
198
198
|
requirement: !ruby/object:Gem::Requirement
|
199
199
|
requirements:
|
200
|
-
- -
|
200
|
+
- - '>='
|
201
201
|
- !ruby/object:Gem::Version
|
202
|
-
version: '
|
202
|
+
version: '1.1'
|
203
203
|
type: :development
|
204
204
|
prerelease: false
|
205
205
|
version_requirements: !ruby/object:Gem::Requirement
|
206
206
|
requirements:
|
207
|
-
- -
|
207
|
+
- - '>='
|
208
208
|
- !ruby/object:Gem::Version
|
209
|
-
version: '
|
209
|
+
version: '1.1'
|
210
210
|
- !ruby/object:Gem::Dependency
|
211
211
|
name: sparql
|
212
212
|
requirement: !ruby/object:Gem::Requirement
|
213
213
|
requirements:
|
214
|
-
- -
|
214
|
+
- - '>='
|
215
215
|
- !ruby/object:Gem::Version
|
216
|
-
version: '
|
216
|
+
version: '1.1'
|
217
217
|
type: :development
|
218
218
|
prerelease: false
|
219
219
|
version_requirements: !ruby/object:Gem::Requirement
|
220
220
|
requirements:
|
221
|
-
- -
|
221
|
+
- - '>='
|
222
222
|
- !ruby/object:Gem::Version
|
223
|
-
version: '
|
223
|
+
version: '1.1'
|
224
224
|
- !ruby/object:Gem::Dependency
|
225
225
|
name: yard
|
226
226
|
requirement: !ruby/object:Gem::Requirement
|
227
227
|
requirements:
|
228
|
-
- -
|
228
|
+
- - '>='
|
229
229
|
- !ruby/object:Gem::Version
|
230
230
|
version: 0.8.5
|
231
231
|
type: :development
|
232
232
|
prerelease: false
|
233
233
|
version_requirements: !ruby/object:Gem::Requirement
|
234
234
|
requirements:
|
235
|
-
- -
|
235
|
+
- - '>='
|
236
236
|
- !ruby/object:Gem::Version
|
237
237
|
version: 0.8.5
|
238
238
|
description: RDF::RDFa is an RDFa reader/writer for Ruby using the RDF.rb library
|
@@ -281,17 +281,17 @@ require_paths:
|
|
281
281
|
- lib
|
282
282
|
required_ruby_version: !ruby/object:Gem::Requirement
|
283
283
|
requirements:
|
284
|
-
- -
|
284
|
+
- - '>='
|
285
285
|
- !ruby/object:Gem::Version
|
286
|
-
version: 1.
|
286
|
+
version: 1.9.3
|
287
287
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
288
288
|
requirements:
|
289
|
-
- -
|
289
|
+
- - '>='
|
290
290
|
- !ruby/object:Gem::Version
|
291
291
|
version: '0'
|
292
292
|
requirements: []
|
293
293
|
rubyforge_project: rdf-rdfa
|
294
|
-
rubygems_version: 2.
|
294
|
+
rubygems_version: 2.1.11
|
295
295
|
signing_key:
|
296
296
|
specification_version: 4
|
297
297
|
summary: RDFa reader/writer for RDF.rb.
|