Skip to content

Commit

Permalink
docs: Add the gallery
Browse files Browse the repository at this point in the history
  • Loading branch information
kmyk committed Aug 2, 2021
1 parent b83df44 commit 3784be7
Show file tree
Hide file tree
Showing 8 changed files with 258 additions and 24 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ jobs:
run: stack --system-ghc build --only-dependencies

- name: Run Haddock
run: stack --system-ghc haddock --haddock-arguments --odir=public
run: stack --system-ghc haddock --haddock-arguments --odir=docs/gh-pages/haddock

- name: Make Garalley
run: |
python3 scripts/make_garalley.py > docs/gh-pages/garalley/data.json
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public
publish_dir: ./docs/gh-pages
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
docs/gh-pages/gallery/data.json

.stack-work/

# Include .cabal file because FP Complete recommends to do so. See https://www.fpcomplete.com/blog/storing-generated-cabal-files/
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ For users:
- [docs/optimization.ja.md](https://github.com/kmyk/Jikka/blob/master/docs/language.md) (Japanese translation)
- A list of optimizations which Jikka does / Jikka が行なってくれる最適化の一覧
- [examples/](https://github.com/kmyk/Jikka/blob/master/examples)
- [gallery](https://kmyk.github.io/Jikka/gallery)
- [CHANGELOG.md](https://github.com/kmyk/Jikka/blob/master/CHANGELOG.md)

For developpers:
Expand All @@ -69,7 +70,7 @@ For developpers:
- [docs/internal.ja.md](https://github.com/kmyk/Jikka/blob/master/docs/internal.ja.md (Japanese)
- 具体的な処理の流れについて
- [Haddock](https://hackage.haskell.org/package/Jikka)
- [Haddock (master)](https://kmyk.github.io/Jikka/)
- [Haddock (master)](https://kmyk.github.io/Jikka/haddock)

## Examples

Expand Down
57 changes: 57 additions & 0 deletions docs/gh-pages/gallery/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />

<title>Jikka Gallery</title>
<meta name="description" content="" />
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1"
crossorigin="anonymous"
/>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css"
integrity="sha384-doAc3Z0i+SBp0Img0yrmvdUG7+DLbBYeol0n0hqTTKNgz9MINQa16YnwWGIcCzqz"
crossorigin="anonymous"
/>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW"
crossorigin="anonymous"
></script>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/styles/default.min.css"
integrity="sha384-bVi32MzPMHhQQoX43XwbzyE2I2YlQETXzSzS0rnURpcv/pkxtPnZ8QpbAN9AzEu5"
crossorigin="anonymous"
/>
<script
src="https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/highlight.min.js"
integrity="sha384-385VkHYTcYER9bopCYIl/TMrS6E92YLBFzSpK3C7aeWw4kyfHy6ZHJ5/AA1UwYbM"
crossorigin="anonymous"
></script>
<script
src="https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/languages/haskell.min.js"
integrity="sha384-hP6+W7Cbc2Vq7E5YIwkiT+03DZqfu7d0VS5UwnqZDCS/Z3GR0jytu0rtkjZl2koX"
crossorigin="anonymous"
></script>
<script src="index.js"></script>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">Jikka Gallery</a>
</div>
</nav>

<div class="container">
<h2 class="mt-3 mb-3">Jikka Gallery</h2>

<div id="gallery" class="container-md">loading...</div>
</div>
</body>
</html>
86 changes: 86 additions & 0 deletions docs/gh-pages/gallery/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
function loadData() {
const req = new XMLHttpRequest();
req.open("GET", "data.json", false);
req.send();
if (req.status != 200) {
throw Error(req.statusText);
}
return JSON.parse(req.responseText);
}

function appendHeader(div, level, text) {
const h = document.createElement("h" + level.toString());
h.textContent = text;
div.appendChild(h);
}

function appendPreCode(div, text, lang) {
const pre = document.createElement("pre");
const code = document.createElement("code");
code.classList.add("language-" + lang);
code.textContent = text;
pre.appendChild(code);
div.appendChild(pre);
return pre;
}

function appendCommon(gallery, example) {
appendHeader(gallery, 3, example["path"]);

// Use two panes
const div = document.createElement("div");
div.classList.add("row");
const left = document.createElement("div");
const right = document.createElement("div");
left.classList.add("col-lg-6");
right.classList.add("col-lg-6");
div.appendChild(left);
div.appendChild(right);
gallery.appendChild(div);

appendHeader(left, 4, "Input");
appendHeader(right, 4, "Output");

appendHeader(left, 5, "Python");
appendPreCode(left, example["python"], "python");
return right;
}

function appendExample(gallery, example) {
const right = appendCommon(gallery, example);
// appendPreCode(right, example["rpython"], "python");
appendHeader(right, 5, "core");
appendPreCode(right, example["core"], "haskell");
appendHeader(right, 5, "C++");
appendPreCode(right, example["cxx"], "cxx");
}

function appendError(gallery, example) {
const right = appendCommon(gallery, example);
appendPreCode(right, example["error"], "plain");
}

window.addEventListener("DOMContentLoaded", function () {
const gallery = document.getElementById("gallery");
let data;
try {
data = loadData();
} catch (error) {
console.error(error);
gallery.textContent = "error: " + error;
return;
}

while (gallery.lastChild) {
gallery.removeChild(gallery.lastChild);
}
for (const example of data["examples"]) {
appendExample(gallery, example);
}
for (const example of data["errors"]) {
appendError(gallery, example);
}
document.querySelectorAll("pre code").forEach((el) => {
hljs.highlightElement(el);
});
});
Loading

0 comments on commit 3784be7

Please sign in to comment.