annotate website/src/lib/Shared.luan @ 1774:764723436f05

better json_parse exception
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 27 Jul 2023 17:24:49 -0600
parents 7d2297155ee3
children fdc59d390615
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1651
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local ipairs = Luan.ipairs or error()
1653
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
4 local pairs = Luan.pairs or error()
1651
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local Shared = {}
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 function Shared.head()
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 %>
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 <meta name="viewport" content="width=device-width, initial-scale=1">
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 <style>
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 @import "/site.css";
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 </style>
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 <%
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 end
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17
1652
d5779a264a4a docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1651
diff changeset
18 local function header(crumbs)
1651
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 %>
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 <div header>
1747
Franklin Schmidt <fschmidt@gmail.com>
parents: 1653
diff changeset
21 <span breadcrumbs>
Franklin Schmidt <fschmidt@gmail.com>
parents: 1653
diff changeset
22 <a href="/">Luan</a>
1651
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 <% for _, crumb in ipairs(crumbs or {}) do %>
1747
Franklin Schmidt <fschmidt@gmail.com>
parents: 1653
diff changeset
24 / <%=crumb%>
1651
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 <% end %>
1747
Franklin Schmidt <fschmidt@gmail.com>
parents: 1653
diff changeset
26 </span>
1762
Franklin Schmidt <fschmidt@gmail.com>
parents: 1747
diff changeset
27 <span><a href="http://www.reactionary.software/">reactionary software</a> by <a href="https://www.linkmystyle.com/fschmidt">fschmidt</a></span>
1651
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 </div>
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 <%
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 end
1652
d5779a264a4a docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1651
diff changeset
31 Shared.header = header
d5779a264a4a docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1651
diff changeset
32
d5779a264a4a docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1651
diff changeset
33 function Shared.docs_header()
d5779a264a4a docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1651
diff changeset
34 header{[[<a href="/docs.html">Documentation</a>]]}
d5779a264a4a docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1651
diff changeset
35 end
1651
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36
1653
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
37 local function show_toc(content)
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
38 %>
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
39 <ul>
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
40 <%
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
41 for id, info in pairs(content) do
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
42 %>
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
43 <li><a id="c_<%=id%>" href="#<%=id%>"><%=info.title%></a>
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
44 <%
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
45 local subs = info.subs
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
46 if subs ~= nil then
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
47 show_toc(subs)
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
48 end
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
49 %>
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
50 </li>
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
51 <%
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
52 end
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
53 %>
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
54 </ul>
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
55 <%
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
56 end
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
57 Shared.show_toc = show_toc
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
58
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
59 local function nothing() end
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
60
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
61 local function show_content(content,h)
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
62 for id, info in pairs(content) do
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
63 %>
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
64 <div heading>
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
65 <h<%=h%>><a id="<%=id%>" href="#<%=id%>"><%=info.title%></a></h<%=h%>>
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
66 <a href="#c_<%=id%>">contents</a>
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
67 </div>
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
68 <%
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
69 (info.content or nothing)()
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
70 local subs = info.subs
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
71 if subs ~= nil then
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
72 show_content(subs,h+1)
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
73 end
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
74 end
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
75 end
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
76 Shared.show_content = show_content
418b610e887b docs work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1652
diff changeset
77
1651
5b8f056527a3 docs work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
78 return Shared