rdf-rdfa 0.3.8 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,10 @@
1
- # This file is automatically generated by ./script/intern_vocabulary
2
- # RDFa vocabulary for http://www.w3.org/profile/rdfa-1.1
3
-
4
- require 'facets/module'
1
+ # This file is automatically generated by script/intern_profile
2
+ # RDFa profile for ./rdfa-1.1.html
5
3
 
6
4
  class RDF::RDFa::Profile
7
- def self.find_with_rdfa_1_1(uri)
8
- if uri.to_s == "http://www.w3.org/profile/rdfa-1.1"
9
- @_rdfa_1_1_prof ||= RDF::RDFa::Profile.new(RDF::URI("http://www.w3.org/profile/rdfa-1.1"), {
5
+ def self.find_with_rdfa_1_1_html(uri)
6
+ if uri.to_s == "http://www.w3.org/2011/rdfa-context/rdfa-1.1"
7
+ @_rdfa_1_1_html_prof ||= RDF::RDFa::Profile.new(RDF::URI("http://www.w3.org/2011/rdfa-context/rdfa-1.1"), {
10
8
  :prefixes => {
11
9
  :cc => "http://creativecommons.org/ns#",
12
10
  :ctag => "http://commontag.org/ns#",
@@ -22,6 +20,7 @@ class RDF::RDFa::Profile
22
20
  :rdfs => "http://www.w3.org/2000/01/rdf-schema#",
23
21
  :rev => "http://purl.org/stuff/rev#",
24
22
  :rif => "http://www.w3.org/2007/rif#",
23
+ :schema => "http://schema.org/",
25
24
  :sioc => "http://rdfs.org/sioc/ns#",
26
25
  :skos => "http://www.w3.org/2004/02/skos/core#",
27
26
  :skosxl => "http://www.w3.org/2008/05/skos-xl#",
@@ -32,21 +31,23 @@ class RDF::RDFa::Profile
32
31
  :wdrs => "http://www.w3.org/2007/05/powder-s#",
33
32
  :xhv => "http://www.w3.org/1999/xhtml/vocab#",
34
33
  :xml => "http://www.w3.org/XML/1998/namespace",
35
- :xmlns => "http://www.w3.org/2000/xmlns/",
36
34
  :xsd => "http://www.w3.org/2001/XMLSchema#",
37
35
  },
38
36
  :terms => {
39
37
  :describedby => "http://www.w3.org/2007/05/powder-s#describedby",
38
+ :license => "http://www.w3.org/1999/xhtml/vocab#license",
39
+ :role => "http://www.w3.org/1999/xhtml/vocab#role",
40
40
  },
41
41
  })
42
42
  else
43
- find_without_rdfa_1_1(uri)
43
+ find_without_rdfa_1_1_html(uri)
44
44
  end
45
45
  end
46
46
 
47
47
  class << self
48
48
  ##
49
49
  # Override find to return this profile, if matched
50
- alias_method_chain :find, :rdfa_1_1
50
+ alias_method :find_without_rdfa_1_1_html, :find
51
+ alias_method :find, :find_with_rdfa_1_1_html
51
52
  end
52
53
  end
@@ -21,8 +21,9 @@ module RDF::RDFa
21
21
  #
22
22
  # Based on processing rules described here:
23
23
  # @see http://www.w3.org/TR/rdfa-syntax/#s_model RDFa 1.0
24
- # @see http://www.w3.org/TR/2011/WD-rdfa-core-20110331/ RDFa Core 1.1
25
- # @see http://www.w3.org/TR/2011/WD-xhtml-rdfa-20110331/ XHTML+RDFa 1.1
24
+ # @see http://www.w3.org/TR/2011/WD-rdfa-core-20111215/ RDFa Core 1.1
25
+ # @see http://www.w3.org/TR/2011/WD-xhtml-rdfa-20111215/ XHTML+RDFa 1.1
26
+ # @see http://www.w3.org/TR/2011/WD-rdfa-in-html-20110525/ HTML+RDFa 1.1
26
27
  #
27
28
  # @author [Gregg Kellogg](http://kellogg-assoc.com/)
28
29
  class Reader < RDF::Reader
@@ -44,19 +45,40 @@ module RDF::RDFa
44
45
  :"rdfa1.1" => [:term, :curie, :absuri],
45
46
  }
46
47
 
48
+ # This expression matches an NCName as defined in
49
+ # [XML-NAMES](http://www.w3.org/TR/2009/REC-xml-names-20091208/#NT-NCName)
50
+ #
51
+ # @see http://www.w3.org/TR/2009/REC-xml-names-20091208/#NT-NCName
47
52
  NC_REGEXP = Regexp.new(
48
53
  %{^
49
54
  (?!\\\\u0301) # &#x301; is a non-spacing acute accent.
50
55
  # It is legal within an XML Name, but not as the first character.
51
56
  ( [a-zA-Z_]
52
- | \\\\u[0-9a-fA-F]
57
+ | \\\\u[0-9a-fA-F]{4}
58
+ )
59
+ ( [0-9a-zA-Z_\.-/]
60
+ | \\\\u([0-9a-fA-F]{4})
61
+ )*
62
+ $},
63
+ Regexp::EXTENDED)
64
+
65
+ # This expression matches an term as defined in
66
+ # [RDFA-CORE](http://www.w3.org/TR/2011/WD-rdfa-core-20111215/#s_terms)
67
+ #
68
+ # @see http://www.w3.org/TR/2011/WD-rdfa-core-20111215/#s_terms
69
+ TERM_REGEXP = Regexp.new(
70
+ %{^
71
+ (?!\\\\u0301) # &#x301; is a non-spacing acute accent.
72
+ # It is legal within an XML Name, but not as the first character.
73
+ ( [a-zA-Z_]
74
+ | \\\\u[0-9a-fA-F]{4}
53
75
  )
54
76
  ( [0-9a-zA-Z_\.-]
55
77
  | \\\\u([0-9a-fA-F]{4})
56
78
  )*
57
79
  $},
58
80
  Regexp::EXTENDED)
59
-
81
+
60
82
  # Host language
61
83
  # @attr [:xml1, :xhtml1, :xhtml5, :html4, :html5, :svg]
62
84
  attr_reader :host_language
@@ -253,6 +275,9 @@ module RDF::RDFa
253
275
  self.extend(@implementation)
254
276
 
255
277
  detect_host_language_version(input, options)
278
+
279
+ add_info(@doc, "version = #{@version}, host_language = #{@host_language}, library = #{@library}")
280
+
256
281
  initialize_xml(input, options) rescue raise RDF::ReaderError.new($!.message)
257
282
 
258
283
  if (root.nil? && validate?)
@@ -263,11 +288,11 @@ module RDF::RDFa
263
288
 
264
289
  # Section 4.2 RDFa Host Language Conformance
265
290
  #
266
- # The Host Language may require the automatic inclusion of one or more default RDFa Profiles.
291
+ # The Host Language may require the automatic inclusion of one or more Initial Contexts
267
292
  @host_defaults = {
268
- :vocabulary => nil,
269
- :uri_mappings => {},
270
- :profiles => [],
293
+ :vocabulary => nil,
294
+ :uri_mappings => {},
295
+ :initial_contexts => [],
271
296
  }
272
297
 
273
298
  if @version == :"rdfa1.0"
@@ -280,13 +305,13 @@ module RDF::RDFa
280
305
 
281
306
  case @host_language
282
307
  when :xml1, :svg
283
- @host_defaults[:profiles] = [XML_RDFA_PROFILE]
284
- when :xhtml1, :xhtml5, :html4, :html5
285
- @host_defaults[:profiles] = [XML_RDFA_PROFILE, XHTML_RDFA_PROFILE]
308
+ @host_defaults[:initial_contexts] = [XML_RDFA_CONTEXT]
309
+ when :xhtml1
310
+ @host_defaults[:initial_contexts] = [XML_RDFA_CONTEXT, XHTML_RDFA_CONTEXT]
311
+ when :xhtml5, :html4, :html5
312
+ @host_defaults[:initial_contexts] = [XML_RDFA_CONTEXT, HTML_RDFA_CONTEXT]
286
313
  end
287
314
 
288
- add_info(@doc, "version = #{@version}, host_language = #{@host_language}, library = #{@library}")
289
-
290
315
  block.call(self) if block_given?
291
316
  end
292
317
  end
@@ -413,7 +438,7 @@ module RDF::RDFa
413
438
 
414
439
  if @version != :"rdfa1.0"
415
440
  # Process default vocabularies
416
- process_profile(root, @host_defaults[:profiles]) do |which, value|
441
+ load_initial_contexts(@host_defaults[:initial_contexts]) do |which, value|
417
442
  add_debug(root) { "parse_whole_document, #{which}: #{value.inspect}"}
418
443
  case which
419
444
  when :uri_mappings then evaluation_context.uri_mappings.merge!(value)
@@ -430,24 +455,24 @@ module RDF::RDFa
430
455
  # Parse and process URI mappings, Term mappings and a default vocabulary from @profile
431
456
  #
432
457
  # Yields each mapping
433
- def process_profile(element, profiles)
434
- profiles.
458
+ def load_initial_contexts(initial_contexts)
459
+ initial_contexts.
435
460
  map {|uri| uri(uri).normalize}.
436
461
  each do |uri|
437
462
  # Don't try to open ourselves!
438
463
  if base_uri == uri
439
- add_debug(element) {"process_profile: skip recursive profile <#{uri}>"}
464
+ add_debug(root) {"load_initial_contexts: skip recursive profile <#{uri}>"}
440
465
  next
441
466
  end
442
467
 
443
468
  old_debug = RDF::RDFa.debug?
444
469
  begin
445
- add_info(element, "process_profile: load <#{uri}>")
470
+ add_info(root, "load_initial_contexts: load <#{uri}>")
446
471
  RDF::RDFa.debug = false
447
472
  profile = Profile.find(uri)
448
473
  rescue Exception => e
449
474
  RDF::RDFa.debug = old_debug
450
- add_error(element, e.message, RDF::RDFA.ProfileReferenceError)
475
+ add_error(root, e.message, RDF::RDFA.ProfileReferenceError)
451
476
  raise # In case we're not in strict mode, we need to be sure processing stops
452
477
  ensure
453
478
  RDF::RDFa.debug = old_debug
@@ -572,6 +597,7 @@ module RDF::RDFa
572
597
  rev
573
598
  src
574
599
  typeof
600
+ value
575
601
  vocab
576
602
  ).each do |a|
