lib/rdf/rdfa/reader.rb in rdf-rdfa-0.3.14 vs lib/rdf/rdfa/reader.rb in rdf-rdfa-0.3.15
- old
+ new
@@ -376,35 +376,27 @@
extract_script(@root, @doc, "application/rdf+xml", @options) do |statement|
block.call(statement)
end
end
-# # Look for Embedded RDF/XML
-# unless @root.xpath("//rdf:RDF", "xmlns:rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#").empty?
-# extract_script(@root, @doc, "application/rdf+xml", @options) do |statement|
-# block.call(statement)
-# end
-# end
-
# Look for Embedded scripts
- @root.css("script[type]") do |el|
- ctx = RDF::URI(el.attribute("id")) if el.attribute("id")
+ @root.css("script[type]").each do |el|
type = el.attribute("type")
extract_script(el, el.inner_text, type, @options) do |statement|
- statement.context = ctx if ctx
block.call(statement)
end
end
- # Just incase root is a <script> element
- if @root.name == 'script' && type = root.attribute('type')
- ctx = RDF::URI(@root.attribute("id")) if @root.attribute("id")
-
- extract_script(@root, @root.inner_text, type, @options) do |statement|
- statement.context = ctx if ctx
- block.call(statement)
+ # Look for Embedded microdata
+ unless @root.xpath("//@itemscope").empty?
+ begin
+ require 'rdf/microdata'
+ add_debug(@doc, "process microdata")
+ RDF::Microdata::Reader.new(@doc, options).each(&block)
+ rescue
+ add_debug(@doc, "microdata detected, not processed")
end
end
end
end
@@ -675,15 +667,17 @@
about
content
datatype
datetime
href
+ id
inlist
property
rel
resource
rev
+ role
src
typeof
value
vocab
).each do |a|
@@ -802,10 +796,15 @@
:restrictions => SafeCURIEorCURIEorIRI.fetch(@version, [])) if attrs[:about]
# if the @typeof attribute is present, set typed resource to new subject
typed_resource = new_subject if attrs[:typeof]
+ add_debug(element) {
+ "[Step 5] new_subject: #{new_subject.to_ntriples rescue 'nil'}, " +
+ "typed_resource: #{typed_resource.to_ntriples rescue 'nil'}"
+ }
+
# If no URI is provided by a resource attribute, then the first match from the following rules
# will apply:
new_subject ||= if [:xhtml1, :xhtml5, :html4, :html5].include?(@host_language) && element.name =~ /^(head|body)$/
# From XHTML+RDFa 1.1:
# if no URI is provided, then first check to see if the element is the head or body element.
@@ -1247,9 +1246,28 @@
if l.empty?
add_triple(element, new_subject, p, RDF.nil)
else
add_triple(element, new_subject, p, l.subject)
end
+ end
+ end
+
+ # Role processing
+ # @id is used as subject, bnode otherwise.
+ # Predicate is xhv:role
+ # Objects are TERMorCURIEorAbsIRIs.
+ # Act as if the default vocabulary is XHV
+ if attrs[:role]
+ subject = attrs[:id] ? uri(base, "##{attrs[:id]}") : RDF::Node.new
+ roles = process_uris(element, attrs[:role], evaluation_context, base,
+ :uri_mappings => uri_mappings,
+ :term_mappings => term_mappings,
+ :vocab => RDF::XHV.to_s,
+ :restrictions => TERMorCURIEorAbsIRI.fetch(@version, []))
+
+ add_debug(element) {"role: about: #{subject.to_ntriples}, roles: #{roles.map(&:to_ntriples).inspect}"}
+ roles.each do |r|
+ add_triple(element, subject, RDF::XHV.role, r)
end
end
end
end