Skip to content

Commit

Permalink
Initial context and example.
Browse files Browse the repository at this point in the history
Signed-off-by: Markus Sabadello <[email protected]>
  • Loading branch information
peacekeeper committed Mar 10, 2021
1 parent bc12f69 commit 4958c49
Show file tree
Hide file tree
Showing 5 changed files with 264 additions and 0 deletions.
159 changes: 159 additions & 0 deletions common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/* globals omitTerms, respecConfig, $, require */
/* exported linkCrossReferences, restrictReferences, fixIncludes */
var ccg = {
// Add as the respecConfig localBiblio variable
// Extend or override global respec references
localBiblio: {
}
};



// We should be able to remove terms that are not actually
// referenced from the common definitions
//
// the termlist is in a block of class "termlist", so make sure that
// has an ID and put that ID into the termLists array so we can
// interrogate all of the included termlists later.
var termNames = [] ;
var termLists = [] ;
var termsReferencedByTerms = [] ;

function restrictReferences(utils, content) {
"use strict";
var base = document.createElement("div");
base.innerHTML = content;

// New new logic:
//
// 1. build a list of all term-internal references
// 2. When ready to process, for each reference INTO the terms,
// remove any terms they reference from the termNames array too.
$.each(base.querySelectorAll("dfn"), function(i, item) {
var $t = $(item) ;
var titles = ''; //$t.getDfnTitles();
var dropit = false;
// do we have an omitTerms
if (window.hasOwnProperty("omitTerms")) {
// search for a match
$.each(omitTerms, function(j, term) {
if (titles.indexOf(term) !== -1) {
dropit = true;
}
});
}
// do we have an includeTerms
if (window.hasOwnProperty("includeTerms")) {
var found = false;
// search for a match
$.each(includeTerms, function(j, term) {
if (titles.indexOf(term) !== -1) {
found = true;
}
});
if (!found) {
dropit = true;
}
}
if (dropit) {
$t.parent().next().remove();
$t.parent().remove();
} else {
var n = 0;//$t.makeID("dfn", titles[0]);
if (n) {
termNames[n] = $t.parent() ;
}
}
});

var $container = $(".termlist",base) ;
var containerID = 0;//$container.makeID("", "terms") ;
termLists.push(containerID) ;

return (base.innerHTML);
}
// add a handler to come in after all the definitions are resolved
//
// New logic: If the reference is within a 'dl' element of
// class 'termlist', and if the target of that reference is
// also within a 'dl' element of class 'termlist', then
// consider it an internal reference and ignore it.