577
603
  attrs[a.to_sym] = element.attributes[a].to_s.strip if element.attributes[a]
@@ -946,22 +972,24 @@ module RDF::RDFa
946
972
  rescue ArgumentError => e
947
973
  add_error(element, e.message)
948
974
  end
949
- elsif attrs[:datetime]
975
+ elsif element.name == 'time'
976
+ # HTML5 support
950
977
  # Lexically scan value and assign appropriate type, otherwise, leave untyped
951
- v = element.attribute('datetime').to_s
952
- datatype = %w(Date Time DateTime Duration).map {|t| RDF::Literal.const_get(t)}.detect do |dt|
978
+ v = (attrs[:datetime] || element.inner_text).to_s
979
+ datatype = %w(Date Time DateTime Year YearMonth Duration).map {|t| RDF::Literal.const_get(t)}.detect do |dt|
953
980
  v.match(dt::GRAMMAR)
954
981
  end || RDF::Literal
955
- add_debug(element) {"[Step 11(1.1)] datetime literal: #{v.class}"}
982
+ add_debug(element) {"[Step 11(1.1)] <time> literal: #{datatype} #{v.inspect}"}
956
983
  datatype.new(v)
957
984
  elsif attrs[:content]
958
985
  # plain literal
959
986
  add_debug(element, "[Step 11(1.1)] plain literal (content)")
