Introduce 'docs' for generating documentation for aiken libraries.

This commit is contained in:
KtorZ 2022-12-16 18:33:04 +01:00
parent 71e71fffe8
commit 16b0a9fbe4
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
13 changed files with 3984 additions and 4 deletions

143
Cargo.lock generated
View File

@ -108,12 +108,15 @@ name = "aiken-project"
version = "0.0.26" version = "0.0.26"
dependencies = [ dependencies = [
"aiken-lang", "aiken-lang",
"askama",
"hex", "hex",
"ignore", "ignore",
"itertools",
"miette", "miette",
"pallas", "pallas",
"pallas-traverse", "pallas-traverse",
"petgraph", "petgraph",
"pulldown-cmark",
"regex", "regex",
"serde", "serde",
"serde_json", "serde_json",
@ -135,6 +138,52 @@ version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
[[package]]
name = "askama"
version = "0.10.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d298738b6e47e1034e560e5afe63aa488fea34e25ec11b855a76f0d7b8e73134"
dependencies = [
"askama_derive",
"askama_escape",
"askama_shared",
]
[[package]]
name = "askama_derive"
version = "0.10.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca2925c4c290382f9d2fa3d1c1b6a63fa1427099721ecca4749b154cc9c25522"
dependencies = [
"askama_shared",
"proc-macro2",
"syn",
]
[[package]]
name = "askama_escape"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341"
[[package]]
name = "askama_shared"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d6083ccb191711e9c2b80b22ee24a8381a18524444914c746d4239e21d1afaf"
dependencies = [
"askama_escape",
"humansize",
"nom",
"num-traits",
"percent-encoding",
"proc-macro2",
"quote",
"serde",
"syn",
"toml",
]
[[package]] [[package]]
name = "atty" name = "atty"
version = "0.2.14" version = "0.2.14"
@ -200,6 +249,18 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitvec"
version = "0.19.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55f93d0ef3363c364d5976646a38f04cf67cfe1d4c8d160cdea02cab2c116b33"
dependencies = [
"funty",
"radium",
"tap",
"wyz",
]
[[package]] [[package]]
name = "bstr" name = "bstr"
version = "0.2.17" version = "0.2.17"
@ -389,6 +450,12 @@ dependencies = [
"percent-encoding", "percent-encoding",
] ]
[[package]]
name = "funty"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7"
[[package]] [[package]]
name = "getrandom" name = "getrandom"
version = "0.2.7" version = "0.2.7"
@ -455,6 +522,12 @@ version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
[[package]]
name = "humansize"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02296996cb8796d7c6e3bc2d9211b7802812d36999a51bb754123ead7d37d026"
[[package]] [[package]]
name = "idna" name = "idna"
version = "0.3.0" version = "0.3.0"
@ -535,6 +608,19 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "lexical-core"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6607c62aa161d23d17a9072cc5da0be67cdfc89d3afb1e8d9c842bebc2525ffe"
dependencies = [
"arrayvec",
"bitflags",
"cfg-if",
"ryu",
"static_assertions",
]
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.133" version = "0.2.133"
@ -642,6 +728,19 @@ dependencies = [
"adler", "adler",
] ]
[[package]]
name = "nom"
version = "6.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7413f999671bd4745a7b624bd370a569fb6bc574b23c83a3c5ed2e453f3d5e2"
dependencies = [
"bitvec",
"funty",
"lexical-core",
"memchr",
"version_check",
]
[[package]] [[package]]
name = "num-traits" name = "num-traits"
version = "0.2.15" version = "0.2.15"
@ -937,6 +1036,17 @@ dependencies = [
"tempfile", "tempfile",
] ]
[[package]]
name = "pulldown-cmark"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffade02495f22453cd593159ea2f59827aae7f53fa8323f756799b670881dcf8"
dependencies = [
"bitflags",
"memchr",
"unicase",
]
[[package]] [[package]]
name = "quick-error" name = "quick-error"
version = "1.2.3" version = "1.2.3"
@ -958,6 +1068,12 @@ dependencies = [
"proc-macro2", "proc-macro2",
] ]
[[package]]
name = "radium"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "941ba9d78d8e2f7ce474c015eea4d9c6d25b6a3327f9832ee29a4de27f91bbb8"
[[package]] [[package]]
name = "rand" name = "rand"
version = "0.8.5" version = "0.8.5"
@ -1120,6 +1236,12 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f67ad224767faa3c7d8b6d91985b78e70a1324408abcb1cfcc2be4c06bc06043" checksum = "f67ad224767faa3c7d8b6d91985b78e70a1324408abcb1cfcc2be4c06bc06043"
[[package]]
name = "static_assertions"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]] [[package]]
name = "strsim" name = "strsim"
version = "0.10.0" version = "0.10.0"
@ -1184,6 +1306,12 @@ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]]
name = "tap"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
[[package]] [[package]]
name = "tempfile" name = "tempfile"
version = "3.3.0" version = "3.3.0"
@ -1334,6 +1462,15 @@ version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0685c84d5d54d1c26f7d3eb96cd41550adb97baed141a761cf335d3d33bcd0ae" checksum = "0685c84d5d54d1c26f7d3eb96cd41550adb97baed141a761cf335d3d33bcd0ae"
[[package]]
name = "unicase"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6"
dependencies = [
"version_check",
]
[[package]] [[package]]
name = "unicode-bidi" name = "unicode-bidi"
version = "0.3.8" version = "0.3.8"
@ -1482,6 +1619,12 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "wyz"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214"
[[package]] [[package]]
name = "yansi" name = "yansi"
version = "0.5.1" version = "0.5.1"

View File

@ -10,16 +10,19 @@ authors = ["Lucas Rosa <x@rvcas.dev>", "Kasey White <kwhitemsg@gmail.com>"]
[dependencies] [dependencies]
aiken-lang = { path = "../lang", version = "0.0.26" } aiken-lang = { path = "../lang", version = "0.0.26" }
askama = "0.10.5"
hex = "0.4.3"
ignore = "0.4.18" ignore = "0.4.18"
uplc = { path = '../uplc', version = "0.0.25" } itertools = "0.10.1"
miette = { version = "5.3.0", features = ["fancy"] } miette = { version = "5.3.0", features = ["fancy"] }
pallas = "0.14.0"
pallas-traverse = "0.14.0"
petgraph = "0.6.2" petgraph = "0.6.2"
pulldown-cmark = { version = "0.8.0", default-features = false }
regex = "1.6.0" regex = "1.6.0"
serde = { version = "1.0.144", features = ["derive"] } serde = { version = "1.0.144", features = ["derive"] }
serde_json = { version = "1.0.85", features = ["preserve_order"] } serde_json = { version = "1.0.85", features = ["preserve_order"] }
thiserror = "1.0.37" thiserror = "1.0.37"
toml = "0.5.9" toml = "0.5.9"
uplc = { path = '../uplc', version = "0.0.25" }
walkdir = "2.3.2" walkdir = "2.3.2"
hex = "0.4.3"
pallas = "0.14.0"
pallas-traverse = "0.14.0"

