annotate src/lib/Shared.luan @ 11:3ed1e3f3a53a

use bbcode_to_html
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 30 Jun 2022 20:05:11 -0600
parents 0472897e790d
children 24668255cede
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
3
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
3 local Http = require "luan:http/Http.luan"
6
9166f6a14021 add email api
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
4 local Io = require "luan:Io.luan"
9166f6a14021 add email api
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
5 local uri = Io.uri or error()
9166f6a14021 add email api
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
6 local Parsers = require "luan:Parsers.luan"
9166f6a14021 add email api
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
7 local json_parse = Parsers.json_parse or error()
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local Forum = require "site:/lib/Forum.luan"
6
9166f6a14021 add email api
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
9 local forum_title = Forum.title or error()
9166f6a14021 add email api
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
10 local mailer_url = Forum.mailer_url or error()
3
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
11 local User = require "site:/lib/User.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
12 local Logging = require "luan:logging/Logging.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
13 local logger = Logging.logger "Shared"
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 local Shared = {}
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 function Shared.head()
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 %>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 <meta name="viewport" content="width=device-width, initial-scale=1">
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 <style>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 @import "/site.css";
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 </style>
7
0472897e790d add javascript
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
24 <script src="/site.js"></script>
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 <%
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 end
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 function Shared.header()
3
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
29 local user = User.current()
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 %>
7
0472897e790d add javascript
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
31 <p style="text-align:center">Yes the aesthetics suck. Will be fixed later.</p>
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 <div header>
6
9166f6a14021 add email api
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
33 <a href="/"><%=forum_title%></a>
3
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
34 <% if user == nil then %>
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
35 <a href="/login.html">login</a>
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
36 <% else %>
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
37 <a href="/account.html"><%=user.name_html%></a>
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
38 <% end %>
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 </div>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 <%
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 end
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 function Shared.footer()
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 %>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 <div footer>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 <a href="/config.html">Configuration</a>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 </div>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 <%
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49 end
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50
4
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
51 function Shared.admin_header()
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
52 %>
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
53 <div header>
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
54 <a href="/private/admin.html">Admin</a>
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
55 </div>
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
56 <%
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
57 end
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
58
3
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
59 function Shared.base_url()
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
60 return Http.request.scheme.."://"..Http.request.headers["host"]
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
61 end
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
62
6
9166f6a14021 add email api
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
63 function Shared.call_mail_api(cmd,parameters)
9166f6a14021 add email api
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
64 local url = mailer_url.."/api/"..cmd..".json"
9166f6a14021 add email api
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
65 local options = {
9166f6a14021 add email api
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
66 parameters = parameters
9166f6a14021 add email api
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
67 }
9166f6a14021 add email api
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
68 local response = uri(url,options).read_text()
9166f6a14021 add email api
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
69 return json_parse(response)
9166f6a14021 add email api
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
70 end
9166f6a14021 add email api
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
71
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
72 return Shared