960
987
  RDF::Literal.new(attrs[:content], :language => language, :validate => validate?, :canonicalize => canonicalize?)
961
- elsif attrs[:value]
988
+ elsif element.name.to_s == 'data' && attrs[:value]
989
+ # HTML5 support
962
990
  # plain literal
963
991
  add_debug(element, "[Step 11(1.1)] plain literal (value)")
964
- RDF::Literal.new(attrs[:value], :validate => validate?, :canonicalize => canonicalize?)
992
+ RDF::Literal.new(attrs[:value], :language => language, :validate => validate?, :canonicalize => canonicalize?)
965
993
  elsif (attrs[:resource] || attrs[:href] || attrs[:src] || attrs[:data]) &&
966
994
  !(attrs[:rel] || attrs[:rev]) &&
967
995
  evaluation_context.incomplete_triples.empty? &&
@@ -220,21 +220,22 @@ module RDF::RDFa
220
220
  when /html 4/i then :html4
221
221
  when /xhtml/i then :xhtml1
222
222
  when /html/i then :html5
223
+ else :html5
223
224
  end
224
225
  when "application/xhtml+xml"
225
226
  case doc_type_string
226
227
  when /html 4/i then :html4
227
228
  when /xhtml/i then :xhtml1
228
229
  when /html/i then :xhtml5
