Mercurial Hosting > luan
comparison website/src/tutorial.html.luan @ 1652:d5779a264a4a
docs work
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Thu, 31 Mar 2022 19:04:59 -0600 |
| parents | 5b8f056527a3 |
| children | 500c706ed4ea |
comparison
equal
deleted
inserted
replaced
| 1651:5b8f056527a3 | 1652:d5779a264a4a |
|---|---|
| 2 local error = Luan.error | 2 local error = Luan.error |
| 3 local Io = require "luan:Io.luan" | 3 local Io = require "luan:Io.luan" |
| 4 local Http = require "luan:http/Http.luan" | 4 local Http = require "luan:http/Http.luan" |
| 5 local Shared = require "site:/lib/Shared.luan" | 5 local Shared = require "site:/lib/Shared.luan" |
| 6 local head = Shared.head or error() | 6 local head = Shared.head or error() |
| 7 local header = Shared.header or error() | 7 local docs_header = Shared.docs_header or error() |
| 8 | 8 |
| 9 | 9 |
| 10 return function() | 10 return function() |
| 11 Io.stdout = Http.response.text_writer() | 11 Io.stdout = Http.response.text_writer() |
| 12 %> | 12 %> |
| 15 <head> | 15 <head> |
| 16 <% head() %> | 16 <% head() %> |
| 17 <title>Luan Tutorial</title> | 17 <title>Luan Tutorial</title> |
| 18 </head> | 18 </head> |
| 19 <body> | 19 <body> |
| 20 <% header{[[<a href="docs.html">Documentation</a>]]} %> | 20 <% docs_header() %> |
| 21 <div content> | 21 <div content> |
| 22 | 22 |
| 23 <h1>Luan Tutorial</h1> | 23 <h1>Luan Tutorial</h1> |
| 24 | 24 |
| 25 | 25 |
| 89 </html> | 89 </html> |
| 90 <% | 90 <% |
| 91 end | 91 end |
| 92 </pre> | 92 </pre> |
| 93 | 93 |
| 94 <p>Now go back to the parent directory and do <b>luan luan:http/serve.luan src</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.html.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.html">http://localhost:8080/hi.html</a> then you will run the program which will generate the web page.</p> | 94 <p>Now go back to the parent directory and do <b>luan luan:http/serve.luan src</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.html.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.html">http://localhost:8080/hi.html</a> then you will run the program which will generate the web page. In fact the page that you are currently looking at <b>tutorial.html</b> is generated from <a href="tutorial.html.luan">tutorial.html.luan</a>.</p> |
| 95 | 95 |
| 96 <p>The Luan webserver expects the file to return a function and calls it to generate the page. Code of the form <b>%>...<%</b> writes its output to <b>Io.stdout</b> which by default is the standard output of the command line. So in the returned function one usually starts by setting <b>Io.stdout</b> to a <code>text_writer</code> which writes its output to the HTTP response (to the web browser).</p> | 96 <p>The Luan webserver expects the file to return a function and calls it to generate the page. Code of the form <b>%>...<%</b> writes its output to <b>Io.stdout</b> which by default is the standard output of the command line. So in the returned function one usually starts by setting <b>Io.stdout</b> to a <code>text_writer</code> which writes its output to the HTTP response (to the web browser).</p> |
| 97 | 97 |
| 98 <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.</p> | 98 <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.</p> |
| 99 | 99 |
