Skip to content

Improved examples #67

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

Merged
merged 4 commits into from
Sep 24, 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
30 changes: 15 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ GEM
colorize (0.8.1)
concurrent-ruby (1.0.5)
connection_pool (2.2.2)
ebnf (1.1.2)
rdf (>= 2.2, < 4.0)
ebnf (1.1.3)
rdf (~> 3.0)
sxp (~> 1.0)
equivalent-xml (0.6.0)
nokogiri (>= 1.4.3)
Expand All @@ -22,11 +22,11 @@ GEM
htmlentities (4.3.4)
i18n (1.1.0)
concurrent-ruby (~> 1.0)
json-ld (3.0.0)
json-ld (3.0.1)
multi_json (~> 1.12)
rdf (>= 2.2.8, < 4.0)
json-ld-preloaded (3.0.0)
json-ld (>= 2.2, < 4.0)
json-ld-preloaded (3.0.1)
json-ld (~> 3.0)
multi_json (~> 1.12)
rdf (~> 3.0)
ld-patch (0.3.3)
Expand Down Expand Up @@ -71,7 +71,7 @@ GEM
nokogiri
public_suffix (3.0.3)
rake (12.3.1)
rdf (3.0.2)
rdf (3.0.3)
hamster (~> 3.0)
link_header (~> 0.0, >= 0.0.8)
rdf-aggregate-repo (2.2.1)
Expand All @@ -85,7 +85,7 @@ GEM
nokogiri (~> 1.8)
rdf (>= 2.2.8, < 4.0)
rdf-xsd (>= 2.2, < 4.0)
rdf-n3 (3.0.0)
rdf-n3 (3.0.1)
rdf (~> 3.0)
rdf-normalize (0.3.3)
rdf (>= 2.2, < 4.0)
Expand All @@ -111,18 +111,18 @@ GEM
rdf (>= 2.2, < 4.0)
rdf-vocab (>= 2.2, < 4.0)
rdf-xsd (>= 2.2, < 4.0)
rdf-trig (2.2.0)
ebnf (~> 1.0, >= 1.0.1)
rdf (>= 2.2, < 4.0)
rdf-turtle (>= 2.2, < 4.0)
rdf-trig (3.0.0)
ebnf (~> 1.1)
rdf (~> 3.0)
rdf-turtle (~> 3.0, >= 3.0.2)
rdf-trix (2.2.1)
rdf (>= 2.2, < 4.0)
rdf-turtle (3.0.1)
rdf-turtle (3.0.2)
ebnf (~> 1.1)
rdf (~> 3.0)
rdf-vocab (3.0.3)
rdf (~> 3.0)
rdf-xsd (3.0.0)
rdf-xsd (3.0.1)
rdf (~> 3.0)
shex (0.5.2)
ebnf (~> 1.1)
Expand All @@ -132,7 +132,7 @@ GEM
rdf-xsd (>= 2.2, < 4.0)
sparql (>= 2.2, < 4.0)
sxp (~> 1.0)
sparql (3.0.1)
sparql (3.0.2)
builder (~> 3.2)
ebnf (~> 1.1)
rdf (~> 3.0)
Expand All @@ -158,4 +158,4 @@ DEPENDENCIES
rake

BUNDLED WITH
1.16.1
1.16.4
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ end

desc "Extract Examples"
task :examples do
sh %(rm -rf examples yaml trig)
sh %(bundle exec common/extract-examples.rb --example-dir examples --yaml-dir yaml --trig-dir trig index.html)
sh %(rm -rf examples yaml)
sh %(bundle exec common/extract-examples.rb --example-dir examples --yaml-dir yaml index.html)
end
50 changes: 41 additions & 9 deletions common/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ function restrictReferences(utils, content) {
// 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) {
require(["core/pubsubhub"], (respecEvents) => {
"use strict";
respecEvents.sub('end', function(message) {
respecEvents.sub('end', (message) => {
if (message === 'core/link-to-dfn') {
// all definitions are linked; find any internal references
const internalTerms = document.querySelectorAll(".termlist a.internalDFN");
Expand All @@ -69,7 +69,7 @@ require(["core/pubsubhub"], function(respecEvents) {

// clearRefs is recursive. Walk down the tree of
// references to ensure that all references are resolved.
const clearRefs = function(theTerm) {
const clearRefs = (theTerm) => {
if (termsReferencedByTerms[theTerm] ) {
for (const item of termsReferencedByTerms[theTerm]) {
if (termNames[item]) {
Expand Down Expand Up @@ -142,10 +142,10 @@ require(["core/pubsubhub"], function(respecEvents) {
* use include the github.io address (as it should...)
*
*/
require(["core/pubsubhub"], function(respecEvents) {
require(["core/pubsubhub"], (respecEvents) => {
"use strict";
respecEvents.sub('beforesave', function(documentElement) {
$("a[href]", documentElement).each( function(index) {
respecEvents.sub('beforesave', (documentElement) => {
$("a[href]", documentElement).each((index) => {
// Don't rewrite these.
if ($(this, documentElement).closest('dd').prev().text().match(/Latest editor|Test suite|Implementation report/)) return;
if ($(this, documentElement).closest('section.preserve').length > 0) return;
Expand All @@ -165,23 +165,55 @@ require(["core/pubsubhub"], function(respecEvents) {
});
});

/*
* Implement tabbed examples.
*/
require(["core/pubsubhub"], (respecEvents) => {
"use strict";
respecEvents.sub('end-all', (documentElement) => {
for (const button of document.querySelectorAll(".ds-selector-tabs .selectors button")) {
button.onclick = () => {
const ex = button.closest(".ds-selector-tabs");
ex.querySelector("button.selected").classList.remove("selected");
ex.querySelector(".selected").classList.remove("selected");
button.classList.add('selected');
ex.querySelector("." + button.dataset.selects).classList.add("selected");
}
}
});
});

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

function reindent(text) {
// TODO: use trimEnd when Edge supports it
const lines = text.trimRight().split("\n");
while (lines.length && !lines[0].trim()) {
lines.shift();
}
const indents = lines.filter(s => s.trim()).map(s => s.search(/[^\s]/));
const leastIndent = Math.min(...indents);
return lines.map(s => s.slice(leastIndent)).join("\n");
}

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


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