230
+ else :xhtml5
229
231
  end
230
232
  else
231
233
  case root_element
232
234
  when /svg/i then :svg
233
- when /html/i then :html4
235
+ when /html/i then :html5
236
+ else :xml1
234
237
  end
235
238
  end
236
-
237
- @host_language ||= :xml1
238
239
  end
239
240
 
240
241
  # Accessor methods to mask native elements & attributes
@@ -246,21 +246,22 @@ module RDF::RDFa
246
246
  when /html 4/i then :html4
247
247
  when /xhtml/i then :xhtml1
248
248
  when /html/i then :html5
249
+ else :html5
249
250
  end
250
251
  when "application/xhtml+xml"
251
252
  case doc_type_string
252
253
  when /html 4/i then :html4
253
254
  when /xhtml/i then :xhtml1
254
255
  when /html/i then :xhtml5
256
+ else :xhtml5
255
257
  end
256
258
  else
257
259
  case root_element
258
260
  when /svg/i then :svg
259
- when /html/i then :html4
261
+ when /html/i then :html5
262
+ else :xml1
260
263
  end
261
264
  end
262
-
263
- @host_language ||= :xml1
264
265
  end
265
266
 
266
267
  # Accessor methods to mask native elements & attributes
@@ -52,16 +52,16 @@ module RDF::RDFa
52
52
  # @author [Gregg Kellogg](http://kellogg-assoc.com/)
53
53
  class Writer < RDF::Writer
54
54
  format RDF::RDFa::Format
55
-
55
+
56
56
  # Defines rdf:type of subjects to be emitted at the beginning of the document.
57
57
  # @return [Array<URI>]
58
58
  attr :top_classes
59
-
59
+
60
60
  # Defines order of predicates to to emit at begninning of a resource description. Defaults to
61
61
  # [rdf:type, rdfs:label, dc:title]
62
62
  # @return [Array<URI>]
63
63
  attr :predicate_order
64
-
64
+
65
65
  # Defines order of predicates to use in heading.
66
66
  # @return [Array<URI>]
67
67
  attr :heading_predicates
@@ -75,7 +75,7 @@ module RDF::RDFa
75
75
 
76
76
  # @return [RDF::URI] Base URI used for relativizing URIs
77
77
  attr_accessor :base_uri
78
-
78
+
79
79
  ##
80
80
  # Initializes the RDFa writer instance.
81
81
  #
@@ -177,7 +177,7 @@ module RDF::RDFa
177
177
  add_debug {"\nserialize: prefixes: #{prefix.inspect}"}
178
178
 
179
179
  subjects = order_subjects
180
-
180
+
181
181
  # Take title from first subject having a heading predicate
182
182
  doc_title = nil
183
183
  titles = {}
@@ -221,7 +221,7 @@ module RDF::RDFa
221
221
  #
222
222
  # @param [Array<RDF::Resource>] subjects
223
223
  # Ordered list of subjects. Template must yield to each subject, which returns
224
- # the serialization of that subject (@see subject_template)
224
+ # the serialization of that subject (@see #subject_template)
225
225
  # @param [Hash{Symbol => Object}] options Rendering options passed to Haml render.
226
226
  # @option options [RDF::URI] base (nil)
227
227
  # Base URI added to document, used for shortening URIs within the document.
@@ -251,39 +251,30 @@ module RDF::RDFa
251
251
  yield(subject) if block_given?
252
252
  end
253
253
  end
254
-
254
+
255
255
  # Render a subject using haml_template[:subject].
256
256
  #
257
257
  # The _subject_ template may be called either as a top-level element, or recursively under another element
258
258
  # if the _rel_ local is not nil.
259
259
  #
260
- # Yields each predicate/property to be rendered separately (@see render_property_value and
261
- # render_property_values).
260
+ # Yields each predicate/property to be rendered separately (@see #render_property_value and
261
+ # {#render_property_values}).
262
262
  #
263
263
  # The default Haml template is:
264
264
  # - if element == :li
265
- # %li{:about => resource, :typeof => typeof}
265
+ # %li{:rel => rel, :resource => (about || resource), :typeof => typeof, :inlist => inlist}
266
266
  # - if typeof
267
267
  # %span.type!= typeof
268
268
  # - predicates.each do |predicate|
269
269
  # != yield(predicate)
270
- # - elsif rel && typeof
271
- # %div{:rel => rel}
272
- # %div{:about => about, :typeof => typeof}
273
- # %span.type!= typeof
274
- # - predicates.each do |predicate|
275
- # != yield(predicate)
276
- # - elsif rel
277
- # %div{:rel => rel, :resource => resource}
278
- # - predicates.each do |predicate|
279
- # != yield(predicate)
280
270
  # - else
281
- # %div{:about => about, :typeof => typeof}
271
+ # %div{:rel => rel, :resource => (about || resource), :typeof => typeof, :inlist => inlist}
282
272
  # - if typeof
283
273
  # %span.type!= typeof
284
274
  # - predicates.each do |predicate|
285
275
  # != yield(predicate)
286
276
  #
277
+ #
287
278
  # @param [Array<RDF::Resource>] subject
288
279
  # Subject to render
289
280
  # @param [Array<RDF::Resource>] predicates
@@ -328,7 +319,7 @@ module RDF::RDFa
328
319
  yield(predicate) if block_given?
329
320
  end
330
321
  end
331
-
322
+
332
323
  # Render a single- or multi-valued predicate using haml_template[:property_value] or haml_template[:property_values].
333
324
  # Yields each object for optional rendering. The block should only
334
325
  # render for recursive subject definitions (i.e., where the object
@@ -346,9 +337,9 @@ module RDF::RDFa
346
337
  # - elsif get_curie(object) == 'rdf:nil'
347
338
  # %span{:rel => get_curie(predicate), :inlist => ''}
348
339
  # - elsif object.node?
349
- # %span{:resource => get_curie(object), :rel => get_curie(predicate), :inlist => inlist}= get_curie(object)
340
+ # %span{:property => get_curie(predicate), :resource => get_curie(object), :inlist => inlist}= get_curie(object)
350
341
  # - elsif object.uri?
351
- # %a{:href => object.to_s, :rel => get_curie(predicate), :inlist => inlist}= object.to_s
342
+ # %a{:property => get_curie(predicate), :href => object.to_s, :inlist => inlist}= object.to_s
352
343
  # - elsif object.datatype == RDF.XMLLiteral
353
344
  # %span{:property => get_curie(predicate), :lang => get_lang(object), :datatype => get_dt_curie(object), :inlist => inlist}<!= get_value(object)
354
345
  # - else
@@ -364,10 +355,10 @@ module RDF::RDFa
364
355
  # - if res = yield(object)
365
356
  # != res
366
357
  # - elsif object.node?
367
- # %li{:rel => get_curie(predicate), :resource => get_curie(object), :inlist => inlist}= get_curie(object)
358
+ # %li{:property => get_curie(predicate), :resource => get_curie(object), :inlist => inlist}= get_curie(object)
368
359
  # - elsif object.uri?
369
360
  # %li
370
- # %a{:rel => get_curie(predicate), :href => object.to_s, :inlist => inlist}= object.to_s
361
+ # %a{:property => get_curie(predicate), :href => object.to_s, :inlist => inlist}= object.to_s
371
362
  # - elsif object.datatype == RDF.XMLLiteral
372
363
  # %li{:property => get_curie(predicate), :lang => get_lang(object), :datatype => get_curie(object.datatype), :inlist => inlist}<!= get_value(object)
373
364
  # - else
@@ -397,7 +388,7 @@ module RDF::RDFa
397
388
  add_debug {"render_property(#{predicate}): #{objects.inspect}"}
398
389
  # If there are multiple objects, and no :property_values is defined, call recursively with
399
390
  # each object
400
-
391
+
401
392
  template = options[:haml]
402
393
  template ||= objects.length > 1 ? haml_template[:property_values] : haml_template[:property_value]
403
394
 
@@ -411,7 +402,7 @@ module RDF::RDFa
411
402
  # Render each list as multiple properties and set :inlist to true
412
403
  list = RDF::List.new(object, @graph)
413
404
  list.each_statement {|st| subject_done(st.subject)}
