rdf-rdfa 3.0.1 → 3.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5bdb70755898ce8bc3abeee0c7ed88456d187f1560842d004fcb15288de6cdbc
4
- data.tar.gz: a7659c93eb5c51b652e67dc24f3cb9e1a5f6b3c948b501c055b0b93cdd1e1ff3
3
+ metadata.gz: 41a438683b553f9eaa31a244a4fbbeeb2413b999f040b4a46980fe939d1891d2
4
+ data.tar.gz: a191ff7cf36e120aa52491c8eea5b4cab05b48d5595c0486a6e9ed774093b39e
5
5
  SHA512:
6
- metadata.gz: 752ced4f5c431a3affbb7847e7244bb82cd809f68c855d14d0c5adb09e57d190a5da3432d53caa1ca6941b0c55e3981d2767b759247b3eb2dba16c2368942b3c
7
- data.tar.gz: d19b8da81d8930d53db82e17f4c8eb4fa1fe14e1aca7e0661980df999b820d57d7eb61ff22245b791074af01fcf9d2c78c5e377eee75ff319adbc80f00fdcd29
6
+ metadata.gz: 4e95a2ef75396bfead46f171d2366bf4019c7a6ffd9be70e1ae24614671d7f20719eb00476906ef17047bbf9ef9ed1ac7f711b5905e42c64094ac85134a48469
7
+ data.tar.gz: b1cd79507874df6cb7f516a6ad87450b9d0e14e63784fe90191c862cd38c35a5520b33c315b287483aadc14800de677b200d7e94dcdb5ae6c54ae9fbf0c282d1
data/README.md CHANGED
@@ -16,7 +16,7 @@ RDF::RDFa parses [RDFa][RDFa 1.1 Core] into statements or triples.
16
16
  * Fully compliant RDFa 1.1 parser.
17
17
  * Template-based Writer to generate XHTML+RDFa.
18
18
  * Writer uses user-replacable [Haml][Haml]-based templates to generate RDFa.
19
- * If available, uses [Nokogiri][] for parsing HTML/SVG, falls back to REXML otherwise. For HTML5, include the [Nokogumbo][] gem for are pure-HTML5 parser with better error detection.
19
+ * If available, uses [Nokogiri][] for parsing HTML/SVG, falls back to REXML otherwise. For HTML5, include the [Nokogumbo][] gem for a pure-HTML5 parser with better error detection.
20
20
 
21
21
  Install with `gem install rdf-rdfa`
22
22
 
@@ -397,12 +397,12 @@ The template hash defines four Haml templates:
397
397
  }
398
398
 
399
399
  ## Dependencies
