From 4958c49224e4c7fdb54e5b0d721f0e544da7799d Mon Sep 17 00:00:00 2001 From: Markus Sabadello Date: Wed, 10 Mar 2021 18:52:41 +0100 Subject: [PATCH] Initial context and example. Signed-off-by: Markus Sabadello --- common.js | 159 ++++++++++++++++++++++ context/v0.1/index.json | 51 +++++++ examples/employment-signed-ed25519.jsonld | 35 +++++ index.html | 14 ++ terms.html | 5 + 5 files changed, 264 insertions(+) create mode 100644 common.js create mode 100644 context/v0.1/index.json create mode 100644 examples/employment-signed-ed25519.jsonld create mode 100644 index.html create mode 100644 terms.html diff --git a/common.js b/common.js new file mode 100644 index 0000000..0989152 --- /dev/null +++ b/common.js @@ -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]; + } + }); + } + });*/ + } + }); + }); + \ No newline at end of file diff --git a/context/v0.1/index.json b/context/v0.1/index.json new file mode 100644 index 0000000..46403aa --- /dev/null +++ b/context/v0.1/index.json @@ -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" + } + } + } +} \ No newline at end of file diff --git a/examples/employment-signed-ed25519.jsonld b/examples/employment-signed-ed25519.jsonld new file mode 100644 index 0000000..ec79e43 --- /dev/null +++ b/examples/employment-signed-ed25519.jsonld @@ -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" + } +} \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..ccfbf18 --- /dev/null +++ b/index.html @@ -0,0 +1,14 @@ + + + + Employment Vocabulary v0.1 + + + + + +

TODO

+ + diff --git a/terms.html b/terms.html new file mode 100644 index 0000000..a9d0f84 --- /dev/null +++ b/terms.html @@ -0,0 +1,5 @@ +

The following terms are used to describe concepts in this specification.

+
+
URI
+
An identifier as defined by [[RFC3986]].
+