374
crates/project/src/docs.rs Normal file
View File

@ -0,0 +1,374 @@
use crate::{config::Config, module::CheckedModule};
use aiken_lang::{
ast::{Definition, TypedDefinition},
format,
};
use askama::Template;
use itertools::Itertools;
use pulldown_cmark as markdown;
use serde::Serialize;
use serde_json as json;
use std::{
path::PathBuf,
time::{Duration, SystemTime},
};
const MAX_COLUMNS: isize = 80;
const VERSION: &str = env!("CARGO_PKG_VERSION");
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct DocFile {
pub path: PathBuf,
pub content: String,
}
#[derive(Template)]
#[template(path = "module.html")]
struct ModuleTemplate<'a> {
aiken_version: &'a str,
breadcrumbs: String,
page_title: &'a str,
module_name: String,
project_name: &'a str,
project_version: &'a str,
links: &'a Vec<DocLink>,
modules: &'a Vec<DocLink>,
functions: Vec<DocFunction>,
types: Vec<DocType>,
constants: Vec<DocConstant>,
documentation: String,
timestamp: String,
}
#[derive(Template)]
#[template(path = "page.html")]
struct PageTemplate<'a> {
aiken_version: &'a str,
breadcrumbs: &'a str,
page_title: &'a str,
project_name: &'a str,
project_version: &'a str,
links: &'a Vec<DocLink>,
modules: &'a Vec<DocLink>,
content: String,
timestamp: &'a str,
}
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone)]
struct DocLink {
name: String,
path: String,
}
#[derive(Serialize, PartialEq, Eq, PartialOrd, Ord, Clone)]
struct SearchIndex {
doc: String,
title: String,
content: String,
url: String,
}
/// Generate documentation files for a given project.
///
/// The documentation is built using template files located at the root of this crate.
/// With the documentation, we also build a client-side search index to ease navigation
/// across multiple modules.
pub fn generate_all(root: &PathBuf, config: &Config, modules: Vec<&CheckedModule>) -> Vec<DocFile> {
let timestamp = new_timestamp();
let mut output_files: Vec<DocFile> = vec![];
let mut search_indexes: Vec<SearchIndex> = vec![];
for module in &modules {
let (indexes, file) = generate_module(config, module, &timestamp);
search_indexes.extend(indexes);
output_files.push(file);
}
output_files.extend(generate_static_assets(search_indexes));
output_files.push(generate_readme(root, config, modules, &timestamp));
output_files
}
fn generate_module(
config: &Config,
module: &CheckedModule,
timestamp: &Duration,
) -> (Vec<SearchIndex>, DocFile) {
let mut search_indexes = vec![];
// Functions
let functions: Vec<DocFunction> = module
.ast
.definitions
.iter()
.flat_map(DocFunction::from_definition)
.sorted()
.collect();
functions.iter().for_each(|function| {
search_indexes.push(SearchIndex {
doc: module.name.to_string(),
title: function.name.to_string(),
content: format!("{}\n{}", function.signature, function.documentation),
url: format!("{}.html#{}", module.name, function.name),
})
});
// Types
// Constants
// Template
search_indexes.push(SearchIndex {
doc: module.name.to_string(),
title: module.name.to_string(),
content: String::new(),
url: format!("{}.html", module.name),
});
let template = ModuleTemplate {
aiken_version: VERSION,
breadcrumbs: to_breadcrumbs(&module.name),
links: &vec![],
documentation: render_markdown(&module.ast.docs.iter().join("\n")),
modules: &vec![],
project_name: &config.name,
page_title: &format!("{} - {}", module.name, config.name),
module_name: module.name.clone(),
project_version: &config.version.to_string(),
functions,
types: vec![],
constants: vec![],
timestamp: timestamp.as_secs().to_string(),
};
(
search_indexes,
DocFile {
path: PathBuf::from(format!("{}.html", module.name)),
content: template
.render()
.expect("Module documentation template rendering"),
},
)
}
fn generate_static_assets(search_indexes: Vec<SearchIndex>) -> Vec<DocFile> {
let mut assets: Vec<DocFile> = vec![];
assets.push(DocFile {
path: PathBuf::from("css/atom-one-light.min.css"),
content: std::include_str!("../templates/css/atom-one-light.min.css").to_string(),
});
assets.push(DocFile {
path: PathBuf::from("css/atom-one-dark.min.css"),
content: std::include_str!("../templates/css/atom-one-dark.min.css").to_string(),
});
assets.push(DocFile {
path: PathBuf::from("css/index.css"),
content: std::include_str!("../templates/css/index.css").to_string(),
});
assets.push(DocFile {
path: PathBuf::from("js/highlight.min.js"),
content: std::include_str!("../templates/js/highlight.min.js").to_string(),
});
assets.push(DocFile {
path: PathBuf::from("js/highlightjs-gleam.js"),
content: std::include_str!("../templates/js/highlightjs-gleam.js").to_string(),
});
assets.push(DocFile {
path: PathBuf::from("js/lunr.min.js"),
content: std::include_str!("../templates/js/lunr.min.js").to_string(),
});
assets.push(DocFile {
path: PathBuf::from("js/index.js"),
content: std::include_str!("../templates/js/index.js").to_string(),
});
assets.push(DocFile {
path: PathBuf::from("search-data.js"),
content: format!(
"window.Aiken.initSearch({});",
json::to_string(&escape_html_contents(search_indexes))
.expect("search index serialization")
),
});
assets
}
fn generate_readme(
root: &PathBuf,
config: &Config,
modules: Vec<&CheckedModule>,
timestamp: &Duration,
) -> DocFile {
let path = PathBuf::from("index.html");
let content = std::fs::read_to_string(root.join("README.md")).unwrap_or_default();
let mut modules_links = vec![];
for module in modules {
let module_path = [&module.name.clone(), ".html"].concat();
modules_links.push(DocLink {
path: module_path,
name: module.name.to_string().clone(),
});
}
modules_links.sort();
let template = PageTemplate {
aiken_version: VERSION,
breadcrumbs: ".",
links: &vec![],
modules: &modules_links,
project_name: &config.name,
page_title: &config.name,
project_version: &config.version.to_string(),
content: render_markdown(&content),
timestamp: &timestamp.as_secs().to_string(),
};
DocFile {
path,
content: template.render().expect("Page template rendering"),
}
}
#[derive(PartialEq, Eq, PartialOrd, Ord)]
struct DocFunction {
name: String,
signature: String,
documentation: String,
source_url: String,
}
impl DocFunction {
fn from_definition(def: &TypedDefinition) -> Option<Self> {
match def {
Definition::Fn(func_def) if func_def.public => Some(DocFunction {
name: func_def.name.clone(),
documentation: func_def
.doc
.as_deref()
.map(render_markdown)
.unwrap_or_default(),
signature: format::Formatter::new()
.docs_fn_signature(
true,
&func_def.name,
&func_def.arguments,
func_def.return_type.clone(),
)
.to_pretty_string(MAX_COLUMNS),
source_url: "TODO: source_url".to_string(),
}),
_ => None,
}
}
}
#[derive(PartialEq, Eq, PartialOrd, Ord)]
struct DocConstant {
name: String,
definition: String,
documentation: String,
text_documentation: String,
source_url: String,
}
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug)]
struct DocType {
name: String,
definition: String,
documentation: String,
constructors: Vec<DocTypeConstructor>,
text_documentation: String,
source_url: String,
}
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug)]
struct DocTypeConstructor {
definition: String,
documentation: String,
text_documentation: String,
arguments: Vec<DocTypeConstructorArg>,
}
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug)]
struct DocTypeConstructorArg {
name: String,
doc: String,
}
// ------ Extra Helpers
fn render_markdown(text: &str) -> String {
let mut s = String::with_capacity(text.len() * 3 / 2);
let p = markdown::Parser::new_ext(text, markdown::Options::all());
markdown::html::push_html(&mut s, p);
s
}
fn escape_html_contents(indexes: Vec<SearchIndex>) -> Vec<SearchIndex> {
fn escape_html_content(it: String) -> String {
it.replace('&', "&amp;")
.replace('<', "&lt;")
.replace('>', "&gt;")
.replace('\"', "&quot;")
.replace('\'', "&#39;")
}
indexes
.into_iter()
.map(|idx| SearchIndex {
doc: idx.doc,
title: idx.title,
content: escape_html_content(idx.content),
url: idx.url,
})
.collect::<Vec<SearchIndex>>()
}
fn new_timestamp() -> Duration {
SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.expect("get current timestamp")
}
fn to_breadcrumbs(path: &str) -> String {
let unnest = path
.strip_prefix('/')
.unwrap_or(path)
.split('/')
.skip(1)
.map(|_| "..")
.join("/");
if unnest.is_empty() {
".".to_string()
} else {
unnest
}
}
#[test]
fn to_breadcrumbs_test() {
// Pages
assert_eq!(to_breadcrumbs("a.html"), ".");
assert_eq!(to_breadcrumbs("/a.html"), ".");
assert_eq!(to_breadcrumbs("/a/b.html"), "..");
assert_eq!(to_breadcrumbs("/a/b/c.html"), "../..");
// Modules
assert_eq!(to_breadcrumbs("a"), ".");
assert_eq!(to_breadcrumbs("a/b"), "..");
assert_eq!(to_breadcrumbs("a/b/c"), "../..");
}

