annotate src/thread.html.luan @ 11:3ed1e3f3a53a

use bbcode_to_html
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 30 Jun 2022 20:05:11 -0600
parents 9674275019bb
children ad1604c72156
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local ipairs = Luan.ipairs or error()
11
3ed1e3f3a53a use bbcode_to_html
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
4 local Html = require "luan:Html.luan"
3ed1e3f3a53a use bbcode_to_html
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
5 local html_encode = Html.encode or error()
3ed1e3f3a53a use bbcode_to_html
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
6 local Parsers = require "luan:Parsers.luan"
3ed1e3f3a53a use bbcode_to_html
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
7 local bbcode_to_html = Parsers.bbcode_to_html or error()
9
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local Io = require "luan:Io.luan"
11
3ed1e3f3a53a use bbcode_to_html
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
9 local output_of = Io.output_of or error()
9
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 local Http = require "luan:http/Http.luan"
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 local Shared = require "site:/lib/Shared.luan"
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 local head = Shared.head or error()
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 local header = Shared.header or error()
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 local footer = Shared.footer or error()
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 local Forum = require "site:/lib/Forum.luan"
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 local forum_title = Forum.title or error()
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 local Db = require "site:/lib/Db.luan"
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 local Post = require "site:/lib/Post.luan"
11
3ed1e3f3a53a use bbcode_to_html
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
19 local User = require "site:/lib/User.luan"
9
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21
11
3ed1e3f3a53a use bbcode_to_html
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
22 local function quoter(content,user_name)
3ed1e3f3a53a use bbcode_to_html
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
23 return output_of( function()
3ed1e3f3a53a use bbcode_to_html
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
24 %><blockquote><%
3ed1e3f3a53a use bbcode_to_html
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
25 if user_name ~= nil then
3ed1e3f3a53a use bbcode_to_html
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
26 local user = User.get_by_name(user_name)
3ed1e3f3a53a use bbcode_to_html
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
27 if user == nil then
3ed1e3f3a53a use bbcode_to_html
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
28 %><%= html_encode(user_name) %> wrote:<%
3ed1e3f3a53a use bbcode_to_html
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
29 else
3ed1e3f3a53a use bbcode_to_html
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
30 %><a href="/user_somthing"><%= html_encode(user_name) %></a> wrote:<%
3ed1e3f3a53a use bbcode_to_html
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
31 end
3ed1e3f3a53a use bbcode_to_html
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
32 end
3ed1e3f3a53a use bbcode_to_html
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
33 %><%= content %><%
3ed1e3f3a53a use bbcode_to_html
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
34 %></blockquote><%
3ed1e3f3a53a use bbcode_to_html
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
35 end_function )
3ed1e3f3a53a use bbcode_to_html
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
36 end
3ed1e3f3a53a use bbcode_to_html
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
37
9
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 return function()
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 local root_id = Http.request.parameters.root or error()
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 local docs, total_hits = Db.search("post_root_id:"..root_id,1,1000,{sort="id"})
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 local posts = Post.from_docs(docs)
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 local subject_html = posts[1].subject_html
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 Io.stdout = Http.response.text_writer()
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 %>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 <!doctype html>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 <html>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 <head>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 <% head() %>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49 <title><%=forum_title%>: <%=subject_html%></title>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50 <style>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
51 [post] {
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52 white-space: pre-wrap;
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53 }
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54 </style>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55 </head>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
56 <body>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
57 <% header() %>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
58 <div content>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
59 <h1><%=subject_html%></h1>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
60 <% for _, post in ipairs(posts) do %>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
61 <hr>
11
3ed1e3f3a53a use bbcode_to_html
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
62 <div post><%=bbcode_to_html(post.content,quoter)%></div>
9
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
63 <p>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
64 <a href="/reply.html?parent=<%=post.id%>">reply</a>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
65 - <a href="/edit.html?post=<%=post.id%>">edit</a>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
66 </p>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
67 <% end %>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
68 </div>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
69 <% footer() %>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
70 </body>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
71 </html>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
72 <%
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
73 end