comparison blog/src/edit.luan @ 596:6bb0c83116e9

add blog sample app
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 15 Sep 2015 21:30:33 -0600
parents
children ca169567ce07
comparison
equal deleted inserted replaced
595:8370c4009cce 596:6bb0c83116e9
1 local Luan = require "luan:Luan"
2 local error = Luan.error
3 local String = require "luan:String"
4 local to_number = String.to_number or error()
5 local Io = require "luan:Io"
6 local Http = require "luan:http/Http"
7 local Post = require "site:/lib/Post"
8
9
10 return function()
11 local post_id = to_number(Http.request.parameter.post) or error()
12 local post = Post.get_by_id(post_id) or error()
13 if Http.request.parameter.save ~= nil then
14 post.subject = Http.request.parameter.subject
15 post.content = Http.request.parameter.content
16 post.save()
17 Http.response.send_redirect("/#p"..post.id)
18 return
19 end
20
21 Io.stdout = Http.response.text_writer()
22 %>
23 <html>
24 <head>
25 <style>
26 @import "/site.css";
27 </style>
28 </head>
29 <body>
30 <h1>Make New Post</h1>
31
32 <form method=post>
33 <p>Subject: <input name=subject size=50 type=text value="<%= post.subject %>"></p>
34 <p><textarea name=content rows=20 cols=90><%= post.content %></textarea></p>
35 <p>
36 <input type=submit name=save value=Submit>
37 </p>
38 </form>
39
40 </body>
41 </html>
42 <%
43 end