View File

@ -0,0 +1,269 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>{{ page_title }}</title>
<meta name="theme-color" content="#ffaff3" media="(prefers-color-scheme: light)"/>
<meta name="theme-color" content="#33384d" media="(prefers-color-scheme: dark)"/>
<link rel="stylesheet" href="{{ breadcrumbs }}/css/index.css?v={{ aiken_version }}" type="text/css"/>
<!-- The docs_config.js file is provided by HexDocs and shared between multiple versions of the same package. -->
<script src="{{ breadcrumbs }}/docs_config.js"></script>
<link id="syntax-theme" rel="stylesheet" href="{{ breadcrumbs }}/css/atom-one-light.min.css?v={{ aiken_version }}"/>
</head>
<body class="prewrap-off theme-light drawer-closed">
<script>
"use strict";
window.breadcrumbs = '{{ breadcrumbs }}';
const aikenConfig = {
theme: {
values: (() => {
const dark = {
value: "dark",
label: "Switch to light mode",
icons: ["moon"],
};
const light = {
value: "light",
label: "Switch to dark mode",
icons: ["sun"],
};
return (
window.matchMedia("(prefers-color-scheme: dark)").matches
? [dark, light]
: [light, dark]
).map((item, index) => {
item.icons.push(`toggle-${0 === index ? "left" : "right"}`);
return item;
});
})(),
update: () => "light" === Aiken.getProperty("theme") ? "dark" : "light",
callback: function(value) {
const syntaxThemes = {
dark: "atom-one-dark",
light: "atom-one-light",
};
const syntaxTheme = document.querySelector("#syntax-theme");
const hrefParts = syntaxTheme.href.match(
/^(.*?)([^/\\#?]+?)((?:\.min)?\.css.*)$/i
);
if (syntaxThemes[value] !== hrefParts[2]) {
hrefParts[2] = syntaxThemes[value];
hrefParts.shift();
syntaxTheme.href = hrefParts.join("");
}
},
},
prewrap: {
values: [
{
value: "off",
label: "Switch to line-wrapped snippets",
icons: ["more-horizontal", "toggle-left"],
},
{
value: "on",
label: "Switch to non-wrapped snippets",
icons: ["more-vertical", "toggle-right"],
},
],
update: () => "off" === Aiken.getProperty("prewrap") ? "on" : "off",
},
};
</script>
<script>
"use strict";
/* Initialise options before any content loads */
void function() {
for (const property in aikenConfig) {
const name = `Aiken.${property}`;
let value;
try {
value = localStorage.getItem(name);
if (value.startsWith('"') && value.endsWith('"')) {
localStorage.setItem(name, value.slice(1, value.length - 1));
}
}
catch (_error) {}
const defaultValue = aikenConfig[property].values[0].value;
try {
value = localStorage.getItem(name);
}
catch(_error) {}
if (-1 < [null, undefined].indexOf(value)) {
value = defaultValue;
}
const bodyClasses = document.body.classList;
bodyClasses.remove(`${property}-${defaultValue}`);
bodyClasses.add(`${property}-${value}`);
try {
aikenConfig[property].callback(value);
}
catch(_error) {}
}
}();
</script>
<header class="page-header">
<button class="sidebar-toggle" tabindex="0">
<svg class="label label-closed icon icon-menu" alt="Open Menu" title="Open Menu"><use xlink:href="#icon-menu"></use></svg>
<svg class="label label-open icon icon-x-circle" alt="Close Menu" title="Close Menu"><use xlink:href="#icon-x-circle"></use></svg>
</button>
<h2>
<a href="{{ breadcrumbs }}/">{{ project_name }}</a>
<span id="project-version">
<span> - v{{ project_version }} </span>
</span>
<script>
"use strict";
if ("undefined" !== typeof versionNodes) {
const currentVersion = "v{{ project_version }}";
if (! versionNodes.find(element => element.version === currentVersion)) {
versionNodes.unshift({ version: currentVersion, url: "#" });
}
document.querySelector("#project-version").innerHTML =
versionNodes.reduce(
(acc, element) => {
const status =
currentVersion === element.version ? "selected disabled" : "";
return `
${acc}
<option value="${element.url}" ${status}>
${element.version}
</option>
`;
},
`
<form autocomplete="off">
<select onchange="window.location.href = this.value">
`
) + `
</select>
<svg class="icon icon-chevrons-down"><use xlink:href="#icon-chevrons-down"></use></svg>
</form>
`;
}
</script>
</h2>
<div class="search">
<div class="search-input-wrap">
<input type="text" id="search-input" class="search-input" tabindex="0" aria-label="Search {{ project_name }}" autocomplete="off">
<label for="search-input" class="search-label"><svg viewBox="0 0 24 24" class="search-icon"><use xlink:href="#icon-svg-search"></use></svg></label>
</div>
<div id="search-results" class="search-results"></div>
</div>
<button class="search-nav-button" id="search-nav-button" tabindex="0">
<svg class="label icon icon-x-circle" alt="Open Search" title="Open Search"><use xlink:href="#icon-svg-search"></use></svg>
</button>
</header>
<div class="page">
<nav class="sidebar">
<button class="sidebar-toggle" tabindex="1">
<svg class="label icon icon-x-circle" alt="Close Menu" title="Close Menu"><use xlink:href="#icon-x-circle"></use></svg>
</button>
{% if !links.is_empty() %}
<h2>Links</h2>
<ul>
{% for link in links %}
<li><a href="{{ link.path }}">{{ link.name }}</a></li>
{% endfor %}
</ul>
{% endif %}
<h2>Modules</h2>
<ul>
{% for module in modules %}
<li><a href="{{ breadcrumbs }}/{{ module.path }}">{{ module.name }}</a></li>
{% endfor %}
</ul>
{% block sidebar_content %}{% endblock %}
</nav>
<main class="content">
{% block content %}{% endblock %}
</main>
<div class="search-overlay"></div>
</div>
<script>
"use strict";
const pride = () => document.body.classList.toggle("show-pride");
</script>
<a class="pride-button" onclick="pride()"></a>
<footer class="pride" onclick="pride()">
<div class="blue">Lucy</div>
<div class="pink">says</div>
<div class="white">trans</div>
<div class="pink">rights</div>
<div class="blue">now</div>
</footer>
<svg class="svg-lib" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<symbol id="icon-chevrons-down" viewBox="0 0 24 24"><path d="M6.293 13.707l5 5c0.391 0.391 1.024 0.391 1.414 0l5-5c0.391-0.391 0.391-1.024 0-1.414s-1.024-0.391-1.414 0l-4.293 4.293-4.293-4.293c-0.391-0.391-1.024-0.391-1.414 0s-0.391 1.024 0 1.414zM6.293 6.707l5 5c0.391 0.391 1.024 0.391 1.414 0l5-5c0.391-0.391 0.391-1.024 0-1.414s-1.024-0.391-1.414 0l-4.293 4.293-4.293-4.293c-0.391-0.391-1.024-0.391-1.414 0s-0.391 1.024 0 1.414z"></path></symbol>
<symbol id="icon-menu" viewBox="0 0 24 24"><path d="M3 13h18c0.552 0 1-0.448 1-1s-0.448-1-1-1h-18c-0.552 0-1 0.448-1 1s0.448 1 1 1zM3 7h18c0.552 0 1-0.448 1-1s-0.448-1-1-1h-18c-0.552 0-1 0.448-1 1s0.448 1 1 1zM3 19h18c0.552 0 1-0.448 1-1s-0.448-1-1-1h-18c-0.552 0-1 0.448-1 1s0.448 1 1 1z"></path></symbol>
<symbol id="icon-moon" viewBox="0 0 24 24"><path d="M21.996 12.882c0.022-0.233-0.038-0.476-0.188-0.681-0.325-0.446-0.951-0.544-1.397-0.219-0.95 0.693-2.060 1.086-3.188 1.162-1.368 0.092-2.765-0.283-3.95-1.158-1.333-0.985-2.139-2.415-2.367-3.935s0.124-3.124 1.109-4.456c0.142-0.191 0.216-0.435 0.191-0.691-0.053-0.55-0.542-0.952-1.092-0.898-2.258 0.22-4.314 1.18-5.895 2.651-1.736 1.615-2.902 3.847-3.137 6.386-0.254 2.749 0.631 5.343 2.266 7.311s4.022 3.313 6.772 3.567 5.343-0.631 7.311-2.266 3.313-4.022 3.567-6.772zM19.567 14.674c-0.49 1.363-1.335 2.543-2.416 3.441-1.576 1.309-3.648 2.016-5.848 1.813s-4.108-1.278-5.417-2.854-2.016-3.648-1.813-5.848c0.187-2.032 1.117-3.814 2.507-5.106 0.782-0.728 1.71-1.3 2.731-1.672-0.456 1.264-0.577 2.606-0.384 3.899 0.303 2.023 1.38 3.934 3.156 5.247 1.578 1.167 3.448 1.668 5.272 1.545 0.752-0.050 1.496-0.207 2.21-0.465z"></path></symbol>
<symbol id="icon-more-horizontal" viewBox="0 0 24 24"><path d="M14 12c0-0.552-0.225-1.053-0.586-1.414s-0.862-0.586-1.414-0.586-1.053 0.225-1.414 0.586-0.586 0.862-0.586 1.414 0.225 1.053 0.586 1.414 0.862 0.586 1.414 0.586 1.053-0.225 1.414-0.586 0.586-0.862 0.586-1.414zM21 12c0-0.552-0.225-1.053-0.586-1.414s-0.862-0.586-1.414-0.586-1.053 0.225-1.414 0.586-0.586 0.862-0.586 1.414 0.225 1.053 0.586 1.414 0.862 0.586 1.414 0.586 1.053-0.225 1.414-0.586 0.586-0.862 0.586-1.414zM7 12c0-0.552-0.225-1.053-0.586-1.414s-0.862-0.586-1.414-0.586-1.053 0.225-1.414 0.586-0.586 0.862-0.586 1.414 0.225 1.053 0.586 1.414 0.862 0.586 1.414 0.586 1.053-0.225 1.414-0.586 0.586-0.862 0.586-1.414z"></path></symbol>
<symbol id="icon-more-vertical" viewBox="0 0 24 24"><path d="M14 12c0-0.552-0.225-1.053-0.586-1.414s-0.862-0.586-1.414-0.586-1.053 0.225-1.414 0.586-0.586 0.862-0.586 1.414 0.225 1.053 0.586 1.414 0.862 0.586 1.414 0.586 1.053-0.225 1.414-0.586 0.586-0.862 0.586-1.414zM14 5c0-0.552-0.225-1.053-0.586-1.414s-0.862-0.586-1.414-0.586-1.053 0.225-1.414 0.586-0.586 0.862-0.586 1.414 0.225 1.053 0.586 1.414 0.862 0.586 1.414 0.586 1.053-0.225 1.414-0.586 0.586-0.862 0.586-1.414zM14 19c0-0.552-0.225-1.053-0.586-1.414s-0.862-0.586-1.414-0.586-1.053 0.225-1.414 0.586-0.586 0.862-0.586 1.414 0.225 1.053 0.586 1.414 0.862 0.586 1.414 0.586 1.053-0.225 1.414-0.586 0.586-0.862 0.586-1.414z"></path></symbol>
<symbol id="icon-star" viewBox="0 0 24 24"><path d="M12.897 1.557c-0.092-0.189-0.248-0.352-0.454-0.454-0.495-0.244-1.095-0.041-1.339 0.454l-2.858 5.789-6.391 0.935c-0.208 0.029-0.411 0.127-0.571 0.291-0.386 0.396-0.377 1.029 0.018 1.414l4.623 4.503-1.091 6.362c-0.036 0.207-0.006 0.431 0.101 0.634 0.257 0.489 0.862 0.677 1.351 0.42l5.714-3.005 5.715 3.005c0.186 0.099 0.408 0.139 0.634 0.101 0.544-0.093 0.91-0.61 0.817-1.155l-1.091-6.362 4.623-4.503c0.151-0.146 0.259-0.344 0.292-0.572 0.080-0.546-0.298-1.054-0.845-1.134l-6.39-0.934zM12 4.259l2.193 4.444c0.151 0.305 0.436 0.499 0.752 0.547l4.906 0.717-3.549 3.457c-0.244 0.238-0.341 0.569-0.288 0.885l0.837 4.883-4.386-2.307c-0.301-0.158-0.647-0.148-0.931 0l-4.386 2.307 0.837-4.883c0.058-0.336-0.059-0.661-0.288-0.885l-3.549-3.457 4.907-0.718c0.336-0.049 0.609-0.26 0.752-0.546z"></path></symbol>
<symbol id="icon-sun" viewBox="0 0 24 24"><path d="M18 12c0-1.657-0.673-3.158-1.757-4.243s-2.586-1.757-4.243-1.757-3.158 0.673-4.243 1.757-1.757 2.586-1.757 4.243 0.673 3.158 1.757 4.243 2.586 1.757 4.243 1.757 3.158-0.673 4.243-1.757 1.757-2.586 1.757-4.243zM16 12c0 1.105-0.447 2.103-1.172 2.828s-1.723 1.172-2.828 1.172-2.103-0.447-2.828-1.172-1.172-1.723-1.172-2.828 0.447-2.103 1.172-2.828 1.723-1.172 2.828-1.172 2.103 0.447 2.828 1.172 1.172 1.723 1.172 2.828zM11 1v2c0 0.552 0.448 1 1 1s1-0.448 1-1v-2c0-0.552-0.448-1-1-1s-1 0.448-1 1zM11 21v2c0 0.552 0.448 1 1 1s1-0.448 1-1v-2c0-0.552-0.448-1-1-1s-1 0.448-1 1zM3.513 4.927l1.42 1.42c0.391 0.391 1.024 0.391 1.414 0s0.391-1.024 0-1.414l-1.42-1.42c-0.391-0.391-1.024-0.391-1.414 0s-0.391 1.024 0 1.414zM17.653 19.067l1.42 1.42c0.391 0.391 1.024 0.391 1.414 0s0.391-1.024 0-1.414l-1.42-1.42c-0.391-0.391-1.024-0.391-1.414 0s-0.391 1.024 0 1.414zM1 13h2c0.552 0 1-0.448 1-1s-0.448-1-1-1h-2c-0.552 0-1 0.448-1 1s0.448 1 1 1zM21 13h2c0.552 0 1-0.448 1-1s-0.448-1-1-1h-2c-0.552 0-1 0.448-1 1s0.448 1 1 1zM4.927 20.487l1.42-1.42c0.391-0.391 0.391-1.024 0-1.414s-1.024-0.391-1.414 0l-1.42 1.42c-0.391 0.391-0.391 1.024 0 1.414s1.024 0.391 1.414 0zM19.067 6.347l1.42-1.42c0.391-0.391 0.391-1.024 0-1.414s-1.024-0.391-1.414 0l-1.42 1.42c-0.391 0.391-0.391 1.024 0 1.414s1.024 0.391 1.414 0z"></path></symbol>
<symbol id="icon-toggle-left" viewBox="0 0 24 24"><path d="M8 4c-2.209 0-4.21 0.897-5.657 2.343s-2.343 3.448-2.343 5.657 0.897 4.21 2.343 5.657 3.448 2.343 5.657 2.343h8c2.209 0 4.21-0.897 5.657-2.343s2.343-3.448 2.343-5.657-0.897-4.21-2.343-5.657-3.448-2.343-5.657-2.343zM8 6h8c1.657 0 3.156 0.67 4.243 1.757s1.757 2.586 1.757 4.243-0.67 3.156-1.757 4.243-2.586 1.757-4.243 1.757h-8c-1.657 0-3.156-0.67-4.243-1.757s-1.757-2.586-1.757-4.243 0.67-3.156 1.757-4.243 2.586-1.757 4.243-1.757zM12 12c0-1.104-0.449-2.106-1.172-2.828s-1.724-1.172-2.828-1.172-2.106 0.449-2.828 1.172-1.172 1.724-1.172 2.828 0.449 2.106 1.172 2.828 1.724 1.172 2.828 1.172 2.106-0.449 2.828-1.172 1.172-1.724 1.172-2.828zM10 12c0 0.553-0.223 1.051-0.586 1.414s-0.861 0.586-1.414 0.586-1.051-0.223-1.414-0.586-0.586-0.861-0.586-1.414 0.223-1.051 0.586-1.414 0.861-0.586 1.414-0.586 1.051 0.223 1.414 0.586 0.586 0.861 0.586 1.414z"></path></symbol>
<symbol id="icon-toggle-right" viewBox="0 0 24 24"><path d="M8 4c-2.209 0-4.21 0.897-5.657 2.343s-2.343 3.448-2.343 5.657 0.897 4.21 2.343 5.657 3.448 2.343 5.657 2.343h8c2.209 0 4.21-0.897 5.657-2.343s2.343-3.448 2.343-5.657-0.897-4.21-2.343-5.657-3.448-2.343-5.657-2.343zM8 6h8c1.657 0 3.156 0.67 4.243 1.757s1.757 2.586 1.757 4.243-0.67 3.156-1.757 4.243-2.586 1.757-4.243 1.757h-8c-1.657 0-3.156-0.67-4.243-1.757s-1.757-2.586-1.757-4.243 0.67-3.156 1.757-4.243 2.586-1.757 4.243-1.757zM20 12c0-1.104-0.449-2.106-1.172-2.828s-1.724-1.172-2.828-1.172-2.106 0.449-2.828 1.172-1.172 1.724-1.172 2.828 0.449 2.106 1.172 2.828 1.724 1.172 2.828 1.172 2.106-0.449 2.828-1.172 1.172-1.724 1.172-2.828zM18 12c0 0.553-0.223 1.051-0.586 1.414s-0.861 0.586-1.414 0.586-1.051-0.223-1.414-0.586-0.586-0.861-0.586-1.414 0.223-1.051 0.586-1.414 0.861-0.586 1.414-0.586 1.051 0.223 1.414 0.586 0.586 0.861 0.586 1.414z"></path></symbol>
<symbol id="icon-x-circle" viewBox="0 0 24 24"><path d="M23 12c0-3.037-1.232-5.789-3.222-7.778s-4.741-3.222-7.778-3.222-5.789 1.232-7.778 3.222-3.222 4.741-3.222 7.778 1.232 5.789 3.222 7.778 4.741 3.222 7.778 3.222 5.789-1.232 7.778-3.222 3.222-4.741 3.222-7.778zM21 12c0 2.486-1.006 4.734-2.636 6.364s-3.878 2.636-6.364 2.636-4.734-1.006-6.364-2.636-2.636-3.878-2.636-6.364 1.006-4.734 2.636-6.364 3.878-2.636 6.364-2.636 4.734 1.006 6.364 2.636 2.636 3.878 2.636 6.364zM8.293 9.707l2.293 2.293-2.293 2.293c-0.391 0.391-0.391 1.024 0 1.414s1.024 0.391 1.414 0l2.293-2.293 2.293 2.293c0.391 0.391 1.024 0.391 1.414 0s0.391-1.024 0-1.414l-2.293-2.293 2.293-2.293c0.391-0.391 0.391-1.024 0-1.414s-1.024-0.391-1.414 0l-2.293 2.293-2.293-2.293c-0.391-0.391-1.024-0.391-1.414 0s-0.391 1.024 0 1.414z"></path></symbol>
<symbol id="icon-svg-search" viewBox="0 0 24 24">
<title>Search</title>
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-search">
<circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line>
</svg>
</symbol>
<symbol id="icon-svg-doc" viewBox="0 0 24 24">
<title>Document</title>
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-file">
<path d="M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"></path><polyline points="13 2 13 9 20 9"></polyline>
</svg>
</symbol>
</defs>
</svg>
<script src="{{ breadcrumbs }}/js/highlight.min.js?v={{ aiken_version }}"></script>
<script src="{{ breadcrumbs }}/js/highlightjs-gleam.js?v={{ aiken_version }}"></script>
<script>
document.querySelectorAll("pre code").forEach((elem) => {
if (elem.className === "") {
elem.classList.add("gleam");
}
});
hljs.highlightAll();
</script>
<script src="{{ breadcrumbs }}/js/lunr.min.js?v={{ aiken_version }}"></script>
<script src="{{ breadcrumbs }}/js/index.js?v={{ timestamp }}"></script>
<!-- Load the search index using JSONP to avoid CORS issues -->
<script src="{{ breadcrumbs }}/search-data.js?v={{ timestamp }}"></script>
</body>
</html>

View File

@ -0,0 +1 @@
pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}.hljs{color:#abb2bf;background:#282c34}.hljs-comment,.hljs-quote{color:#5c6370;font-style:italic}.hljs-doctag,.hljs-formula,.hljs-keyword{color:#c678dd}.hljs-deletion,.hljs-name,.hljs-section,.hljs-selector-tag,.hljs-subst{color:#e06c75}.hljs-literal{color:#56b6c2}.hljs-addition,.hljs-attribute,.hljs-meta .hljs-string,.hljs-regexp,.hljs-string{color:#98c379}.hljs-attr,.hljs-number,.hljs-selector-attr,.hljs-selector-class,.hljs-selector-pseudo,.hljs-template-variable,.hljs-type,.hljs-variable{color:#d19a66}.hljs-bullet,.hljs-link,.hljs-meta,.hljs-selector-id,.hljs-symbol,.hljs-title{color:#61aeee}.hljs-built_in,.hljs-class .hljs-title,.hljs-title.class_{color:#e6c07b}.hljs-emphasis{font-style:italic}.hljs-strong{font-weight:700}.hljs-link{text-decoration:underline}

View File

@ -0,0 +1 @@
pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}.hljs{color:#383a42;background:#fafafa}.hljs-comment,.hljs-quote{color:#a0a1a7;font-style:italic}.hljs-doctag,.hljs-formula,.hljs-keyword{color:#a626a4}.hljs-deletion,.hljs-name,.hljs-section,.hljs-selector-tag,.hljs-subst{color:#e45649}.hljs-literal{color:#0184bb}.hljs-addition,.hljs-attribute,.hljs-meta .hljs-string,.hljs-regexp,.hljs-string{color:#50a14f}.hljs-attr,.hljs-number,.hljs-selector-attr,.hljs-selector-class,.hljs-selector-pseudo,.hljs-template-variable,.hljs-type,.hljs-variable{color:#986801}.hljs-bullet,.hljs-link,.hljs-meta,.hljs-selector-id,.hljs-symbol,.hljs-title{color:#4078f2}.hljs-built_in,.hljs-class .hljs-title,.hljs-title.class_{color:#c18401}.hljs-emphasis{font-style:italic}.hljs-strong{font-weight:700}.hljs-link{text-decoration:underline}

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,103 @@
hljs.registerLanguage("gleam", function (hljs) {
const KEYWORDS =
"as assert case const external fn if import let " +
"use 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,
],
};
});

