forked from lustre-labs/lustre
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚀 Deploy docs to GitHub Pages./mybackend -o test.s test.cl
- Loading branch information
1 parent
18c4c64
commit 640e335
Showing
9 changed files
with
6,255 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,209 @@ | ||
"use strict"; | ||
|
||
window.Gleam = function() { | ||
/* Global Object */ | ||
const self = {}; | ||
|
||
/* Public Properties */ | ||
|
||
self.hashOffset = undefined; | ||
|
||
/* Public Methods */ | ||
|
||
self.getProperty = function(property) { | ||
let value; | ||
try { | ||
value = localStorage.getItem(`Gleam.${property}`); | ||
} | ||
catch (_error) {} | ||
if (-1 < [null, undefined].indexOf(value)) { | ||
return gleamConfig[property].values[0].value; | ||
} | ||
return value; | ||
}; | ||
|
||
self.icons = function() { | ||
return Array.from(arguments).reduce( | ||
(acc, name) => | ||
`${acc} | ||
<svg class="icon icon-${name}"><use xlink:href="#icon-${name}"></use></svg>`, | ||
"" | ||
); | ||
} | ||
|
||
self.scrollToHash = function() { | ||
const locationHash = arguments[0] || window.location.hash; | ||
const query = locationHash ? locationHash : "body"; | ||
const hashTop = document.querySelector(query).offsetTop; | ||
window.scrollTo(0, hashTop - self.hashOffset); | ||
return locationHash; | ||
}; | ||
|
||
self.toggleSidebar = function() { | ||
const previousState = | ||
bodyClasses.contains("drawer-open") ? "open" : "closed"; | ||
|
||
let state; | ||
if (0 < arguments.length) { | ||
state = false === arguments[0] ? "closed" : "open"; | ||
} | ||
else { | ||
state = "open" === previousState ? "closed" : "open"; | ||
} | ||
|
||
bodyClasses.remove(`drawer-${previousState}`); | ||
bodyClasses.add(`drawer-${state}`); | ||
|
||
if ("open" === state) { | ||
document.addEventListener("click", closeSidebar, false); | ||
} | ||
}; | ||
|
||
/* Private Properties */ | ||
|
||
const html = document.documentElement; | ||
const body = document.body; | ||
const bodyClasses = body.classList; | ||
const sidebar = document.querySelector(".sidebar"); | ||
const sidebarToggles = document.querySelectorAll(".sidebar-toggle"); | ||
const displayControls = document.createElement("div"); | ||
|
||
displayControls.classList.add("display-controls"); | ||
sidebar.appendChild(displayControls); | ||
|
||
/* Private Methods */ | ||
|
||
const initProperty = function(property) { | ||
const config = gleamConfig[property]; | ||
|
||
displayControls.insertAdjacentHTML( | ||
"beforeend", | ||
config.values.reduce( | ||
(acc, item, index) => { | ||
const tooltip = | ||
item.label | ||
? `alt="${item.label}" title="${item.label}"` | ||
: ""; | ||
let inner; | ||
if (item.icons) { | ||
inner = self.icons(...item.icons); | ||
} | ||
else if (item.label) { | ||
inner = item.label; | ||
} | ||
else { | ||
inner = ""; | ||
} | ||
return ` | ||
${acc} | ||
<span class="label label-${index}" ${tooltip}> | ||
${inner} | ||
</span> | ||
`; | ||
}, | ||
`<button | ||
id="${property}-toggle" | ||
class="control control-${property} toggle toggle-0"> | ||
` | ||
) + ` | ||
</button> | ||
` | ||
); | ||
|
||
setProperty(null, property, function() { | ||
return self.getProperty(property); | ||
}); | ||
}; | ||
|
||
const setProperty = function(_event, property) { | ||
const previousValue = self.getProperty(property); | ||
|
||
const update = | ||
2 < arguments.length ? arguments[2] : gleamConfig[property].update; | ||
const value = update(); | ||
|
||
try { | ||
localStorage.setItem("Gleam." + property, value); | ||
} | ||
catch (_error) {} | ||
|
||
bodyClasses.remove(`${property}-${previousValue}`); | ||
bodyClasses.add(`${property}-${value}`); | ||
|
||
const isDefault = value === gleamConfig[property].values[0].value; | ||
const toggleClasses = | ||
document.querySelector(`#${property}-toggle`).classList; | ||
toggleClasses.remove(`toggle-${isDefault ? 1 : 0}`); | ||
toggleClasses.add(`toggle-${isDefault ? 0 : 1}`); | ||
|
||
try { | ||
gleamConfig[property].callback(value); | ||
} | ||
catch(_error) {} | ||
|
||
return value; | ||
} | ||
|
||
const setHashOffset = function() { | ||
const el = document.createElement("div"); | ||
el.style.cssText = | ||
` | ||
height: var(--hash-offset); | ||
pointer-events: none; | ||
position: absolute; | ||
visibility: hidden; | ||
width: 0; | ||
`; | ||
body.appendChild(el); | ||
self.hashOffset = parseInt( | ||
getComputedStyle(el).getPropertyValue("height") || "0" | ||
); | ||
body.removeChild(el); | ||
}; | ||
|
||
const closeSidebar = function(event) { | ||
if (! event.target.closest(".sidebar-toggle")) { | ||
document.removeEventListener("click", closeSidebar, false); | ||
self.toggleSidebar(false); | ||
} | ||
}; | ||
|
||
const init = function() { | ||
for (const property in gleamConfig) { | ||
initProperty(property); | ||
const toggle = document.querySelector(`#${property}-toggle`); | ||
toggle.addEventListener("click", function(event) { | ||
setProperty(event, property); | ||
}); | ||
} | ||
|
||
sidebarToggles.forEach(function(sidebarToggle) { | ||
sidebarToggle.addEventListener("click", function(event) { | ||
event.preventDefault(); | ||
self.toggleSidebar(); | ||
}); | ||
}); | ||
|
||
setHashOffset(); | ||
window.addEventListener("load", function(_event) { | ||
self.scrollToHash(); | ||
}); | ||
window.addEventListener("hashchange", function(_event) { | ||
self.scrollToHash(); | ||
}); | ||
|
||
document.querySelectorAll(` | ||
.module-name > a, | ||
.member-name a[href^='#'] | ||
`).forEach(function(title) { | ||
title.innerHTML = | ||
title.innerHTML.replace(/([A-Z])|([_/])/g, "$2<wbr>$1"); | ||
}); | ||
}; | ||
|
||
/* Initialise */ | ||
|
||
init(); | ||
|
||
return self; | ||
}(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
hljs.registerLanguage("gleam", function (hljs) { | ||
const KEYWORDS = | ||
"as assert case const external fn if import let " + | ||
"opaque pub todo try tuple type"; | ||
const STRING = { | ||
className: "string", | ||
variants: [{ begin: /"/, end: /"/ }], | ||
contains: [hljs.BACKSLASH_ESCAPE], | ||
relevance: 0, | ||
}; | ||
const NAME = { | ||
className: "variable", | ||
begin: "\\b[a-z][a-z0-9_]*\\b", | ||
relevance: 0, | ||
}; | ||
const DISCARD_NAME = { | ||
className: "comment", | ||
begin: "\\b_[a-z][a-z0-9_]*\\b", | ||
relevance: 0, | ||
}; | ||
const NUMBER = { | ||
className: "number", | ||
variants: [ | ||
{ | ||
// binary | ||
begin: "\\b0[bB](?:_?[01]+)+", | ||
}, | ||
{ | ||
// octal | ||
begin: "\\b0[oO](?:_?[0-7]+)+", | ||
}, | ||
{ | ||
// hex | ||
begin: "\\b0[xX](?:_?[0-9a-fA-F]+)+", | ||
}, | ||
{ | ||
// dec, float | ||
begin: "\\b\\d(?:_?\\d+)*(?:\\.(?:\\d(?:_?\\d+)*)*)?", | ||
}, | ||
], | ||
relevance: 0, | ||
}; | ||
|
||
return { | ||
name: "Gleam", | ||
aliases: ["gleam"], | ||
contains: [ | ||
hljs.C_LINE_COMMENT_MODE, | ||
STRING, | ||
{ | ||
// bit string | ||
begin: "<<", | ||
end: ">>", | ||
contains: [ | ||
{ | ||
className: "keyword", | ||
beginKeywords: | ||
"binary bytes int float bit_string bits utf8 utf16 utf32 " + | ||
"utf8_codepoint utf16_codepoint utf32_codepoint signed unsigned " + | ||
"big little native unit size", | ||
}, | ||
KEYWORDS, | ||
STRING, | ||
NAME, | ||
DISCARD_NAME, | ||
NUMBER, | ||
], | ||
relevance: 10, | ||
}, | ||
{ | ||
className: "function", | ||
beginKeywords: "fn", | ||
end: "\\(", | ||
excludeEnd: true, | ||
contains: [ | ||
{ | ||
className: "title", | ||
begin: "[a-z][a-z0-9_]*\\w*", | ||
relevance: 0, | ||
}, | ||
], | ||
}, | ||
{ | ||
className: "keyword", | ||
beginKeywords: KEYWORDS, | ||
}, | ||
{ | ||
// Type names and constructors | ||
className: "title", | ||
begin: "\\b[A-Z][A-Za-z0-9]*\\b", | ||
relevance: 0, | ||
}, | ||
{ | ||
className: "operator", | ||
begin: "[+\\-*/%!=<>&|.]+", | ||
relevance: 0, | ||
}, | ||
NAME, | ||
DISCARD_NAME, | ||
NUMBER, | ||
], | ||
}; | ||
}); | ||
document.querySelectorAll("pre code").forEach(block => { | ||
if (block.className === "") { | ||
block.classList.add("gleam"); | ||
} | ||
hljs.highlightBlock(block); | ||
}); |
Oops, something went wrong.