Skip to content

Commit 44dab22

Browse files
authored
Merge pull request #1 from w3c/cg-import
Initial spec import
2 parents 0013b9e + f9bb62e commit 44dab22

File tree

5 files changed

+5630
-35
lines changed

5 files changed

+5630
-35
lines changed

common/algorithm-terms.html

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<dl class="termlist" data-sort>
2+
<dt><dfn>active graph</dfn></dt><dd>
3+
The name of the currently active graph that the processor should use when
4+
processing.</dd>
5+
<dt><dfn>active object</dfn></dt><dd>
6+
The currently active object that the processor should use when
7+
processing.</dd>
8+
<dt><dfn>active property</dfn></dt><dd>
9+
The currently active <a>property</a> or <a>keyword</a> that the processor
10+
should use when processing. The <a>active property</a> is represented in
11+
the original lexical form, which is used for finding coercion mappings in
12+
the <a>active context</a>.</dd>
13+
<dt><dfn>active subject</dfn></dt><dd>
14+
The currently active subject that the processor should use when
15+
processing.</dd>
16+
<dt><dfn>explicit inclusion flag</dfn></dt><dd>
17+
A flag specifying that for <a>properties</a> to be included in the output, they
18+
must be explicitly declared in the matching <a>frame</a>.</dd>
19+
<dt><dfn>framing state</dfn></dt><dd>
20+
A <a>dictionary</a> containing values for the
21+
<a>object embed flag</a>, the
22+
<a>require all flag</a>, the
23+
<a>explicit inclusion flag</a>, and the
24+
<a>omit default flag</a>.</dd>
25+
<dt><dfn>input frame</dfn></dt><dd>
26+
The initial <a>Frame</a> provided to the framing algorithm.</dd>
27+
<dt><dfn>JSON-LD input</dfn></dt><dd>
28+
The JSON-LD data structure that is provided as input to the algorithm.</dd>
29+
<dt><dfn>JSON-LD output</dfn></dt><dd>
30+
The JSON-LD data structure that is produced as output by the algorithm.</dd>
31+
<dt><dfn>map of flattened subjects</dfn></dt><dd>
32+
A map of subjects that is the result of the
33+
<a data-cite="JSON-LD11-API#node-map-generation">Node Map Generation algorithm</a>.</dd>
34+
<dt><dfn>object embed flag</dfn></dt><dd>
35+
A flag specifying that <a>node objects</a> should be directly embedded in the output,
36+
instead of being referred to by their <a>IRI</a>.</dd>
37+
<dt><dfn>omit default flag</dfn></dt><dd>
38+
A flag specifying that properties that are missing from the
39+
<a>JSON-LD input</a>, but present in the <a>input frame</a>
40+
should be omitted from the output.</dd>
41+
<dt class="changed"><dfn>omit graph flag</dfn></dt><dd class="changed">
42+
A flag that determines if framing output is always contained within a
43+
<code>@graph</code> member, or only if required to represent multiple <a>node objects</a>.</dd>
44+
<dt><dfn>processor state</dfn></dt><dd>
45+
The <a>processor state</a>, which includes the <a>active
46+
context</a>, <a>active subject</a>, and
47+
<a>active property</a>. The <a>processor state</a> is managed
48+
as a stack with elements from the previous <a>processor state</a>
49+
copied into a new <a>processor state</a> when entering a new
50+
<a>JSON object</a>.</dd>
51+
<dt><dfn data-lt="promises">promise</dfn></dt><dd>
52+
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.
53+
Promises are defined in [[ECMASCRIPT-6.0]].</dd>
54+
<dt><dfn>require all flag</dfn></dt><dd>
55+
A flag specifying that all properties present in the <a>input frame</a>
56+
MUST either have a default value or be present in the <a>JSON-LD
57+
input</a> for the frame to match.</dd>
58+
</dl>