View File

@ -0,0 +1,609 @@
"use strict";
window.Aiken = (function () {
/* Global Object */
const self = {};
/* Public Properties */
self.hashOffset = undefined;
/* Public Methods */
self.getProperty = function (property) {
let value;
try {
value = localStorage.getItem(`Aiken.${property}`);
} catch (_error) {}
if (-1 < [null, undefined].indexOf(value)) {
return aikenConfig[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 = aikenConfig[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] : aikenConfig[property].update;
const value = update();
try {
localStorage.setItem("Aiken." + property, value);
} catch (_error) {}
bodyClasses.remove(`${property}-${previousValue}`);
bodyClasses.add(`${property}-${value}`);
const isDefault = value === aikenConfig[property].values[0].value;
const toggleClasses = document.querySelector(
`#${property}-toggle`
).classList;
toggleClasses.remove(`toggle-${isDefault ? 1 : 0}`);
toggleClasses.add(`toggle-${isDefault ? 0 : 1}`);
try {
aikenConfig[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 addEvent = function (el, type, handler) {
if (el.attachEvent) el.attachEvent("on" + type, handler);
else el.addEventListener(type, handler);
};
const searchLoaded = function (index, docs) {
const preview_words_after = 10;
const preview_words_before = 5;
const previews = 3;
const searchInput = document.getElementById("search-input");
const searchNavButton = document.getElementById("search-nav-button");
const searchResults = document.getElementById("search-results");
let currentInput;
let currentSearchIndex = 0;
function showSearch() {
document.documentElement.classList.add("search-active");
}
searchNavButton.addEventListener("click", function (e) {
e.stopPropagation();
showSearch();
setTimeout(function () {
searchInput.focus();
}, 0);
});
function hideSearch() {
document.documentElement.classList.remove("search-active");
}
function update() {
currentSearchIndex++;
const input = searchInput.value;
showSearch();
if (input === currentInput) {
return;
}
currentInput = input;
searchResults.innerHTML = "";
if (input === "") {
return;
}
let results = index.query(function (query) {
const tokens = lunr.tokenizer(input);
query.term(tokens, {
boost: 10,
});
query.term(tokens, {
wildcard: lunr.Query.wildcard.TRAILING,
});
});
if (results.length == 0 && input.length > 2) {
const tokens = lunr.tokenizer(input).filter(function (token, i) {
return token.str.length < 20;
});
if (tokens.length > 0) {
results = index.query(function (query) {
query.term(tokens, {
editDistance: Math.round(Math.sqrt(input.length / 2 - 1)),
});
});
}
}
if (results.length == 0) {
const noResultsDiv = document.createElement("div");
noResultsDiv.classList.add("search-no-result");
noResultsDiv.innerText = "No results found";
searchResults.appendChild(noResultsDiv);
} else {
const resultsList = document.createElement("ul");
resultsList.classList.add("search-results-list");
searchResults.appendChild(resultsList);
addResults(resultsList, results, 0, 10, 100, currentSearchIndex);
}
function addResults(
resultsList,
results,
start,
batchSize,
batchMillis,
searchIndex
) {
if (searchIndex != currentSearchIndex) {
return;
}
for (let i = start; i < start + batchSize; i++) {
if (i == results.length) {
return;
}
addResult(resultsList, results[i]);
}
setTimeout(function () {
addResults(
resultsList,
results,
start + batchSize,
batchSize,
batchMillis,
searchIndex
);
}, batchMillis);
}
function addResult(resultsList, result) {
const doc = docs[result.ref];
const resultsListItem = document.createElement("li");
resultsListItem.classList.add("search-results-list-item");
resultsList.appendChild(resultsListItem);
const resultLink = document.createElement("a");
resultLink.classList.add("search-result");
resultLink.setAttribute("href", `${window.breadcrumbs}/${doc.url}`);
resultsListItem.appendChild(resultLink);
const resultTitle = document.createElement("div");
resultTitle.classList.add("search-result-title");
resultLink.appendChild(resultTitle);
const resultDoc = document.createElement("div");
resultDoc.classList.add("search-result-doc");
resultDoc.innerHTML =
'<svg viewBox="0 0 24 24" class="search-result-icon"><use xlink:href="#icon-svg-doc"></use></svg>';
resultTitle.appendChild(resultDoc);
const resultDocTitle = document.createElement("div");
resultDocTitle.classList.add("search-result-doc-title");
resultDocTitle.innerHTML = doc.doc;
resultDoc.appendChild(resultDocTitle);
let resultDocOrSection = resultDocTitle;
if (doc.doc != doc.title) {
resultDoc.classList.add("search-result-doc-parent");
const resultSection = document.createElement("div");
resultSection.classList.add("search-result-section");
resultSection.innerHTML = doc.title;
resultTitle.appendChild(resultSection);
resultDocOrSection = resultSection;
}
const metadata = result.matchData.metadata;
const titlePositions = [];
const contentPositions = [];
for (let j in metadata) {
const meta = metadata[j];
if (meta.title) {
const positions = meta.title.position;
for (let k in positions) {
titlePositions.push(positions[k]);
}
}
if (meta.content) {
const positions = meta.content.position;
for (let k in positions) {
const position = positions[k];
let previewStart = position[0];
let previewEnd = position[0] + position[1];
let ellipsesBefore = true;
let ellipsesAfter = true;
for (let k = 0; k < preview_words_before; k++) {
const nextSpace = doc.content.lastIndexOf(
" ",
previewStart - 2
);
const nextDot = doc.content.lastIndexOf(". ", previewStart - 2);
if (nextDot >= 0 && nextDot > nextSpace) {
previewStart = nextDot + 1;
ellipsesBefore = false;
break;
}
if (nextSpace < 0) {
previewStart = 0;
ellipsesBefore = false;
break;
}
previewStart = nextSpace + 1;
}
for (let k = 0; k < preview_words_after; k++) {
const nextSpace = doc.content.indexOf(" ", previewEnd + 1);
const nextDot = doc.content.indexOf(". ", previewEnd + 1);
if (nextDot >= 0 && nextDot < nextSpace) {
previewEnd = nextDot;
ellipsesAfter = false;
break;
}
if (nextSpace < 0) {
previewEnd = doc.content.length;
ellipsesAfter = false;
break;
}
previewEnd = nextSpace;
}
contentPositions.push({
highlight: position,
previewStart: previewStart,
previewEnd: previewEnd,
ellipsesBefore: ellipsesBefore,
ellipsesAfter: ellipsesAfter,
});
}
}
}
if (titlePositions.length > 0) {
titlePositions.sort(function (p1, p2) {
return p1[0] - p2[0];
});
resultDocOrSection.innerHTML = "";
addHighlightedText(
resultDocOrSection,
doc.title,
0,
doc.title.length,
titlePositions
);
}
if (contentPositions.length > 0) {
contentPositions.sort(function (p1, p2) {
return p1.highlight[0] - p2.highlight[0];
});
let contentPosition = contentPositions[0];
let previewPosition = {
highlight: [contentPosition.highlight],
previewStart: contentPosition.previewStart,
previewEnd: contentPosition.previewEnd,
ellipsesBefore: contentPosition.ellipsesBefore,
ellipsesAfter: contentPosition.ellipsesAfter,
};
const previewPositions = [previewPosition];
for (let j = 1; j < contentPositions.length; j++) {
contentPosition = contentPositions[j];
if (previewPosition.previewEnd < contentPosition.previewStart) {
previewPosition = {
highlight: [contentPosition.highlight],
previewStart: contentPosition.previewStart,
previewEnd: contentPosition.previewEnd,
ellipsesBefore: contentPosition.ellipsesBefore,
ellipsesAfter: contentPosition.ellipsesAfter,
};
previewPositions.push(previewPosition);
} else {
previewPosition.highlight.push(contentPosition.highlight);
previewPosition.previewEnd = contentPosition.previewEnd;
previewPosition.ellipsesAfter = contentPosition.ellipsesAfter;
}
}
const resultPreviews = document.createElement("div");
resultPreviews.classList.add("search-result-previews");
resultLink.appendChild(resultPreviews);
const content = doc.content;
for (
let j = 0;
j < Math.min(previewPositions.length, previews);
j++
) {
const position = previewPositions[j];
const resultPreview = document.createElement("div");
resultPreview.classList.add("search-result-preview");
resultPreviews.appendChild(resultPreview);
if (position.ellipsesBefore) {
resultPreview.appendChild(document.createTextNode("... "));
}
addHighlightedText(
resultPreview,
content,
position.previewStart,
position.previewEnd,
position.highlight
);
if (position.ellipsesAfter) {
resultPreview.appendChild(document.createTextNode(" ..."));
}
}
}
const resultRelUrl = document.createElement("span");
resultRelUrl.classList.add("search-result-rel-url");
resultRelUrl.innerText = doc.url;
resultTitle.appendChild(resultRelUrl);
}
function addHighlightedText(parent, text, start, end, positions) {
let index = start;
for (let i in positions) {
const position = positions[i];
const span = document.createElement("span");
span.innerHTML = text.substring(index, position[0]);
parent.appendChild(span);
index = position[0] + position[1];
const highlight = document.createElement("span");
highlight.classList.add("search-result-highlight");
highlight.innerHTML = text.substring(position[0], index);
parent.appendChild(highlight);
}
const span = document.createElement("span");
span.innerHTML = text.substring(index, end);
parent.appendChild(span);
}
}
addEvent(searchInput, "focus", function () {
setTimeout(update, 0);
});
addEvent(searchInput, "keyup", function (e) {
switch (e.keyCode) {
case 27: // When esc key is pressed, hide the results and clear the field
searchInput.value = "";
break;
case 38: // arrow up
case 40: // arrow down
case 13: // enter
e.preventDefault();
return;
}
update();
});
addEvent(searchInput, "keydown", function (e) {
let active;
switch (e.keyCode) {
case 38: // arrow up
e.preventDefault();
active = document.querySelector(".search-result.active");
if (active) {
active.classList.remove("active");
if (active.parentElement.previousSibling) {
const previous =
active.parentElement.previousSibling.querySelector(
".search-result"
);
previous.classList.add("active");
}
}
return;
case 40: // arrow down
e.preventDefault();
active = document.querySelector(".search-result.active");
if (active) {
if (active.parentElement.nextSibling) {
const next =
active.parentElement.nextSibling.querySelector(
".search-result"
);
active.classList.remove("active");
next.classList.add("active");
}
} else {
const next = document.querySelector(".search-result");
if (next) {
next.classList.add("active");
}
}
return;
case 13: // enter
e.preventDefault();
active = document.querySelector(".search-result.active");
if (active) {
active.click();
} else {
const first = document.querySelector(".search-result");
if (first) {
first.click();
}
}
return;
}
});
addEvent(document, "click", function (e) {
if (e.target != searchInput) {
hideSearch();
}
});
};
self.initSearch = function initSeach(docs) {
// enable support for hyphenated search words
lunr.tokenizer.separator = /[\s/]+/;
const index = lunr(function () {
this.ref("id");
this.field("title", { boost: 200 });
this.field("content", { boost: 2 });
this.field("url");
this.metadataWhitelist = ["position"];
for (let [i, entry] of docs.entries()) {
this.add({
id: i,
title: entry.title,
content: entry.content,
url: `${window.breadcrumbs}/${entry.url}`,
});
}
});
searchLoaded(index, docs);
};
const init = function () {
for (let property in aikenConfig) {
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;
})();

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,159 @@
{% extends "_layout.html" %}
{% block sidebar_content %}
{% if !types.is_empty() %}
<h2>Types</h2>
<ul>
{% for type_info in types %}
<li><a href="#{{ type_info.name }}">{{ type_info.name }}</a></li>
{% endfor %}
</ul>
{% endif %}
{% if !constants.is_empty() %}
<h2>Constants</h2>
<ul>
{% for constant in constants %}
<li><a href="#{{ constant.name }}">{{ constant.name }}</a></li>
{% endfor %}
</ul>
{% endif %}
{% if !functions.is_empty() %}
<h2>Functions</h2>
<ul>
{% for function in functions %}
<li><a href="#{{ function.name }}">{{ function.name }}</a></li>
{% endfor %}
</ul>
{% endif %}
{% endblock %}
{% block content %}
<h1 id="module-name" class="module-name">
<a href="#module-name">{{ module_name }}</a>
</h1>
{{ documentation|safe }}
{% if !types.is_empty() %}
<section class="module-members">
<h1 id="module-types" class="module-member-kind">
<a href="#module-types">Types</a>
</h1>
{% for type_info in types %}
<div class="member">
<div class="member-name">
<h2 id="{{ type_info.name }}">
<a href="#{{ type_info.name }}">
{{ type_info.name }}
</a>
</h2>
{% if !type_info.source_url.is_empty() %}
<a class="member-source" alt="View Source" title="View Source" href="{{ type_info.source_url|safe }}">
&lt;/&gt;
</a>
{% endif %}
</div>
<div class="custom-type-constructors">
<div class="rendered-markdown">{{ type_info.documentation|safe }}</div>
<pre><code class="hljs gleam">{{ type_info.definition }}</code></pre>
{% if !type_info.constructors.is_empty() %}
<h3>
Constructors
</h3>
<ul class="constructor-list">
{% for constructor in type_info.constructors %}
<li class="constructor-item">
<div class="constructor-row">
<svg class="icon icon-star"><use xlink:href="#icon-star"></use></svg>
<pre class="constructor-name"><code class="hljs gleam">{{ constructor.definition }}</code></pre>
</div>
<div class="constructor-item-docs">
{{ constructor.documentation|safe }}
{% if !constructor.arguments.is_empty() %}
<h4>
Arguments
</h4>
<ul class="constructor-argument-list">
{% for argument in constructor.arguments %}
<li>
<div class="constructor-argument-item">
<p class="constructor-argument-label">
<i>{{ argument.name }}</i>
</p>
<div class="constructor-argument-doc">
{{ argument.doc|safe }}
</div>
</div>
</li>
{% endfor %}
</ul>
{% endif %}
</div>
</li>
{% endfor %}
</ul>
{% endif %}
</div>
</div>
{% endfor %}
</section>
{% endif %}
{% if !constants.is_empty() %}
<section class="module-members">
<h1 id="module-constants" class="module-member-kind">
<a href="#module-constants">Constants</a>
</h1>
{% for constant in constants %}
<div class="member">
<div class="member-name">
<h2 id="{{ constant.name }}">
<a href="#{{ constant.name }}">
{{ constant.name }}
</a>
</h2>
{% if !constant.source_url.is_empty() %}
<a class="member-source" alt="View Source" title="View Source" href="{{ constant.source_url|safe }}">
&lt;/&gt;
</a>
{% endif %}
</div>
<pre><code class="hljs gleam">{{ constant.definition }}</code></pre>
<div class="rendered-markdown">{{ constant.documentation|safe }}</div>
</div>
{% endfor %}
</section>
{% endif %}
{% if !functions.is_empty() %}
<section class="module-members">
<h1 id="module-functions" class="module-member-kind">
<a href="#module-functions">Functions</a>
</h1>
{% for function in functions %}
<div class="member">
<div class="member-name">
<h2 id="{{ function.name }}">
<a href="#{{ function.name }}">
{{ function.name }}
</a>
</h2>
{% if !function.source_url.is_empty() %}
<a class="member-source" alt="View Source" title="View Source" href="{{ function.source_url|safe }}">
&lt;/&gt;
</a>
{% endif %}
</div>
<pre><code class="hljs gleam">{{ function.signature }}</code></pre>
<div class="rendered-markdown">{{ function.documentation|safe }}</div>
</div>
{% endfor %}
</section>
{% endif %}
{% endblock %}

View File

@ -0,0 +1,9 @@
{% extends "_layout.html" %}
{% block title %}
{{ title }} - {{ project_name }}
{% endblock %}
{% block content %}
{{ content|safe }}
{% endblock %}