Skip to content

Commit 91bce75

Browse files
authored
Merge pull request #67 from w3c/improved-examples
Improved examples
2 parents f3edaa5 + 9ef6b94 commit 91bce75

File tree

570 files changed

+10622
-3598
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

570 files changed

+10622
-3598
lines changed

Gemfile.lock

+15-15
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ GEM
99
colorize (0.8.1)
1010
concurrent-ruby (1.0.5)
1111
connection_pool (2.2.2)
12-
ebnf (1.1.2)
13-
rdf (>= 2.2, < 4.0)
12+
ebnf (1.1.3)
13+
rdf (~> 3.0)
1414
sxp (~> 1.0)
1515
equivalent-xml (0.6.0)
1616
nokogiri (>= 1.4.3)
@@ -22,11 +22,11 @@ GEM
2222
htmlentities (4.3.4)
2323
i18n (1.1.0)
2424
concurrent-ruby (~> 1.0)
25-
json-ld (3.0.0)
25+
json-ld (3.0.1)
2626
multi_json (~> 1.12)
2727
rdf (>= 2.2.8, < 4.0)
28-
json-ld-preloaded (3.0.0)
29-
json-ld (>= 2.2, < 4.0)
28+
json-ld-preloaded (3.0.1)
29+
json-ld (~> 3.0)
3030
multi_json (~> 1.12)
3131
rdf (~> 3.0)
3232
ld-patch (0.3.3)
@@ -71,7 +71,7 @@ GEM
7171
nokogiri
7272
public_suffix (3.0.3)
7373
rake (12.3.1)
74-
rdf (3.0.2)
74+
rdf (3.0.3)
7575
hamster (~> 3.0)
7676
link_header (~> 0.0, >= 0.0.8)
7777
rdf-aggregate-repo (2.2.1)
@@ -85,7 +85,7 @@ GEM
8585
nokogiri (~> 1.8)
8686
rdf (>= 2.2.8, < 4.0)
8787
rdf-xsd (>= 2.2, < 4.0)
88-
rdf-n3 (3.0.0)
88+
rdf-n3 (3.0.1)
8989
rdf (~> 3.0)
9090
rdf-normalize (0.3.3)
9191
rdf (>= 2.2, < 4.0)
@@ -111,18 +111,18 @@ GEM
111111
rdf (>= 2.2, < 4.0)
112112
rdf-vocab (>= 2.2, < 4.0)
113113
rdf-xsd (>= 2.2, < 4.0)
114-
rdf-trig (2.2.0)
115-
ebnf (~> 1.0, >= 1.0.1)
116-
rdf (>= 2.2, < 4.0)
117-
rdf-turtle (>= 2.2, < 4.0)
114+
rdf-trig (3.0.0)
115+
ebnf (~> 1.1)
116+
rdf (~> 3.0)
117+
rdf-turtle (~> 3.0, >= 3.0.2)
118118
rdf-trix (2.2.1)
119119
rdf (>= 2.2, < 4.0)
120-
rdf-turtle (3.0.1)
120+
rdf-turtle (3.0.2)
121121
ebnf (~> 1.1)
122122
rdf (~> 3.0)
123123
rdf-vocab (3.0.3)
124124
rdf (~> 3.0)
125-
rdf-xsd (3.0.0)
125+
rdf-xsd (3.0.1)
126126
rdf (~> 3.0)
127127
shex (0.5.2)
128128
ebnf (~> 1.1)
@@ -132,7 +132,7 @@ GEM
132132
rdf-xsd (>= 2.2, < 4.0)
133133
sparql (>= 2.2, < 4.0)
134134
sxp (~> 1.0)
135-
sparql (3.0.1)
135+
sparql (3.0.2)
136136
builder (~> 3.2)
137137
ebnf (~> 1.1)
138138
rdf (~> 3.0)
@@ -158,4 +158,4 @@ DEPENDENCIES
158158
rake
159159

160160
BUNDLED WITH
161-
1.16.1
161+
1.16.4

Rakefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ end
77

88
desc "Extract Examples"
99
task :examples do
10-
sh %(rm -rf examples yaml trig)
11-
sh %(bundle exec common/extract-examples.rb --example-dir examples --yaml-dir yaml --trig-dir trig index.html)
10+
sh %(rm -rf examples yaml)
11+
sh %(bundle exec common/extract-examples.rb --example-dir examples --yaml-dir yaml index.html)
1212
end

