annotate examples/blog/src/edit.luan @ 813:f8f7cb485c25

remove UserIdentity
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 08 Sep 2016 22:01:33 -0600
parents c38f6619feb9
children 21d157b153fe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
693
ca169567ce07 module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents: 596
diff changeset
1 local Luan = require "luan:Luan.luan"
596
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
693
ca169567ce07 module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents: 596
diff changeset
3 local String = require "luan:String.luan"
596
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local to_number = String.to_number or error()
693
ca169567ce07 module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents: 596
diff changeset
5 local Io = require "luan:Io.luan"
ca169567ce07 module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents: 596
diff changeset
6 local Http = require "luan:http/Http.luan"
ca169567ce07 module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents: 596
diff changeset
7 local Post = require "site:/lib/Post.luan"
596
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 return function()
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 local post_id = to_number(Http.request.parameter.post) or error()
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 local post = Post.get_by_id(post_id) or error()
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 if Http.request.parameter.save ~= nil then
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 post.subject = Http.request.parameter.subject
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 post.content = Http.request.parameter.content
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 post.save()
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 Http.response.send_redirect("/#p"..post.id)
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 return
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 end
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 Io.stdout = Http.response.text_writer()
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 %>
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 <html>
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 <head>
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 <style>
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 @import "/site.css";
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 </style>
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 </head>
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 <body>
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 <h1>Make New Post</h1>
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 <form method=post>
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 <p>Subject: <input name=subject size=50 type=text value="<%= post.subject %>"></p>
777
1460d297e960 add bbcode to blog example
Franklin Schmidt <fschmidt@gmail.com>
parents: 693
diff changeset
34 <p><textarea name=content rows=20 cols=90><%= post.content %></textarea><br>bbcode works</p>
596
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 <p>
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 <input type=submit name=save value=Submit>
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 </p>
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 </form>
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 </body>
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 </html>
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 <%
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 end