common/common.js

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
/* Web Payments Community Group common spec JavaScript */
2+
var jsonld = {
3+
// Add as the respecConfig localBiblio variable
4+
// Extend or override global respec references
5+
localBiblio: {
6+
"JSON-LD11": {
7+
title: "JSON-LD 1.1",
8+
href: "https://w3c.github.io/json-ld-syntax/",
9+
authors: ["Gregg Kellogg"],
10+
publisher: "W3C",
11+
status: 'ED'
12+
},
13+
"JSON-LD11-API": {
14+
title: "JSON-LD 1.1 Processing Algorithms and API",
15+
href: "https://w3c.github.io/json-ld-api/",
16+
authors: ["Gregg Kellogg"],
17+
publisher: "W3C",
18+
status: 'ED'
19+
},
20+
"JSON-LD11-FRAMING": {
21+
title: "JSON-LD 1.1 Framing",
22+
href: "https://w3c.github.io/json-ld-framing/",
23+
authors: ["Gregg Kellogg"],
24+
publisher: "W3C",
25+
status: 'ED'
26+
},
27+
"JSON-LD-TESTS": {
28+
title: "JSON-LD 1.1 Test Suite",
29+
href: "https://json-ld.org/test-suite/",
30+
authors: ["Gregg Kellogg"],
31+
publisher: "Linking Data in JSON Community Group"
32+
},
33+
// aliases to known references
34+
"IEEE-754-2008": {
35+
title: "IEEE 754-2008 Standard for Floating-Point Arithmetic",
36+
href: "http://standards.ieee.org/findstds/standard/754-2008.html",
37+
publisher: "Institute of Electrical and Electronics Engineers",
38+
date: "2008"
39+
},
40+
"PROMISES": {
41+
title: 'Promise Objects',
42+
href: 'https://github.com/domenic/promises-unwrapping',
43+
authors: ['Domenic Denicola'],
44+
status: 'unofficial',
45+
date: 'January 2014'
46+
},
47+
"MICROFORMATS": {
48+
title: "Microformats",
49+
href: "http://microformats.org"
50+
}
51+
}
52+
};
53+
54+
// We should be able to remove terms that are not actually
55+
// referenced from the common definitions
56+
//
57+
// Add class "preserve" to a definition to ensure it is not removed.
58+
//
59+
// the termlist is in a block of class "termlist", so make sure that
60+
// has an ID and put that ID into the termLists array so we can
61+
// interrogate all of the included termlists later.
62+
var termNames = [] ;
63+
var termLists = [] ;
64+
var termsReferencedByTerms = [] ;
65+
66+
function restrictReferences(utils, content) {
67+
var base = document.createElement("div");
68+
base.innerHTML = content;
69+
70+
// New new logic:
71+
//
72+
// 1. build a list of all term-internal references
73+
// 2. When ready to process, for each reference INTO the terms,
74+
// remove any terms they reference from the termNames array too.
75+
$.each(base.querySelectorAll("dfn:not(.preserve)"), function(i, item) {
76+
var $t = $(item) ;
77+
var titles = $t.getDfnTitles();
78+
var n = $t.makeID("dfn", titles[0]);
79+
if (n) {
80+
termNames[n] = $t.parent() ;
81+
}
82+
});
83+
84+
var $container = $(".termlist", base) ;
85+
var containerID = $container.makeID("", "terms") ;
86+
termLists.push(containerID) ;
87+
return (base.innerHTML);
88+
}
89+
90+
// add a handler to come in after all the definitions are resolved
91+
//
92+
// New logic: If the reference is within a 'dl' element of
93+
// class 'termlist', and if the target of that reference is
94+
// also within a 'dl' element of class 'termlist', then
95+
// consider it an internal reference and ignore it.
96+
97+
function internalizeTermListReferences() {
98+
// all definitions are linked; find any internal references
99+
$(".termlist a.internalDFN").each(function() {
100+
var $r = $(this);
101+
var id = $r.attr('href');
102+
var idref = id.replace(/^#/,"") ;
103+
if (termNames[idref]) {
104+
// this is a reference to another term
105+
// what is the idref of THIS term?
106+
var $def = $r.closest('dd') ;
107+
if ($def.length) {
108+
var $p = $def.prev('dt').find('dfn') ;
109+
var tid = $p.attr('id') ;
110+
if (tid) {
111+
if (termsReferencedByTerms[tid]) {
112+
termsReferencedByTerms[tid].push(idref);
113+
} else {
114+
termsReferencedByTerms[tid] = [] ;
115+
termsReferencedByTerms[tid].push(idref);
116+
}
117+
}
118+
}
119+
}
120+
});
121+
122+
// clearRefs is recursive. Walk down the tree of
123+
// references to ensure that all references are resolved.
124+
var clearRefs = function(theTerm) {
125+
if ( termsReferencedByTerms[theTerm] ) {
126+
$.each(termsReferencedByTerms[theTerm], function(i, item) {
127+
if (termNames[item]) {
128+
delete termNames[item];
129+
clearRefs(item);
130+
}
131+
});
132+
};
133+
// make sure this term doesn't get removed
134+
if (termNames[theTerm]) {
135+
delete termNames[theTerm];
136+
}
137+
};
138+
139+
// now termsReferencedByTerms has ALL terms that
140+
// reference other terms, and a list of the
141+
// terms that they reference
142+
$("a.internalDFN").each(function () {
143+
var $item = $(this) ;
144+
var t = $item.attr('href');
145+
var r = t.replace(/^#/,"") ;
146+
if (r === 'dictionary') {
147+
var rr = r;
148+
}
149+
// if the item is outside the term list
150+
if ( ! $item.closest('dl.termlist').length ) {
151+
clearRefs(r);
152+
}
153+
});
154+
155+
// delete any terms that were not referenced.
156+
Object.keys(termNames).forEach(function(term) {
157+
var $p = $("#"+term) ;
158+
if ($p) {
159+
var tList = $p.getDfnTitles();
160+
$p.parent().next().remove();
161+
$p.remove() ;
162+
tList.forEach(function( item ) {
163+
if (respecConfig.definitionMap[item]) {
164+
delete respecConfig.definitionMap[item];
165+
}
166+
});
167+
}
168+
});
169+
}
170+
171+
function _esc(s) {
172+
s = s.replace(/&/g,'&amp;');
173+
s = s.replace(/>/g,'&gt;');
174+
s = s.replace(/"/g,'&quot;');
175+
s = s.replace(/</g,'&lt;');
176+
return s;
177+
}
178+
179+
function updateExample(doc, content) {
180+
// perform transformations to make it render and prettier
181+
content = unComment(doc, content);
182+
content = _esc(content);
183+
content = content.replace(/\*\*\*\*([^*]*)\*\*\*\*/g, '<span class="hl-bold">$1</span>');
184+
content = content.replace(/####([^#]*)####/g, '<span class="comment">$1</span>');
185+
return content ;
186+
}
187+
188+
189+
function unComment(doc, content) {
190+
// perform transformations to make it render and prettier
191+
content = content.replace(/<!--/, '');
192+
content = content.replace(/-->/, '');
193+
return content ;
194+
}

0 commit comments

Comments
 (0)