Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CG import ivan #2

Merged
merged 5 commits into from
Jun 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions common/algorithm-terms.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<dl class="termlist" data-sort>
<dt><dfn>active graph</dfn></dt><dd>
The name of the currently active graph that the processor should use when
processing.</dd>
<dt><dfn>active object</dfn></dt><dd>
The currently active object that the processor should use when
processing.</dd>
<dt><dfn>active property</dfn></dt><dd>
The currently active <a>property</a> or <a>keyword</a> that the processor
should use when processing. The <a>active property</a> is represented in
the original lexical form, which is used for finding coercion mappings in
the <a>active context</a>.</dd>
<dt><dfn>active subject</dfn></dt><dd>
The currently active subject that the processor should use when
processing.</dd>
<dt><dfn>explicit inclusion flag</dfn></dt><dd>
A flag specifying that for <a>properties</a> to be included in the output, they
must be explicitly declared in the matching <a>frame</a>.</dd>
<dt><dfn>framing state</dfn></dt><dd>
A <a>dictionary</a> containing values for the
<a>object embed flag</a>, the
<a>require all flag</a>, the
<a>explicit inclusion flag</a>, and the
<a>omit default flag</a>.</dd>
<dt><dfn>input frame</dfn></dt><dd>
The initial <a>Frame</a> provided to the framing algorithm.</dd>
<dt><dfn>JSON-LD input</dfn></dt><dd>
The JSON-LD data structure that is provided as input to the algorithm.</dd>
<dt><dfn>JSON-LD output</dfn></dt><dd>
The JSON-LD data structure that is produced as output by the algorithm.</dd>
<dt><dfn>map of flattened subjects</dfn></dt><dd>
A map of subjects that is the result of the
<a data-cite="JSON-LD11-API#node-map-generation">Node Map Generation algorithm</a>.</dd>
<dt><dfn>object embed flag</dfn></dt><dd>
A flag specifying that <a>node objects</a> should be directly embedded in the output,
instead of being referred to by their <a>IRI</a>.</dd>
<dt><dfn>omit default flag</dfn></dt><dd>
A flag specifying that properties that are missing from the
<a>JSON-LD input</a>, but present in the <a>input frame</a>
should be omitted from the output.</dd>
<dt class="changed"><dfn>omit graph flag</dfn></dt><dd class="changed">
A flag that determines if framing output is always contained within a
<code>@graph</code> member, or only if required to represent multiple <a>node objects</a>.</dd>
<dt><dfn>processor state</dfn></dt><dd>
The <a>processor state</a>, which includes the <a>active
context</a>, <a>active subject</a>, and
<a>active property</a>. The <a>processor state</a> is managed
as a stack with elements from the previous <a>processor state</a>
copied into a new <a>processor state</a> when entering a new
<a>JSON object</a>.</dd>
<dt><dfn data-lt="promises">promise</dfn></dt><dd>
A <a data-cite="ECMASCRIPT-6.0#sec-promise-objects" class="externalDFN">promise</a> is an object that represents the eventual result of a single asynchronous operation.
Promises are defined in [[ECMASCRIPT-6.0]].</dd>
<dt><dfn>require all flag</dfn></dt><dd>
A flag specifying that all properties present in the <a>input frame</a>
MUST either have a default value or be present in the <a>JSON-LD
input</a> for the frame to match.</dd>
</dl>
194 changes: 194 additions & 0 deletions common/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
/* Web Payments Community Group common spec JavaScript */
var jsonld = {
// Add as the respecConfig localBiblio variable
// Extend or override global respec references
localBiblio: {
"JSON-LD11": {
title: "JSON-LD 1.1",
href: "https://w3c.github.io/json-ld-syntax/",
authors: ["Gregg Kellogg"],
publisher: "W3C",
status: 'ED'
},
"JSON-LD11-API": {
title: "JSON-LD 1.1 Processing Algorithms and API",
href: "https://w3c.github.io/json-ld-api/",
authors: ["Gregg Kellogg"],
publisher: "W3C",
status: 'ED'
},
"JSON-LD11-FRAMING": {
title: "JSON-LD 1.1 Framing",
href: "https://w3c.github.io/json-ld-framing/",
authors: ["Gregg Kellogg"],
publisher: "W3C",
status: 'ED'
},
"JSON-LD-TESTS": {
title: "JSON-LD 1.1 Test Suite",
href: "https://json-ld.org/test-suite/",
authors: ["Gregg Kellogg"],
publisher: "Linking Data in JSON Community Group"
},
// aliases to known references
"IEEE-754-2008": {
title: "IEEE 754-2008 Standard for Floating-Point Arithmetic",
href: "http://standards.ieee.org/findstds/standard/754-2008.html",
publisher: "Institute of Electrical and Electronics Engineers",
date: "2008"
},
"PROMISES": {
title: 'Promise Objects',
href: 'https://github.com/domenic/promises-unwrapping',
authors: ['Domenic Denicola'],
status: 'unofficial',
date: 'January 2014'
},
"MICROFORMATS": {
title: "Microformats",
href: "http://microformats.org"
}
}
};

// We should be able to remove terms that are not actually
// referenced from the common definitions
//
// Add class "preserve" to a definition to ensure it is not removed.
//
// 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) {
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:not(.preserve)"), function(i, item) {
var $t = $(item) ;
var titles = $t.getDfnTitles();
var n = $t.makeID("dfn", titles[0]);
if (n) {
termNames[n] = $t.parent() ;
}
});

var $container = $(".termlist", base) ;
var containerID = $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.

function internalizeTermListReferences() {
// 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 (r === 'dictionary') {
var rr = r;
}
// 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.remove() ;
tList.forEach(function( item ) {
if (respecConfig.definitionMap[item]) {
delete respecConfig.definitionMap[item];
}
});
}
});
}

function _esc(s) {
s = s.replace(/&/g,'&amp;');
s = s.replace(/>/g,'&gt;');
s = s.replace(/"/g,'&quot;');
s = s.replace(/</g,'&lt;');
return s;
}

function updateExample(doc, content) {
// perform transformations to make it render and prettier
content = unComment(doc, content);
content = _esc(content);
content = content.replace(/\*\*\*\*([^*]*)\*\*\*\*/g, '<span class="hl-bold">$1</span>');
content = content.replace(/####([^#]*)####/g, '<span class="comment">$1</span>');
return content ;
}


function unComment(doc, content) {
// perform transformations to make it render and prettier
content = content.replace(/<!--/, '');
content = content.replace(/-->/, '');
return content ;
}
Loading