require(["core/pubsubhub"], function(respecEvents) {
"use strict";
respecEvents.sub('end', function(message) {
if (message === 'core/link-to-dfn') {
// all definitions are linked; find any internal references
$(".termlist a.internalDFN").each(function() {
var $r = $(this);
var id = $r.attr('href');
var idref = id.replace(/^#/,"") ;
if (termNames[idref]) {
// this is a reference to another term
// what is the idref of THIS term?
var $def = $r.closest('dd') ;
if ($def.length) {
var $p = $def.prev('dt').find('dfn') ;
var tid = $p.attr('id') ;
if (tid) {
if (termsReferencedByTerms[tid]) {
termsReferencedByTerms[tid].push(idref);
} else {
termsReferencedByTerms[tid] = [] ;
termsReferencedByTerms[tid].push(idref);
}
}
}
}
}) ;

// clearRefs is recursive. Walk down the tree of
// references to ensure that all references are resolved.
var clearRefs = function(theTerm) {
if ( termsReferencedByTerms[theTerm] ) {
$.each(termsReferencedByTerms[theTerm], function(i, item) {
if (termNames[item]) {
delete termNames[item];
clearRefs(item);
}
});
}
// make sure this term doesn't get removed
if (termNames[theTerm]) {
delete termNames[theTerm];
}
};

// now termsReferencedByTerms has ALL terms that
// reference other terms, and a list of the
// terms that they reference
$("a.internalDFN").each(function () {
var $item = $(this) ;
var t = $item.attr('href');
var r = t.replace(/^#/,"") ;
// if the item is outside the term list
if ( ! $item.closest('dl.termlist').length ) {
clearRefs(r);
}
});

// delete any terms that were not referenced.
/*
Object.keys(termNames).forEach(function(term) {
var $p = $("#"+term) ;
if ($p) {
var tList = $p.getDfnTitles();
$p.parent().next().remove();
$p.parent().remove() ;
tList.forEach(function( item ) {
console.log("CHECKING ITEM", item, respecConfig);
if (respecConfig.definitionMap[item]) {
delete respecConfig.definitionMap[item];
}
});
}
});*/
}
});
});

51 changes: 51 additions & 0 deletions context/v0.1/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"@context": {
"@version": 1.1,
"@protected": true,
"id": "@id",
"type": "@type",
"EmploymentCredential": {
"@id": "https://danubetech.github.io/employment-vocab/#EmploymentCredential",
"@context": {
"@version": 1.1,
"@protected": true,
"id": "@id",
"type": "@type",
"name": "https://schema.org/name",
"description": "https://schema.org/description"
}
},
"Employee": {
"@id": "https://danubetech.github.io/employment-vocab/#Employee",
"@context": {
"@version": 1.1,
"@protected": true,
"id": "@id",
"type": "@type",
"title": "https://danubetech.github.io/employment-vocab/#title",
"jobStartDate": {
"@id": "https://danubetech.github.io/employment-vocab/#jobStartDate",
"@type": "http://www.w3.org/2001/XMLSchema#dateTime"
},
"employer": "https://danubetech.github.io/employment-vocab/#employer",
"manager": "https://danubetech.github.io/employment-vocab/#manager",
"location": "https://schema.org/location",
"department": {
"@id": "https://danubetech.github.io/employment-vocab/#department",
"@type": "https://danubetech.github.io/employment-vocab/#Department"
}
}
},
"Department": {
"@id": "https://danubetech.github.io/employment-vocab/#Department",
"@context": {
"@version": 1.1,
"@protected": true,
"id": "@id",
"type": "@type",
"departmentName": "https://danubetech.github.io/employment-vocab/#departmentName",
"departmentNumber": "https://danubetech.github.io/employment-vocab/#departmentNumber"
}
}
}
}
35 changes: 35 additions & 0 deletions examples/employment-signed-ed25519.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://danubetech.github.io/employment-vocab/context/v0.1/"
],
"type": [
"VerifiableCredential",
"EmploymentCredential"
],
"id": "urn:uuid:2b767d24-681d-4746-b013-9342c1c6a5aa",
"name": "Employment Credential",
"description": "Employment Credential",
"issuer": "did:key:z6MkkXNmybrz4A1oh39GdxNNDDDPgCcmbrrStGWPGBAdcuj1",
"issuanceDate": "2021-03-03T04:07:09.815Z",
"credentialSubject": {
"id": "did:key:z6MkrdgrcvRxnC6MtmjrWM2ro6DmtL179L4tPFNoaoFjtSai",
"type": "Employee",
"title": "Senior Researcher",
"jobStartDate": "2021-03-18T00:00:00.000Z",
"employer": "Dairy Informatica",
"manager": "Dr. René Pascal",
"location": "San Diego, CA, USA",
"department": {
"departmentName": "Research and Development",
"departmentNumber": "4"
}
},
"proof": {
"type": "Ed25519Signature2018",
"created": "2021-03-03T04:07:09Z",
"jws": "eyJhbGciOiJFZERTQSIsImI2NCI6ZmFsc2UsImNyaXQiOlsiYjY0Il19..1QkbBH23Lur8Bj16SSqVsmRIresAeto8hkGQFyqF4nFBbV1DNNXmHHERbgdrfJtwOEFoLtIQrZJge7gLXtzgCQ",
"proofPurpose": "assertionMethod",
"verificationMethod": "did:key:z6MkrtYMJe2ZesvsnoSr8K1yVerjo6EhC2G5jxBDKrD284L2#z6MkrtYMJe2ZesvsnoSr8K1yVerjo6EhC2G5jxBDKrD284L2"
}
}
14 changes: 14 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>Employment Vocabulary v0.1</title>
<meta http-equiv=" Content-Type" content="text/html;charset=utf-8">
<script>
console.log('🧪...');
</script>

</head>
<body>
<p>TODO</p>
</body>
</html>
5 changes: 5 additions & 0 deletions terms.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<p>The following terms are used to describe concepts in this specification.</p>
<dl class="termlist">
<dt><dfn data-lt="URI|URIs">URI</dfn></dt>
<dd>An identifier as defined by [[RFC3986]].</dd>
</dl>

0 comments on commit 4958c49

Please sign in to comment.