comparison website/src/tutorial.html.luan @ 494:2b9bc97f0439

change luan:web to luan:http
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 15 May 2015 17:43:13 -0600
parents 322c03d85ada
children 598123096772
comparison
equal deleted inserted replaced
493:1d082a0812e0 494:2b9bc97f0439
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:web/Http" 3 local Http = require "luan:http/Http"
4 local Shared = require "site:/Shared" 4 local Shared = require "site:/Shared"
5 5
6 6
7 function service() 7 function service()
8 Io.stdout = Http.response.text_writer() 8 Io.stdout = Http.response.text_writer()
70 70
71 <p>Now let's make a web page. First we need a directory for our website. So create a directory <b>site</b>. In this directory, create a file <b>hi.luan</b> containing: 71 <p>Now let's make a web page. First we need a directory for our website. So create a directory <b>site</b>. In this directory, create a file <b>hi.luan</b> containing:
72 72
73 <p><tt><pre><%=Html.encode[[ 73 <p><tt><pre><%=Html.encode[[
74 local Io = require "luan:Io" 74 local Io = require "luan:Io"
75 local Http = require "luan:web/Http" 75 local Http = require "luan:http/Http"
76 76
77 function service() 77 function service()
78 Io.stdout = Http.response.text_writer() 78 Io.stdout = Http.response.text_writer()
79 %> 79 %>
80 <html> 80 <html>
84 </html> 84 </html>
85 <% 85 <%
86 end 86 end
87 ]]%></pre></tt></p> 87 ]]%></pre></tt></p>
88 88
89 <p>Now go back to the parent directory and do <b>luan luan:web/serve file:site</b>. This will run the Luan web server on port 8080. Try going to <a href="http://localhost:8080/">http://localhost:8080/</a>. You should see the directory. If you click on <b>hi.luan</b> you will see the source. But if you remove the <b>.luan</b> and just go to <a href="http://localhost:8080/hi">http://localhost:8080/hi</a> then you will run the program which will generate the web page.</p> 89 <p>Now go back to the parent directory and do <b>luan luan:http/serve file:site</b>. This will run the Luan web server on port 8080. Try going to <a href="http://localhost:8080/">http://localhost:8080/</a>. You should see the directory. If you click on <b>hi.luan</b> you will see the source. But if you remove the <b>.luan</b> and just go to <a href="http://localhost:8080/hi">http://localhost:8080/hi</a> then you will run the program which will generate the web page.</p>
90 90
91 <p>The Luan webserver looks for function named <b>service</b> in the file and calls it to generate the page. Code of the form <b><%=Html.encode[[%>...<%]]%></b> writes its output to <b>Io.stdout</b> which by default is the standard output of the command line. So in <b>service</b> one usually starts by setting <b>Io.stdout</b> to a <tt>text_writer</tt> which writes its output to the HTTP response (to the web browser).</p> 91 <p>The Luan webserver looks for function named <b>service</b> in the file and calls it to generate the page. Code of the form <b><%=Html.encode[[%>...<%]]%></b> writes its output to <b>Io.stdout</b> which by default is the standard output of the command line. So in <b>service</b> one usually starts by setting <b>Io.stdout</b> to a <tt>text_writer</tt> which writes its output to the HTTP response (to the web browser).</p>
92 92
93 <p>You can find this example and others in the <a href="examples">examples directory</a>. Take a look at <a href="examples/hi2.luan">hi2.luan</a> next. Remember to remove the <b>.luan</b> from the URL to run the code. And by the way, you can see the source for this page at <a href="tutorial.html.luan">tutorial.html.luan</a>.</p> 93 <p>You can find this example and others in the <a href="examples">examples directory</a>. Take a look at <a href="examples/hi2.luan">hi2.luan</a> next. Remember to remove the <b>.luan</b> from the URL to run the code. And by the way, you can see the source for this page at <a href="tutorial.html.luan">tutorial.html.luan</a>.</p>
94 94