• R/O
  • SSH
  • HTTPS

luatinycgi: Commit


Commit MetaInfo

Revision6 (tree)
Time2010-06-12 17:45:04
Authorsmeghead

Log Message

サンプルの足し算の機能とvalidationの機能呼び出しを実装した。

Change Summary

Incremental Difference

--- trunk/samples/webapp/lua/action/calc.lua (revision 5)
+++ trunk/samples/webapp/lua/action/calc.lua (revision 6)
@@ -1,12 +1,39 @@
11 module(..., package.seeall)
22 require "service.calc"
33
4-function index(request, response, path_infos, env)
5- env.message = request.QUERY.message
4+function index(request, response)
5+ return {forward = "./lp/calc/index.lp"}
6+end
7+
8+function plus(request, response)
9+ return {forward = "./lp/calc/plus.lp"}
10+end
11+function plus_submit(request, response)
12+ local env = {
13+ a = request.QUERY.a or 0,
14+ b = request.QUERY.b or 0
15+ }
16+ require "validate"
17+ env.errors = validate.validate {
18+ ['A'] = {
19+ [validate.required] = env.a,
20+ [validate.num] = env.a,
21+ },
22+ ['B'] = {
23+ [validate.required] = env.b,
24+ [validate.num] = env.b,
25+ },
26+ }
27+ if #env.errors > 0 then
28+ return {
29+ forward = "./lp/calc/plus.lp",
30+ env = env
31+ }
32+ end
33+ env.answer = env.a + env.b
634 return {
7- forward = "./lp/calc/index.lp",
35+ forward = "./lp/calc/plus.lp",
836 env = env
937 }
1038 end
11-
1239 -- vim: set ts=4 sw=4 sts=4 expandtab :
--- trunk/samples/webapp/site-lua/cgi.lua (revision 5)
+++ trunk/samples/webapp/site-lua/cgi.lua (revision 6)
@@ -193,7 +193,12 @@
193193 stdout:write(...)
194194 end
195195 function Response:forward(result)
196- local filename, env = result.forward, result.env
196+ local filename, env = result.forward, _G
197+ if result.env then
198+ for k, v in pairs(result.env) do
199+ env[k] = v
200+ end
201+ end
197202 local dir = string.match(self.script_filename, '^(.*)/[^/]+$')
198203 self:put("Content-Type: text/html;charset=UTF-8;\n\n")
199204 cgi.log:debug('forward')
@@ -229,7 +234,6 @@
229234
230235 local subapp_name = table.remove(request.path_infos, 1)
231236 local action_name = table.remove(request.path_infos, 1)
232- local path_infos = request.path_infos
233237
234238 -- if subapp_name ~= 'auth' and not request.session.data.loginuser then
235239 -- cgi.log:debug('timeout? data: ', request.session.data)
@@ -245,7 +249,7 @@
245249 local result = {}
246250 env.errors = {}
247251 if action then
248- result = action(request, response, path_infos, env)
252+ result = action(request, response)
249253 else
250254 cgi.log:info('no action. ', request.url)
251255 response:file_not_found(request.url)
--- trunk/samples/webapp/css/style.css (revision 5)
+++ trunk/samples/webapp/css/style.css (revision 6)
@@ -353,5 +353,12 @@
353353 color: #FF9900;
354354 border-width: 3px;
355355 }
356+input.number {
357+ width: 40px;
358+}
359+.error {
360+ color: red;
361+ font-weight: bold;
362+}
356363
357364 /* vim: set ts=2 sw=2 sts=2 expandtab : */
Show on old repository browser