414
-
405
+
415
406
  add_debug {"list: #{list.inspect} #{list.to_a}"}
416
407
  render_property(predicate, list.to_a, options.merge(:inlist => ""), &block)
417
408
  end.join(" ")
@@ -443,36 +434,36 @@ module RDF::RDFa
443
434
  end
444
435
  end
445
436
  end
446
-
437
+
447
438
  # Perform any preprocessing of statements required
448
439
  # @return [ignored]
449
440
  def preprocess
450
- # Load default profiles
441
+ # Load initial contexts
451
442
  # Add terms and prefixes to local store for converting URIs
452
443
  # Keep track of vocabulary from left-most profile
453
- [XML_RDFA_PROFILE, XHTML_RDFA_PROFILE].each do |uri|
444
+ [XML_RDFA_CONTEXT, HTML_RDFA_CONTEXT].each do |uri|
454
445
  prof = Profile.find(uri)
455
446
  prof.prefixes.each_pair do |k, v|
456
447
  @uri_to_prefix[v] = k
457
448
  end
458
-
449
+
459
450
  prof.terms.each_pair do |k, v|
460
451
  @uri_to_term_or_curie[v] = k
461
452
  end
462
-
453
+
463
454
  @vocabulary = prof.vocabulary.to_s if prof.vocabulary
464
455
  end
465
-
456
+
466
457
  # Load defined prefixes
467
458
  (@options[:prefixes] || {}).each_pair do |k, v|
468
459
  @uri_to_prefix[v.to_s] = k
469
460
  end
470
461
  @options[:prefixes] = {} # Will define actual used when matched
471
-
462
+
472
463
  # Process each statement to establish CURIEs and Terms
473
464
  @graph.each {|statement| preprocess_statement(statement)}
474
465
  end
475
-
466
+
476
467
  # Order subjects for output. Override this to output subjects in another order.
477
468
  #
478
469
  # Uses #top_classes and #base_uri.
@@ -480,13 +471,13 @@ module RDF::RDFa
480
471
  def order_subjects
481
472
  seen = {}
482
473
  subjects = []
483
-
474
+
484
475
  # Start with base_uri
485
476
  if base_uri && @subjects.keys.include?(base_uri)
486
477
  subjects << base_uri
487
478
  seen[base_uri] = true
488
479
  end
489
-
480
+
490
481
  # Add distinguished classes
491
482
  top_classes.
492
483
  select {|s| !seen.include?(s)}.
@@ -497,18 +488,18 @@ module RDF::RDFa
497
488
  seen[subject] = true
498
489
  end
499
490
  end
500
-
491
+
501
492
  # Sort subjects by resources over nodes, ref_counts and the subject URI itself
502
493
  recursable = @subjects.keys.
503
494
  select {|s| !seen.include?(s)}.
504
495
  map {|r| [r.is_a?(RDF::Node) ? 1 : 0, ref_count(r), r]}.
505
496
  sort
506
-
497
+
507
498
  add_debug {"order_subjects: #{recursable.inspect}"}
508
499
 
509
500
  subjects += recursable.map{|r| r.last}
510
501
  end
511
-
502
+
512
503
  # Take a hash from predicate uris to lists of values.
513
504
  # Sort the lists of values. Return a sorted list of properties.
514
505
  #
@@ -517,17 +508,17 @@ module RDF::RDFa
517
508
  def order_properties(properties)
518
509
  # Make sorted list of properties
519
510
  prop_list = []
520
-
511
+
521
512
  predicate_order.each do |prop|
522
513
  next unless properties[prop.to_s]
523
514
  prop_list << prop.to_s
524
515
  end
525
-
516
+
526
517
  properties.keys.sort.each do |prop|
527
518
  next if prop_list.include?(prop.to_s)
528
519
  prop_list << prop.to_s
529
520
  end
530
-
521
+
531
522
  add_debug {"order_properties: #{prop_list.join(', ')}"}
532
523
  prop_list
533
524
  end
@@ -546,7 +537,7 @@ module RDF::RDFa
546
537
  get_curie(statement.object)
547
538
  get_curie(statement.object.datatype) if statement.object.literal? && statement.object.has_datatype?
548
539
  end
549
-
540
+
550
541
  # Reset parser to run again
551
542
  def reset
552
543
  @depth = 0