400
- * [Ruby](http://ruby-lang.org/) (>= 2.2)
401
- * [RDF.rb](http://rubygems.org/gems/rdf) (~> 3.0)
402
- * [Haml](https://rubygems.org/gems/haml) (~> 5.0)
403
- * [HTMLEntities](https://rubygems.org/gems/htmlentities) (>= 4.3.1)
404
- * Soft dependency on [Nokogiri](http://rubygems.org/gems/nokogiri) (>= 1.7.1)
405
- * Soft dependency on [Nokogumbo](https://github.com/rubys/nokogumbo) (>= 1.4.10)
400
+ * [Ruby](http://ruby-lang.org/) (>= 2.4)
401
+ * [RDF.rb](http://rubygems.org/gems/rdf) (~> 3.1)
402
+ * [Haml](https://rubygems.org/gems/haml) (~> 5.1)
403
+ * [HTMLEntities](https://rubygems.org/gems/htmlentities) (>= 4.3)
404
+ * Soft dependency on [Nokogiri](http://rubygems.org/gems/nokogiri) (>= 1.10)
405
+ * Soft dependency on [Nokogumbo](https://github.com/rubys/nokogumbo) (>= 2.0)
406
406
 
407
407
  ## Documentation
408
408
  Full documentation available on [Rubydoc.info][RDFa doc]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.1
1
+ 3.1.0
@@ -40,7 +40,7 @@ module RDF::RDFa
40
40
  # @yieldparam [RDF::RDFa::Context] context
41
41
  # @yieldreturn [void] ignored
42
42
  # @return [RDF::RDFa::Context]
43
- def initialize(uri, options = {}, &block)
43
+ def initialize(uri, **options, &block)
44
44
  @uri = RDF::URI.intern(uri)
45
45
  @prefixes = options.fetch(:prefixes, {})
46
46
  @terms = options.fetch(:terms, {})
@@ -97,7 +97,7 @@ module RDF::RDFa
97
97
  cache[uri] = new(uri) do |context|
98
98
  log_debug("process_context: retrieve context <#{uri}>") if respond_to?(:log_debug)
99
99
  Context.load(uri)
100
- context.parse(repository.query(graph_name: uri))
100
+ context.parse(repository.query({graph_name: uri}))
101
101
  end
102
102
  rescue Exception => e
103
103
  if respond_to?(:log_fatal)
@@ -4,8 +4,8 @@
4
4
  class RDF::RDFa::Context
5
5
  def self.find_with_html_rdfa_1_1(uri)
6
6
  if uri.to_s == "http://www.w3.org/2011/rdfa-context/html-rdfa-1.1"
7
- @_html_rdfa_1_1_prof ||= RDF::RDFa::Context.new(RDF::URI("http://www.w3.org/2011/rdfa-context/html-rdfa-1.1"), {
8
- })
7
+ @_html_rdfa_1_1_prof ||= RDF::RDFa::Context.new(RDF::URI("http://www.w3.org/2011/rdfa-context/html-rdfa-1.1"),
8
+ )
9
9
  else
10
10
  find_without_html_rdfa_1_1(uri)
11
11
  end
@@ -4,7 +4,7 @@
4
4
  class RDF::RDFa::Context
5
5
  def self.find_with_xhtml_rdfa_1_1(uri)
6
6
  if uri.to_s == "http://www.w3.org/2011/rdfa-context/xhtml-rdfa-1.1"
7
- @_xhtml_rdfa_1_1_prof ||= RDF::RDFa::Context.new(RDF::URI("http://www.w3.org/2011/rdfa-context/xhtml-rdfa-1.1"), {
7
+ @_xhtml_rdfa_1_1_prof ||= RDF::RDFa::Context.new(RDF::URI("http://www.w3.org/2011/rdfa-context/xhtml-rdfa-1.1"),
8
8
  terms: {
9
9
  alternate: "http://www.w3.org/1999/xhtml/vocab#alternate",
10
10
  appendix: "http://www.w3.org/1999/xhtml/vocab#appendix",
@@ -32,7 +32,7 @@ class RDF::RDFa::Context
32
32
  top: "http://www.w3.org/1999/xhtml/vocab#top",
33
33
  up: "http://www.w3.org/1999/xhtml/vocab#up",
34
34
  },
35
- })
35
+ )
36
36
  else
37
37
  find_without_xhtml_rdfa_1_1(uri)
38
38
  end
@@ -4,8 +4,9 @@
4
4
  class RDF::RDFa::Context
5
5
  def self.find_with_rdfa_1_1(uri)
6
6
  if uri.to_s == "http://www.w3.org/2011/rdfa-context/rdfa-1.1"
7
- @_rdfa_1_1_prof ||= RDF::RDFa::Context.new(RDF::URI("http://www.w3.org/2011/rdfa-context/rdfa-1.1"), {
7
+ @_rdfa_1_1_prof ||= RDF::RDFa::Context.new(RDF::URI("http://www.w3.org/2011/rdfa-context/rdfa-1.1"),
8
8
  prefixes: {
9
+ as: "https://www.w3.org/ns/activitystreams#",
9
10
  cc: "http://creativecommons.org/ns#",
10
11
  csvw: "http://www.w3.org/ns/csvw#",
11
12
  ctag: "http://commontag.org/ns#",
@@ -13,11 +14,16 @@ class RDF::RDFa::Context
13
14
  dc11: "http://purl.org/dc/elements/1.1/",
14
15
  dcat: "http://www.w3.org/ns/dcat#",
15
16
  dcterms: "http://purl.org/dc/terms/",
17
+ dqv: "http://www.w3.org/ns/dqv#",
18
+ duv: "https://www.w3.org/ns/duv#",
16
19
  foaf: "http://xmlns.com/foaf/0.1/",
17
20
  gr: "http://purl.org/goodrelations/v1#",
18
21
  grddl: "http://www.w3.org/2003/g/data-view#",
19
22
  ical: "http://www.w3.org/2002/12/cal/icaltzd#",
23
+ ldp: "http://www.w3.org/ns/ldp#",
20
24
  ma: "http://www.w3.org/ns/ma-ont#",
25
+ oa: "http://www.w3.org/ns/oa#",
26
+ odrl: "http://www.w3.org/ns/odrl/2/",
21
27
  og: "http://ogp.me/ns#",
22
28
  org: "http://www.w3.org/ns/org#",
23
29
  owl: "http://www.w3.org/2002/07/owl#",
@@ -34,6 +40,9 @@ class RDF::RDFa::Context
34
40
  sioc: "http://rdfs.org/sioc/ns#",
35
41
  skos: "http://www.w3.org/2004/02/skos/core#",
36
42
  skosxl: "http://www.w3.org/2008/05/skos-xl#",
43
+ sosa: "http://www.w3.org/ns/sosa/",
44
+ ssn: "http://www.w3.org/ns/ssn/",
45
+ time: "http://www.w3.org/2006/time#",
37
46
  v: "http://rdf.data-vocabulary.org/#",
38
47
  vcard: "http://www.w3.org/2006/vcard/ns#",
39
48
  void: "http://rdfs.org/ns/void#",
@@ -48,7 +57,7 @@ class RDF::RDFa::Context
48
57
  license: "http://www.w3.org/1999/xhtml/vocab#license",
49
58
  role: "http://www.w3.org/1999/xhtml/vocab#role",
50
59
  },
51
- })
60
+ )
52
61
  else
53
62
  find_without_rdfa_1_1(uri)
54
63
  end
@@ -17,7 +17,7 @@ module RDF::RDFa
17
17
  add_debug("expand") {"Repository has #{repository.count} statements"}
18
18
 
19
19
  # Load missing vocabularies
20
- vocabs = repository.query(predicate: RDF::RDFA.usesVocabulary).to_a.map(&:object)
20
+ vocabs = repository.query({predicate: RDF::RDFA.usesVocabulary}).to_a.map(&:object)
21
21
  vocabs.map! do |vocab|
22
22
  begin
23
23
  # Create the name with a predictable name so that it is enumerated and can be found
@@ -297,7 +297,7 @@ module RDF::RDFa
297
297
  # @yieldparam [RDF::Reader] reader
298
298
  # @yieldreturn [void] ignored
299
299
  # @raise [RDF::ReaderError] if _validate_
300
- def initialize(input = $stdin, options = {}, &block)
300
+ def initialize(input = $stdin, **options, &block)
301
301
  super do
302
302
  @options = {reference_folding: true}.merge(@options)
303
303
  @repository = RDF::Repository.new
@@ -327,7 +327,7 @@ module RDF::RDFa
327
327
  end
328
328
  self.extend(@implementation)
329
329
 
330
- detect_host_language_version(input, options)
330
+ detect_host_language_version(input, **options)
331
331
 
332
332
  parse_lib = if @library == :nokogiri && @host_language == :html5
333
333
  begin
@@ -344,7 +344,7 @@ module RDF::RDFa
344
344
  add_info(@doc, "version = #{@version}, host_language = #{@host_language}, library = #{parse_lib}, rdfagraph = #{@options[:rdfagraph].inspect}, expand = #{@options[:vocab_expansion]}")
345
345
 
346
346
  begin
347
- initialize_xml(input, options)
347
+ initialize_xml(input, **options)
348
348
  rescue
349
349
  add_error(nil, "Malformed document: #{$!.message}")
350
350
  end
@@ -381,6 +381,38 @@ module RDF::RDFa
381
381
  end
382
382
  end
383
383
 
384
+ ##
385
+ # Extracts RDF from script element, or embeded RDF/XML
386
+ def extract_script(el, input, type, **options, &block)
387
+ add_debug(el, "script element of type #{type}")
388
+ begin
389
+ # Formats don't exist unless they've been required
390
+ case type.to_s
391
+ when 'application/csvm+json' then require 'rdf/tabular'
392
+ when 'application/ld+json' then require 'json/ld'
393
+ when 'application/rdf+xml' then require 'rdf/rdfxml'
394
+ when 'text/ntriples' then require 'rdf/ntriples'
395
+ when 'text/turtle' then require 'rdf/turtle'
396
+ end
397
+ rescue LoadError
398
+ end
399
+
400
+ @readers ||= {}
401
+ reader = @readers[type.to_s] = RDF::Reader.for(content_type: type.to_s) unless @readers.has_key?(type.to_s)
402
+ if reader = @readers[type.to_s]
403
+ add_debug(el, "=> reader #{reader.to_sym}")
404
+ # Wrap input in a RemoteDocument with appropriate content-type and base
405
+ doc = if input.is_a?(String)
406
+ RDF::Util::File::RemoteDocument.new(input, content_type: type.to_s, **options)
407
+ else
408
+ input
409
+ end
410
+ reader.new(doc, **options).each(&block)
411
+ else
412
+ add_debug(el, "=> no reader found")
413
+ end
414
+ end
415
+
384
416
  ##
385
417
  # Iterates the given block for each RDF statement in the input.
386
418
  #
@@ -400,52 +432,9 @@ module RDF::RDFa
400
432
  # parse
401
433
  parse_whole_document(@doc, RDF::URI(base_uri))
402
434
 
403
- def extract_script(el, input, type, options, &block)
404
- add_debug(el, "script element of type #{type}")
405
- begin
406
- # Formats don't exist unless they've been required
407
- case type.to_s
408
- when 'application/csvm+json' then require 'rdf/tabular'
409
- when 'application/ld+json' then require 'json/ld'
410
- when 'application/rdf+xml' then require 'rdf/rdfxml'
411
- when 'text/ntriples' then require 'rdf/ntriples'
412
- when 'text/turtle' then require 'rdf/turtle'
413
- end
414
- rescue LoadError
415
- end
416
-
417
- if reader = RDF::Reader.for(content_type: type.to_s)
418
- add_debug(el, "=> reader #{reader.to_sym}")
419
- # Wrap input in a RemoteDocument with appropriate content-type and base
420
- doc = if input.is_a?(String)
421
- RDF::Util::File::RemoteDocument.new(input,
422
- options.merge(
423
- content_type: type.to_s,
424
- base_uri: base_uri
425
- ))
426
- else
427
- input
428
- end
429
- reader.new(doc, options).each(&block)
430
- else
431
- add_debug(el, "=> no reader found")
432
- end
433
- end
434
-
435
435
  # Look for Embedded RDF/XML
436
436
  unless @root.xpath("//rdf:RDF", "rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#").empty?
437
- extract_script(@root, @doc, "application/rdf+xml", @options) do |statement|
438
- @repository << statement
439
- end
440
- end
441
-
442
- # Look for Embedded scripts
443
- @root.css("script[type]").each do |el|
444
- type = el.attribute("type")
445
-
446
- text = el.inner_html.sub(%r(\A\s*\<!\[CDATA\[)m, '').sub(%r(\]\]>\s*\Z)m, '')
447
-
448
- extract_script(el, text, type, @options) do |statement|
437
+ extract_script(@root, @doc, "application/rdf+xml", **@options.merge(base_uri: base_uri)) do |statement|
449
438
  @repository << statement
450
439
  end
451
440
  end
@@ -455,7 +444,7 @@ module RDF::RDFa
455
444
  begin
456
445
  require 'rdf/microdata'
457
446
  add_debug(@doc, "process microdata")
458
- @repository << RDF::Microdata::Reader.new(@doc, options)
447
+ @repository << RDF::Microdata::Reader.new(@doc, **options)
459
448
  rescue LoadError
460
449
  add_debug(@doc, "microdata detected, not processed")
461
450
  end
@@ -775,6 +764,7 @@ module RDF::RDFa
775
764
  rev
776
765
  role
777
766
  src
767
+ type
778
768
  typeof
779
769
  value
780
770
  vocab
@@ -830,6 +820,15 @@ module RDF::RDFa
830
820
  language = nil if language.to_s.empty?
831
821
  add_debug(element) {"HTML5 [3.2.3.3] lang: #{language.inspect}"} if language
832
822
 
823
+ # Embedded scripts
824
+ if element.name == 'script'
825
+ text = element.inner_html.sub(%r(\A\s*\<!\[CDATA\[)m, '').sub(%r(\]\]>\s*\Z)m, '')
826
+
827
+ extract_script(element, text, attrs[:type], **@options.merge(base_uri: base)) do |statement|
828
+ @repository << statement
829
+ end
830
+ end
831
+
833
832
  # From HTML5, if the property attribute and the rel and/or rev attribute exists on the same element, the non-CURIE and non-URI rel and rev values are ignored. If, after this, the value of rel and/or rev becomes empty, then the processor must act as if the respective attribute is not present.
834
833
  if [:html5, :xhtml5].include?(@host_language) && attrs[:property] && (attrs[:rel] || attrs[:rev])
835
834
  old_rel, old_rev = attrs[:rel], attrs[:rev]
@@ -1392,13 +1391,13 @@ module RDF::RDFa
1392
1391
  end
1393
1392
 
1394
1393
  # space-separated TERMorCURIEorAbsIRI or SafeCURIEorCURIEorIRI
1395
- def process_uris(element, value, evaluation_context, base, options)
1394
+ def process_uris(element, value, evaluation_context, base, **options)
1396
1395
  return [] if value.to_s.empty?
1397
1396
  add_debug(element) {"process_uris: #{value}"}
1398
- value.to_s.split(/\s+/).map {|v| process_uri(element, v, evaluation_context, base, options)}.compact
1397
+ value.to_s.split(/\s+/).map {|v| process_uri(element, v, evaluation_context, base, **options)}.compact
1399
1398
  end
1400
1399
 
1401
- def process_uri(element, value, evaluation_context, base, options = {})
1400
+ def process_uri(element, value, evaluation_context, base, **options)
1402
1401
  return if value.nil?
1403
1402
  restrictions = options[:restrictions]
1404
1403
  add_debug(element) {"process_uri: #{value}, restrictions = #{restrictions.inspect}"}
@@ -1419,7 +1418,7 @@ module RDF::RDFa
1419
1418
  # TERMorCURIEorAbsIRI
1420
1419
  # If the value is an NCName, then it is evaluated as a term according to General Use of Terms in
1421
1420
  # Attributes. Note that this step may mean that the value is to be ignored.
1422
- uri = process_term(element, value.to_s, options)
1421
+ uri = process_term(element, value.to_s, **options)
1423
1422
  add_debug(element) {"process_uri: #{value} => term => #{uri ? uri.to_base : 'nil'}"}
1424
1423
  uri
1425
1424
  else
@@ -1458,7 +1457,7 @@ module RDF::RDFa
1458
1457
  end
1459
1458
 
1460
1459
  # [7.4.3] General Use of Terms in Attributes
1461
- def process_term(element, value, options)
1460
+ def process_term(element, value, **options)
1462
1461
  if options[:vocab]
1463
1462
  # If there is a local default vocabulary, the IRI is obtained by concatenating that value and the term
1464
1463
  return uri(options[:vocab] + value)
@@ -35,12 +35,10 @@ module RDF::RDFa
35
35
  # @return [String]
36
36
  def language
37
37
  language = case
38
- when @node.document.is_a?(::Nokogiri::HTML::Document) && @node.attributes["xml:lang"]
39
- @node.attributes["xml:lang"].to_s
40
- when @node.document.is_a?(::Nokogiri::HTML::Document) && @node.attributes["lang"]
41
- @node.attributes["lang"].to_s
42
38
  when @node.attribute_with_ns("lang", RDF::XML.to_s)
43
39
  @node.attribute_with_ns("lang", RDF::XML.to_s)
40
+ when @node.attribute("xml:lang")
41
+ @node.attribute("xml:lang").to_s
44
42
  when @node.attribute("lang")
45
43
  @node.attribute("lang").to_s
46
44
  end
@@ -51,7 +49,7 @@ module RDF::RDFa
51
49
  #
52
50
  # @return [String]
53
51
  def base
54
- @node.attribute_with_ns("base", RDF::XML.to_s)
52
+ @node.attribute_with_ns("base", RDF::XML.to_s) || @node.attribute('xml:base')
55
53
  end
56
54
 
57
55
  def display_path
@@ -160,7 +158,7 @@ module RDF::RDFa
160
158
  #
161
159
  # @param [Hash{Symbol => Object}] options
162
160
  # @return [void]
163
- def initialize_xml(input, options = {})
161
+ def initialize_xml(input, **options)
164
162
  require 'nokogiri' unless defined?(::Nokogiri)
165
163
  @doc = case input
166
164
  when ::Nokogiri::HTML::Document, ::Nokogiri::XML::Document
@@ -191,7 +189,7 @@ module RDF::RDFa
191
189
  end
192
190
 
193
191
  # Determine the host language and/or version from options and the input document
194
- def detect_host_language_version(input, options)
192
+ def detect_host_language_version(input, **options)
195
193
  @host_language = options[:host_language] ? options[:host_language].to_sym : nil
196
194
  @version = options[:version] ? options[:version].to_sym : nil
197
195
  return if @host_language && @version
@@ -202,8 +200,6 @@ module RDF::RDFa
202
200
  doc_type_string = input.children.detect {|c| c.is_a?(::Nokogiri::XML::DTD)}
203
201
  version_attr = input.root && input.root.attribute("version").to_s
204
202
  root_element = input.root.name.downcase
205
- root_namespace = input.root.namespace.to_s
206
- root_attrs = input.root.attributes
207
203
  content_type = case
208
204
  when root_element == "html" && input.is_a?(::Nokogiri::HTML::Document)
209
205
  "text/html"
@@ -226,7 +222,7 @@ module RDF::RDFa
226
222
  doc_type_string = head.match(%r(<!DOCTYPE[^>]*>)m).to_s
227
223
  root = head.match(%r(<[^!\?>]*>)m).to_s
228
224
  root_element = root.match(%r(^<(\S+)[ >])) ? $1 : ""
229
- version_attr = root.match(/version\s+=\s+(\S+)[\s">]/m) ? $1 : ""
225
+ version_attr = root.match(/version\s*=\s*"([^"]+)"/m) ? $1 : ""
230
226
  head_element = head.match(%r(<head.*<\/head>)mi)
231
227
  head_doc = ::Nokogiri::HTML.parse(head_element.to_s)
232
228
 
@@ -308,7 +304,7 @@ module RDF::RDFa
308
304
  base_el = @doc.at_css("html>head>base")
309
305
  base = base.join(base_el.attribute("href").to_s.split("#").first) if base_el
310
306
  else
311
- xml_base = root.attribute_with_ns("base", RDF::XML.to_s) if root
307
+ xml_base = root.attribute_with_ns("base", RDF::XML.to_s) || root.attribute('xml:base') if root
312
308
  base = base.join(xml_base) if xml_base
313
309
  end
314
310
 
@@ -39,6 +39,8 @@ module RDF::RDFa
39
39
  language = case
40
40
  when @node.attribute("lang", RDF::XML.to_s)
41
41
  @node.attribute("lang", RDF::XML.to_s)
42
+ when @node.attribute("xml:lang")
43
+ @node.attribute("xml:lang").to_s
42
44
  when @node.attribute("lang")
43
45
  @node.attribute("lang").to_s
44
46
  end
@@ -49,7 +51,7 @@ module RDF::RDFa
49
51
  #
50
52
  # @return [String]
51
53
  def base
52
- @node.attribute("base", RDF::XML.to_s)
54
+ @node.attribute("base", RDF::XML.to_s) || @node.attribute('xml:base')
53
55
  end
54
56
 
55
57
  def display_path
@@ -206,7 +208,7 @@ module RDF::RDFa
206
208
  #
207
209
  # @param [Hash{Symbol => Object}] options
208
210
  # @return [void]
209
- def initialize_xml(input, options = {})
211
+ def initialize_xml(input, **options)
210
212
  require 'rexml/document' unless defined?(::REXML)
211
213
  @doc = case input
212
214
  when ::REXML::Document
@@ -227,7 +229,7 @@ module RDF::RDFa
227
229
  end
228
230
 
229
231
  # Determine the host language and/or version from options and the input document
230
- def detect_host_language_version(input, options)
232
+ def detect_host_language_version(input, **options)
231
233
  @host_language = options[:host_language] ? options[:host_language].to_sym : nil
232
234
  @version = options[:version] ? options[:version].to_sym : nil
233
235
  return if @host_language && @version
@@ -238,8 +240,6 @@ module RDF::RDFa
238
240
  doc_type_string = input.doctype.to_s
239
241
  version_attr = input.root && input.root.attribute("version").to_s
240
242
  root_element = input.root.name.downcase
241
- root_namespace = input.root.namespace.to_s
242
- root_attrs = input.root.attributes
243
243
  content_type = "application/xhtml+html" # FIXME: what about other possible XML types?
244
244
  else
245
245
  content_type = input.content_type if input.respond_to?(:content_type)
@@ -257,7 +257,7 @@ module RDF::RDFa
257
257
  doc_type_string = head.match(%r(<!DOCTYPE[^>]*>)m).to_s
258
258
  root = head.match(%r(<[^!\?>]*>)m).to_s
259
259
  root_element = root.match(%r(^<(\S+)[ >])) ? $1 : ""
260
- version_attr = root.match(/version\s+=\s+(\S+)[\s">]/m) ? $1 : ""
260
+ version_attr = root.match(/version\s*=\s*"([^"]+)"/m) ? $1 : ""
261
261
  head_element = head.match(%r(<head.*<\/head>)mi)
262
262
  head_doc = ::REXML::Document.new(head_element.to_s)
263
263
 
@@ -331,7 +331,7 @@ module RDF::RDFa
331
331
  base_el = ::REXML::XPath.first(@doc, "/html/head/base") rescue nil
332
332
  base = base.join(base_el.attribute("href").to_s.split("#").first) if base_el
333
333
  else
334
- xml_base = root.attribute("base", RDF::XML.to_s) if root
334
+ xml_base = root.attribute("base", RDF::XML.to_s) || root.attribute('xml:base') if root
335
335
  base = base.join(xml_base) if xml_base
336
336
  end
337
337
 
@@ -116,7 +116,7 @@ module RDF::RDFa
116
116
  # Options to pass to Haml::Engine.new.
117
117
  # @yield [writer]
118
118
  # @yieldparam [RDF::Writer] writer
119
- def initialize(output = $stdout, options = {}, &block)
119
+ def initialize(output = $stdout, **options, &block)
120
120
  super do
121
121
  @uri_to_term_or_curie = {}
122
122
  @uri_to_prefix = {}
@@ -175,7 +175,7 @@ module RDF::RDFa
175
175
  doc_title = nil
176
176
  titles = {}
177
177
  heading_predicates.each do |pred|
178
- @graph.query(predicate: pred) do |statement|
178
+ @graph.query({predicate: pred}) do |statement|
179
179
  titles[statement.subject] ||= statement.object
180
180
  end
181
181
  end
@@ -220,14 +220,14 @@ module RDF::RDFa
220
220
  # @yieldreturn [:ignored]
221
221
  # @return String
222
222
  # The rendered document is returned as a string
223
- def render_document(subjects, options = {})
223
+ def render_document(subjects, **options)
224
224
  template = options[:haml] || :doc
225
225
  options = {
226
226
  prefix: nil,
227
227
  subjects: subjects,
228
228
  title: nil,
229
229
  }.merge(options)
230
- hamlify(template, options) do |subject|
230
+ hamlify(template, **options) do |subject|
231
231
  yield(subject) if block_given?
232
232
  end.gsub(/^\s+$/m, '')
233
233
  end
@@ -265,7 +265,7 @@ module RDF::RDFa
265
265
  # @return String
266
266
  # The rendered document is returned as a string
267
267
  # Return Haml template for document from `haml_template[:subject]`
268
- def render_subject(subject, predicates, options = {})
268
+ def render_subject(subject, predicates, **options)
269
269
  template = options[:haml] || :subject
270
270
  options = {
271
271
  about: (get_curie(subject) unless options[:rel]),
@@ -278,7 +278,7 @@ module RDF::RDFa
278
278
  subject: subject,
279
279
  typeof: nil,
280
280
  }.merge(options)
281
- hamlify(template, options) do |predicate|
281
+ hamlify(template, **options) do |predicate|
282
282
  yield(predicate) if block_given?
283
283
  end
284
284
  end
@@ -303,7 +303,7 @@ module RDF::RDFa
303
303
  # The block should only return a string for recursive object definitions.
304
304
  # @return String
305
305
  # The rendered document is returned as a string
306
- def render_property(predicate, objects, options = {}, &block)
306
+ def render_property(predicate, objects, **options, &block)
307
307
  log_debug {"render_property(#{predicate}): #{objects.inspect}, #{options.inspect}"}
308
308
  # If there are multiple objects, and no :property_values is defined, call recursively with
309
309
  # each object
@@ -319,7 +319,7 @@ module RDF::RDFa
319
319
  unless list_objects.empty?
320
320
  # Render non-list objects
321
321
  log_debug {"properties with lists: #{list_objects} non-lists: #{objects - list_objects}"}
322
- nl = log_depth {render_property(predicate, objects - list_objects, options, &block)} unless objects == list_objects
322
+ nl = log_depth {render_property(predicate, objects - list_objects, **options, &block)} unless objects == list_objects
323
323
  return nl.to_s + list_objects.map do |object|
324
324
  # Render each list as multiple properties and set :inlist to true
325
325
  list = RDF::List.new(subject: object, graph: @graph)
@@ -327,7 +327,7 @@ module RDF::RDFa
327
327
 
328
328
  log_debug {"list: #{list.inspect} #{list.to_a}"}
329
329
  log_depth do
330
- render_property(predicate, list.to_a, options.merge(inlist: "true")) do |object|
330
+ render_property(predicate, list.to_a, **options.merge(inlist: "true")) do |object|
331
331
  yield(object, true) if block_given?
332
332
  end
333
333
  end
@@ -337,7 +337,7 @@ module RDF::RDFa
337
337
  if objects.length > 1 && template.nil?
338
338
  # If there is no property_values template, render each property using property_value template
339
339
  objects.map do |object|
340
- log_depth {render_property(predicate, [object], options, &block)}
340
+ log_depth {render_property(predicate, [object], **options, &block)}
341
341
  end.join(" ")
342
342
  else
343
343
  log_fatal("Missing property template", exception: RDF::WriterError) if template.nil?
@@ -406,7 +406,7 @@ module RDF::RDFa
406
406
  top_classes.
407
407
  select {|s| !seen.include?(s)}.
408
408
  each do |class_uri|
409
- graph.query(predicate: RDF.type, object: class_uri).map {|st| st.subject}.sort.uniq.each do |subject|
409
+ graph.query({predicate: RDF.type, object: class_uri}).map {|st| st.subject}.sort.uniq.each do |subject|
410
410
  #log_debug {"order_subjects: #{subject.inspect}"}
411
411
  subjects << subject
412
412
  seen[subject] = true
@@ -490,7 +490,7 @@ module RDF::RDFa
490
490
  # @option options [RDF::Resource] :rel (nil)
491
491
  # Optional @rel property
492
492
  # @return [String]
493
- def subject(subject, options = {})
493
+ def subject(subject, **options)
494
494
  return if is_done?(subject)
495
495
 
496
496
  subject_done(subject)
@@ -503,14 +503,14 @@ module RDF::RDFa
503
503
 
504
504
  render_opts = {typeof: typeof, property_values: properties}.merge(options)
505
505
 
506
- render_subject_template(subject, prop_list, render_opts)
506
+ render_subject_template(subject, prop_list, **render_opts)
507
507
  end
508
508
 
509
509
  # @param [RDF::Resource] subject
510
510
  # @return [Hash{String => Object}]
511
511
  def properties_for_subject(subject)
512
512
  properties = {}
513
- @graph.query(subject: subject) do |st|
513
+ @graph.query({subject: subject}) do |st|
514
514
  key = st.predicate.to_s.freeze
515
515
  properties[key] ||= []
516
516
  properties[key] << st.object
@@ -545,7 +545,7 @@ module RDF::RDFa
545
545
  # @param [Array] prop_list
546
546
  # @param [Hash] render_opts
547
547
  # @return [String]
548
- def render_subject_template(subject, prop_list, render_opts)
548
+ def render_subject_template(subject, prop_list, **render_opts)
549
549
  # See if there's a template based on the sorted concatenation of all types of this subject
550
550
  # or any type of this subject
551
551
  tmpl = find_template(subject)
@@ -555,7 +555,7 @@ module RDF::RDFa
555
555
  # If :rel is specified and :typeof is nil, use @resource instead of @about.
556
556
  # Pass other options from calling context
557
557
  with_template(tmpl) do
558
- render_subject(subject, prop_list, render_opts) do |pred|
558
+ render_subject(subject, prop_list, **render_opts) do |pred|
559
559
  log_depth do
560
560
  pred = RDF::URI(pred) if pred.is_a?(String)
561
561
  values = render_opts[:property_values][pred.to_s]
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: 3.0.1
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregg
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-02-11 00:00:00.000000000 Z
12
+ date: 2019-12-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdf
@@ -17,62 +17,56 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '3.0'
20
+ version: '3.1'
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: '3.0'
27
+ version: '3.1'
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
- version: '5.0'
34
+ version: '5.1'
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
- version: '5.0'
41
+ version: '5.1'
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: '3.0'
48
+ version: '3.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: '3.0'
55
+ version: '3.1'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rdf-aggregate-repo
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: '2.2'
63
- - - "<"
60
+ - - "~>"
64
61
  - !ruby/object:Gem::Version
65
- version: '4.0'
62
+ version: '3.1'
66
63
  type: :runtime
67
64
  prerelease: false
68
65
  version_requirements: !ruby/object:Gem::Requirement
69
66
  requirements:
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- version: '2.2'
73
- - - "<"
67
+ - - "~>"
74
68
  - !ruby/object:Gem::Version
75
- version: '4.0'
69
+ version: '3.1'
76
70
  - !ruby/object:Gem::Dependency
77
71
  name: htmlentities
78
72
  requirement: !ruby/object:Gem::Requirement
@@ -91,180 +85,156 @@ dependencies:
91
85
  name: json-ld
92
86
  requirement: !ruby/object:Gem::Requirement
93
87
  requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '2.1'
97
- - - "<"
88
+ - - "~>"
98
89
  - !ruby/object:Gem::Version
99
- version: '4.0'
90
+ version: '3.1'
100
91
  type: :development
101
92
  prerelease: false
102
93
  version_requirements: !ruby/object:Gem::Requirement
103
94
  requirements:
104
- - - ">="
105
- - !ruby/object:Gem::Version
106
- version: '2.1'
107
- - - "<"
95
+ - - "~>"
108
96
  - !ruby/object:Gem::Version
109
- version: '4.0'
97
+ version: '3.1'
110
98
  - !ruby/object:Gem::Dependency
111
99
  name: rspec
112
100
  requirement: !ruby/object:Gem::Requirement
113
101
  requirements:
114
102
  - - "~>"
115
103
  - !ruby/object:Gem::Version
116
- version: '3.7'
104
+ version: '3.9'
117
105
  type: :development
118
106
  prerelease: false
119
107
  version_requirements: !ruby/object:Gem::Requirement
120
108
  requirements:
121
109
  - - "~>"
122
110
  - !ruby/object:Gem::Version
123
- version: '3.7'
111
+ version: '3.9'
124
112
  - !ruby/object:Gem::Dependency
125
113
  name: rspec-its
126
114
  requirement: !ruby/object:Gem::Requirement
127
115
  requirements:
128
116
  - - "~>"
129
117
  - !ruby/object:Gem::Version
130
- version: '1.2'
118
+ version: '1.3'
131
119
  type: :development
132
120
  prerelease: false
133
121
  version_requirements: !ruby/object:Gem::Requirement
134
122
  requirements:
135
123
  - - "~>"
136
124
  - !ruby/object:Gem::Version
137
- version: '1.2'
125
+ version: '1.3'
138
126
  - !ruby/object:Gem::Dependency
139
127
  name: rdf-spec
140
128
  requirement: !ruby/object:Gem::Requirement
141
129
  requirements:
142
130
  - - "~>"
143
131
  - !ruby/object:Gem::Version
144
- version: '3.0'
132
+ version: '3.1'
145
133
  type: :development
146
134
  prerelease: false
147
135
  version_requirements: !ruby/object:Gem::Requirement
148
136
  requirements:
149
137
  - - "~>"
150
138
  - !ruby/object:Gem::Version
151
- version: '3.0'
139
+ version: '3.1'
152
140
  - !ruby/object:Gem::Dependency
153
141
  name: rdf-turtle
154
142
  requirement: !ruby/object:Gem::Requirement
155
143
  requirements:
156
144
  - - "~>"
157
145
  - !ruby/object:Gem::Version
158
- version: '3.0'
146
+ version: '3.1'
159
147
  type: :development
160
148
  prerelease: false
161
149
  version_requirements: !ruby/object:Gem::Requirement
162
150
  requirements:
163
151
  - - "~>"
164
152
  - !ruby/object:Gem::Version
165
- version: '3.0'
153
+ version: '3.1'
166
154
  - !ruby/object:Gem::Dependency
167
155
  name: rdf-vocab
168
156
  requirement: !ruby/object:Gem::Requirement
169
157
  requirements:
170
158
  - - "~>"
171
159
  - !ruby/object:Gem::Version
172
- version: '3.0'
160
+ version: '3.1'
173
161
  type: :development
174
162
  prerelease: false
175
163
  version_requirements: !ruby/object:Gem::Requirement
176
164
  requirements:
177
165
  - - "~>"
178
166
  - !ruby/object:Gem::Version
179
- version: '3.0'
167
+ version: '3.1'
180
168
  - !ruby/object:Gem::Dependency
181
169
  name: rdf-isomorphic
182
170
  requirement: !ruby/object:Gem::Requirement
183
171
  requirements:
184
172
  - - "~>"
185
173
  - !ruby/object:Gem::Version
186
- version: '3.0'
174
+ version: '3.1'
187
175
  type: :development
188
176
  prerelease: false
189
177
  version_requirements: !ruby/object:Gem::Requirement
190
178
  requirements:
191
179
  - - "~>"
192
180
  - !ruby/object:Gem::Version
193
- version: '3.0'
181
+ version: '3.1'
194
182
  - !ruby/object:Gem::Dependency
195
183
  name: rdf-tabular
196
184
  requirement: !ruby/object:Gem::Requirement
197
185
  requirements:
198
- - - ">="
199
- - !ruby/object:Gem::Version
200
- version: '2.2'
201
- - - "<"
186
+ - - "~>"
202
187
  - !ruby/object:Gem::Version
203
- version: '4.0'
188
+ version: '3.1'
204
189
  type: :development
205
190
  prerelease: false
206
191
  version_requirements: !ruby/object:Gem::Requirement
207
192
  requirements:
208
- - - ">="
209
- - !ruby/object:Gem::Version
210
- version: '2.2'
211
- - - "<"
193
+ - - "~>"
212
194
  - !ruby/object:Gem::Version
213
- version: '4.0'
195
+ version: '3.1'
214
196
  - !ruby/object:Gem::Dependency
215
197
  name: rdf-rdfxml
216
198
  requirement: !ruby/object:Gem::Requirement
217
199
  requirements:
218
- - - ">="
219
- - !ruby/object:Gem::Version
220
- version: '2.2'
221
- - - "<"
200
+ - - "~>"
222
201
  - !ruby/object:Gem::Version
223
- version: '4.0'
202
+ version: '3.1'
224
203
  type: :development
225
204
  prerelease: false
226
205
  version_requirements: !ruby/object:Gem::Requirement
227
206
  requirements:
228
- - - ">="
229
- - !ruby/object:Gem::Version
230
- version: '2.2'
231
- - - "<"
207
+ - - "~>"
232
208
  - !ruby/object:Gem::Version
233
- version: '4.0'
209
+ version: '3.1'
234
210
  - !ruby/object:Gem::Dependency
235
211
  name: sparql
236
212
  requirement: !ruby/object:Gem::Requirement
237
213
  requirements:
238
- - - ">="
239
- - !ruby/object:Gem::Version
240
- version: '2.2'
241
- - - "<"
214
+ - - "~>"
242
215
  - !ruby/object:Gem::Version
243
- version: '4.0'
216
+ version: '3.1'
244
217
  type: :development
245
218
  prerelease: false
246
219
  version_requirements: !ruby/object:Gem::Requirement
247
220
  requirements:
248
- - - ">="
249
- - !ruby/object:Gem::Version
250
- version: '2.2'
251
- - - "<"
221
+ - - "~>"
252
222
  - !ruby/object:Gem::Version
253
- version: '4.0'
223
+ version: '3.1'
254
224
  - !ruby/object:Gem::Dependency
255
225
  name: yard
256
226
  requirement: !ruby/object:Gem::Requirement
257
227
  requirements:
258
228
  - - "~>"
259
229
  - !ruby/object:Gem::Version
260
- version: 0.9.12
230
+ version: 0.9.20
261
231
  type: :development
262
232
  prerelease: false
263
233
  version_requirements: !ruby/object:Gem::Requirement
264
234
  requirements:
265
235
  - - "~>"
266
236
  - !ruby/object:Gem::Version
267
- version: 0.9.12
237
+ version: 0.9.20
268
238
  description: RDF::RDFa is an RDFa reader/writer for Ruby using the RDF.rb library
269
239
  suite.
270
240
  email: public-rdf-ruby@w3.org
@@ -303,15 +273,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
303
273
  requirements:
304
274
  - - ">="
305
275
  - !ruby/object:Gem::Version
306
- version: 2.2.2
276
+ version: '2.4'
307
277
  required_rubygems_version: !ruby/object:Gem::Requirement
308
278
  requirements:
309
279
  - - ">="
310
280
  - !ruby/object:Gem::Version
311
281
  version: '0'
312
282
  requirements: []
313
- rubyforge_project:
314
- rubygems_version: 2.7.3
283
+ rubygems_version: 3.0.6
315
284
  signing_key:
316
285
  specification_version: 4
317
286
  summary: RDFa reader/writer for RDF.rb.