comparison website/src/examples/hi2_simply_html.luan @ 503:92c3d22745b8

make _ENV optional
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 20 May 2015 23:24:46 -0600
parents 55f9f74f1e55
children 7bc63886d4f2
comparison
equal deleted inserted replaced
502:d3183a330ff5 503:92c3d22745b8
1 local Io = require "luan:Io" 1 local Io = require "luan:Io"
2 local Html = require "luan:Html" 2 local Html = require "luan:Html"
3 local Http = require "luan:http/Http" 3 local Http = require "luan:http/Http"
4 4
5 local M = {}
5 6
6 local function form() %> 7 local function form() %>
7 <form> 8 <form>
8 <label>What is your name?</label> 9 <label>What is your name?</label>
9 <input name="name" margin-bottom="1em"> 10 <input name="name" margin-bottom="1em">
10 <input type=submit> 11 <input type=submit>
11 </form> 12 </form>
12 <% end 13 <% end
13 14
14 15
15 local function hello() %> 16 local function hello(name) %>
16 <p>Hi <%= name %>!</p> 17 <p>Hi <%= name %>!</p>
17 <% end 18 <% end
18 19
19 20
20 function respond() 21 function M.respond()
21 Io.stdout = Http.response.text_writer() 22 Io.stdout = Http.response.text_writer()
22 name = Http.request.parameter.name 23 local name = Http.request.parameter.name
23 %> 24 %>
24 <html> 25 <html>
25 <head> 26 <head>
26 <% Html.simply_html_head() %> 27 <% Html.simply_html_head() %>
27 </head> 28 </head>
30 <h1 margin-bottom="1em">Hello</h1> 31 <h1 margin-bottom="1em">Hello</h1>
31 <% 32 <%
32 if name == nil then 33 if name == nil then
33 form() 34 form()
34 else 35 else
35 hello() 36 hello(name)
36 end 37 end
37 %> 38 %>
38 <p margin-top="2em"><small>This page was made with <a href="http://www.simplyhtml.org/">SimplyHTML</a>.</small></p> 39 <p margin-top="2em"><small>This page was made with <a href="http://www.simplyhtml.org/">SimplyHTML</a>.</small></p>
39 </div> 40 </div>
40 <% Html.simply_html_body_bottom() %> 41 <% Html.simply_html_body_bottom() %>
41 </body> 42 </body>
42 </html> 43 </html>
43 <% 44 <%
44 end 45 end
46
47 return M