common/common.js

+41-9
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ function restrictReferences(utils, content) {
4343
// class 'termlist', and if the target of that reference is
4444
// also within a 'dl' element of class 'termlist', then
4545
// consider it an internal reference and ignore it.
46-
require(["core/pubsubhub"], function(respecEvents) {
46+
require(["core/pubsubhub"], (respecEvents) => {
4747
"use strict";
48-
respecEvents.sub('end', function(message) {
48+
respecEvents.sub('end', (message) => {
4949
if (message === 'core/link-to-dfn') {
5050
// all definitions are linked; find any internal references
5151
const internalTerms = document.querySelectorAll(".termlist a.internalDFN");
@@ -69,7 +69,7 @@ require(["core/pubsubhub"], function(respecEvents) {
6969

7070
// clearRefs is recursive. Walk down the tree of
7171
// references to ensure that all references are resolved.
72-
const clearRefs = function(theTerm) {
72+
const clearRefs = (theTerm) => {
7373
if (termsReferencedByTerms[theTerm] ) {
7474
for (const item of termsReferencedByTerms[theTerm]) {
7575
if (termNames[item]) {
@@ -142,10 +142,10 @@ require(["core/pubsubhub"], function(respecEvents) {
142142
* use include the github.io address (as it should...)
143143
*
144144
*/
145-
require(["core/pubsubhub"], function(respecEvents) {
145+
require(["core/pubsubhub"], (respecEvents) => {
146146
"use strict";
147-
respecEvents.sub('beforesave', function(documentElement) {
148-
$("a[href]", documentElement).each( function(index) {
147+
respecEvents.sub('beforesave', (documentElement) => {
148+
$("a[href]", documentElement).each((index) => {
149149
// Don't rewrite these.
150150
if ($(this, documentElement).closest('dd').prev().text().match(/Latest editor|Test suite|Implementation report/)) return;
151151
if ($(this, documentElement).closest('section.preserve').length > 0) return;
@@ -165,23 +165,55 @@ require(["core/pubsubhub"], function(respecEvents) {
165165
});
166166
});
167167

168+
/*
169+
* Implement tabbed examples.
170+
*/
171+
require(["core/pubsubhub"], (respecEvents) => {
172+
"use strict";
173+
respecEvents.sub('end-all', (documentElement) => {
174+
for (const button of document.querySelectorAll(".ds-selector-tabs .selectors button")) {
175+
button.onclick = () => {
176+
const ex = button.closest(".ds-selector-tabs");
177+
ex.querySelector("button.selected").classList.remove("selected");
178+
ex.querySelector(".selected").classList.remove("selected");
179+
button.classList.add('selected');
180+
ex.querySelector("." + button.dataset.selects).classList.add("selected");
181+
}
182+
}
183+
});
184+
});
185+
168186
function _esc(s) {
169187
return s.replace(/&/g,'&amp;')
170188
.replace(/>/g,'&gt;')
171189
.replace(/"/g,'&quot;')
172190
.replace(/</g,'&lt;');
173191
}
174192

193+
function reindent(text) {
194+
// TODO: use trimEnd when Edge supports it
195+
const lines = text.trimRight().split("\n");
196+
while (lines.length && !lines[0].trim()) {
197+
lines.shift();
198+
}
199+
const indents = lines.filter(s => s.trim()).map(s => s.search(/[^\s]/));
200+
const leastIndent = Math.min(...indents);
201+
return lines.map(s => s.slice(leastIndent)).join("\n");
202+
}
203+
175204
function updateExample(doc, content) {
176205
// perform transformations to make it render and prettier
177-
return _esc(unComment(doc, content))
206+
return _esc(reindent(unComment(doc, content)))
178207
.replace(/\*\*\*\*([^*]*)\*\*\*\*/g, '<span class="hl-bold">$1</span>')
179208
.replace(/####([^#]*)####/g, '<span class="comment">$1</span>');
180209
}
181210

182211

183212
function unComment(doc, content) {
184213
// perform transformations to make it render and prettier
185-
return content.replace(/<!--/, '')
186-
.replace(/-->/, '');
214+
return content
215+
.replace(/<!--/, '')
216+
.replace(/-->/, '')
217+
.replace(/< !--/g, '<!--')
218+
.replace(/-- >/g, '-->');
187219
}

0 commit comments

Comments
 (0)