@@ -580,16 +571,16 @@ module RDF::RDFa
580
571
  # @return [Nokogiri::XML::Element, {Namespace}]
581
572
  def subject(subject, options = {})
582
573
  return if is_done?(subject)
583
-
574
+
584
575
  subject_done(subject)
585
-
576
+
586
577
  properties = {}
587
578
  @graph.query(:subject => subject) do |st|
588
579
  properties[st.predicate.to_s] ||= []
589
580
  properties[st.predicate.to_s] << st.object
590
581
  end
591
582
  prop_list = order_properties(properties)
592
-
583
+
593
584
  # Find appropriate template
594
585
  curie ||= case
595
586
  when subject.node?
@@ -604,7 +595,7 @@ module RDF::RDFa
604
595
 
605
596
  typeof = [properties.delete(RDF.type.to_s)].flatten.compact.map {|r| get_curie(r)}.join(" ")
606
597
  typeof = nil if typeof.empty?
607
-
598
+
608
599
  # Nodes without a curie need a blank @typeof to generate a subject
609
600
  typeof ||= "" unless curie
610
601
  prop_list -= [RDF.type.to_s]
@@ -627,7 +618,7 @@ module RDF::RDFa
627
618
  end
628
619
  end
629
620
  end
630
-
621
+
631
622
  # Write a predicate with one or more values.
632
623
  #
633
624
  # Values may be a combination of Literal and Resource (Node or URI).
@@ -638,9 +629,9 @@ module RDF::RDFa
638
629
  # @return [String]
639
630
  def predicate(predicate, objects)
640
631
  add_debug {"predicate: #{predicate.inspect}, objects: #{objects}"}
641
-
632
+
642
633
  return if objects.to_a.empty?
643
-
634
+
644
635
  add_debug {"predicate: #{get_curie(predicate)}"}
645
636
  render_property(predicate, objects) do |o|
646
637
  # Yields each object, for potential recursive definition.
@@ -648,7 +639,7 @@ module RDF::RDFa
648
639
  depth {subject(o, :rel => get_curie(predicate), :element => (:li if objects.length > 1))} if !is_done?(o) && @subjects.include?(o)
649
640
  end
650
641
  end
651
-
642
+
652
643
  # Haml rendering helper. Return CURIE for the literal datatype, if the literal is a typed literal.
653
644
  #
654
645
  # @param [RDF::Resource] resource
@@ -749,7 +740,7 @@ module RDF::RDFa
749
740
  add_debug {"get_curie(#{uri}): none"}
750
741
  uri
751
742
  end
752
-
743
+
753
744
  #add_debug {"get_curie(#{resource}) => #{curie}"}
754
745
 
755
746
  @uri_to_term_or_curie[uri] = curie
@@ -757,7 +748,7 @@ module RDF::RDFa
757
748
  raise RDF::WriterError, "Invalid URI #{uri.inspect}: #{e.message}"
758
749
  end
759
750
  private
760
-
751
+
761
752
  ##
762
753
  # Haml rendering helper. Escape entities to avoid whitespace issues.
763
754
  #
@@ -777,7 +768,7 @@ module RDF::RDFa
777
768
  @depth -= 1
778
769
  ret
779
770
  end
780
-
771
+
781
772
  # Set the template to use within block
782
773
  def with_template(templ)
783
774
  if templ
@@ -792,10 +783,10 @@ module RDF::RDFa
792
783
  res = yield
793
784
  # Restore template
794
785
  @haml_template = old_template
795
-
786
+
796
787
  res
797
788
  end
798
-
789
+
799
790
  # Render HAML
800
791
  # @param [Symbol, String] template
801
792
  # If a symbol, finds a matching template from haml_template, otherwise uses template as is
@@ -821,7 +812,7 @@ module RDF::RDFa
821
812
  end
822
813
 
823
814
  ##
824
- # Find a template appropriate for the subject.
815
+ # Find a template appropriate for the subject.
825
816
  # Override this method to provide templates based on attributes of a given subject
826
817
  #
827
818
  # @param [RDF::URI] subject
@@ -832,7 +823,7 @@ module RDF::RDFa
832
823
  def subject_done(subject)
833
824
  @serialized[subject] = true
834
825
  end
835
-
826
+
836
827
  def is_done?(subject)
837
828
  @serialized.include?(subject)
838
829
  end