Skip to content
Browse files

Fix issue with anonymous nodes in relations

  • Loading branch information...
1 parent 9c11885 commit 35c450404c0019f3613bac22221ad23b6a97aa42 @bergie committed Nov 30, 2012
Showing with 62 additions and 15 deletions.
  1. +20 −3 src/service/RdfaService.js
  2. +22 −12 test/index.html
  3. +20 −0 test/service/rdfa.js
View
23 src/service/RdfaService.js
@@ -30,11 +30,15 @@ VIE.prototype.RdfaService = function(options) {
subjectSelector : "[about],[typeof],[src],html",
predicateSelector : "[property],[rel]",
/* default rules that are shipped with this service */
- rules : []
+ rules : [],
+ bnodePrefix: '_a'
};
/* the options are merged with the default options */
this.options = jQuery.extend(true, defaults, options ? options : {});
+ // Counter for bnodes created by this service instance
+ this.bnodes = 0;
+
this.views = [];
this.templates = {};
@@ -418,7 +422,13 @@ VIE.prototype.RdfaService.prototype = {
return null;
},
- getElementSubject : function(element) {
+ _generatebnodeId: function () {
+ var newId = this.options.bnodePrefix + ':' + this.bnodes;
+ this.bnodes++;
+ return newId;
+ },
+
+ getElementSubject : function(element, allowTypeOf) {
var service = this;
if (typeof document !== 'undefined') {
if (element === document) {
@@ -438,6 +448,13 @@ VIE.prototype.RdfaService.prototype = {
return true;
}
if (jQuery(this).attr('typeof') !== service.options.attributeExistenceComparator) {
+ var typeElement = jQuery(this);
+ if (typeElement.data('vie-bnode')) {
+ subject = typeElement.data('vie-bnode');
+ return true;
+ }
+ subject = service._generatebnodeId();
+ typeElement.data('vie-bnode', subject);
return true;
}
// We also handle baseURL outside browser context by manually
@@ -617,7 +634,7 @@ VIE.prototype.RdfaService.prototype = {
var value = [];
var service = this;
jQuery(element).children(this.options.subjectSelector).each(function() {
- value.push(service.getElementSubject(this));
+ value.push(service.getElementSubject(this, true));
});
return value;
}
View
34 test/index.html
@@ -166,21 +166,31 @@ <h2 property="title">Content</h2>
</div>
</div>
<div class="rdfa-datatypes">
- <div about="http://example.net/datatypes">
- <div property="boolean" datatype="xsd:boolean" content="false">False</div>
- <div property="boolean2" datatype="xsd:boolean" content="true">Yes</div>
- <div property="date" datatype="xsd:dateTime" content="2012-09-05T16:30:00Z">Back in September</div>
+ <div about="http://example.net/datatypes">
+ <div property="boolean" datatype="xsd:boolean" content="false">False</div>
+ <div property="boolean2" datatype="xsd:boolean" content="true">Yes</div>
+ <div property="date" datatype="xsd:dateTime" content="2012-09-05T16:30:00Z">Back in September</div>
- <div property="number" datatype="xsd:integer">123</div>
- </div>
+ <div property="number" datatype="xsd:integer">123</div>
+ </div>
</div>
<div class="rdfa-twoinstances">
- <div about="http://example.net/example">
- <div property="dcterms:title">Foo</div>
- </div>
- <div about="http://example.net/example">
- <div property="dcterms:description">Bar</div>
- </div>
+ <div about="http://example.net/example">
+ <div property="dcterms:title">Foo</div>
+ </div>
+ <div about="http://example.net/example">
+ <div property="dcterms:description">Bar</div>
+ </div>
+ </div>
+ <div class="rdfa-anonrelation">
+ <div about="http://example.net/example">
+ <div property="dcterms:title">Foo</div>
+ <div rel="relations">
+ <div typeof="relation">
+ <div property="dcterms:title">Bar</div>
+ </div>
+ </div>
+ </div>
</div>
</div>
View
20 test/service/rdfa.js
@@ -430,3 +430,23 @@ test("Test multiple RDFa instances of same entity", function () {
start();
});
});
+
+test("Test anonymous relation", function () {
+ var z = new VIE();
+ z.use(new z.RdfaService);
+
+ var html = jQuery('#qunit-fixture .rdfa-anonrelation');
+
+ stop();
+ z.load({element: html}).from('rdfa').execute().done(function (entities) {
+ start();
+
+ var entity = z.entities.get('<http://example.net/example>');
+ ok(entity);
+ equal(entity.get('dcterms:title'), 'Foo');
+
+ var relations = entity.get('relations');
+ equal(relations.length, 1);
+ equal(relations.at(0).get('dcterms:title'), 'Bar');
+ });
+});

0 comments on commit 35c4504

Please sign in to comment.
Something went wrong with that request. Please try again.