15
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
|
3 local Parsers = require "luan:Parsers.luan"
|
|
4 local json_string = Parsers.json_string or error()
|
|
5 local Io = require "luan:Io.luan"
|
|
6 local output_of = Io.output_of or error()
|
|
7 local Http = require "luan:http/Http.luan"
|
|
8 local Post = require "site:/lib/Post.luan"
|
|
9 local Bbcode = require "site:/lib/Bbcode.luan"
|
|
10 local bbcode_preprocess = Bbcode.preprocess or error()
|
|
11 local bbcode_to_html = Bbcode.to_html or error()
|
|
12 local Db = require "site:/lib/Db.luan"
|
|
13
|
|
14
|
|
15 return function()
|
|
16 local post = Http.request.parameters.post or error()
|
|
17 local text = Http.request.parameters.text or error()
|
|
18 text = bbcode_preprocess(text)
|
|
19 Db.run_in_transaction( function()
|
|
20 post = Post.get_by_id(post) or error()
|
16
|
21 post.author_is_current() or error()
|
15
|
22 post.content = text
|
|
23 post.save()
|
|
24 end )
|
|
25 local html = output_of(function() bbcode_to_html(post.content) end)
|
|
26 Io.stdout = Http.response.text_writer()
|
|
27 %>
|
|
28 let postDiv = document.querySelector('[post="<%=post.id%>"]');
|
19
|
29 cancelEdit(postDiv);
|
15
|
30 postDiv.querySelector('[message]').innerHTML = <%= json_string(html) %>;
|
|
31 <%
|
|
32 end
|