Mercurial Hosting > luan
diff website/src/tutorial.html.luan @ 1812:f44dcb3fedf7
docs - add code block
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 10 Jun 2024 14:41:48 -0600 |
parents | 4b56eff90040 |
children | 50e570b598b2 |
line wrap: on
line diff
--- a/website/src/tutorial.html.luan Wed May 15 18:02:28 2024 -0600 +++ b/website/src/tutorial.html.luan Mon Jun 10 14:41:48 2024 -0600 @@ -25,31 +25,31 @@ <p>Create a file <b>hello.luan</b> containing:</p> -<pre> - %> - Hello World - <% -</pre> +<code block> +%> +Hello World +<% +</code> <p>To run this, type <b>luan hello.luan</b> on the command line. This should print <b>Hello World</b>.</p> <p>The syntax here is based on <a href="http://en.wikipedia.org/wiki/JavaServer_Pages">JSP</a>. Let's change it a little:</p> -<pre> - local name = "Bob" - %> - Hello <%= name %> - <% -</pre> +<code block> +local name = "Bob" +%> +Hello <%= name %> +<% +</code> <p>This should print <b>Hello Bob</b>. Now let's try a more conventional approach:</p> -<pre> - local Io = require "luan:Io.luan" - local print = Io.print +<code block> +local Io = require "luan:Io.luan" +local print = Io.print - print("Hello World") -</pre> +print("Hello World") +</code> <p>In Luan, a function call with one string argument doesn't require parenthesis, so <b>print("Hello World")</b> is the same as <b>print "Hello World"</b> and <b>require "luan:Io.luan"</b> is the same as <b>require("luan:Io.luan")</b>. Both <b>require</b> and <b>print</b> are functions.</p> @@ -59,37 +59,37 @@ <p>Let's a make fancier version:</p> -<pre> - local Io = require "luan:Io.luan" - local print = Io.print +<code block> +local Io = require "luan:Io.luan" +local print = Io.print - local function hello(name) - print("Hello "..name) - end +local function hello(name) + print("Hello "..name) +end - hello("Bob") -</pre> +hello("Bob") +</code> <p>The <b>..</b> operator does concatenation. This will print <b>Hello Bob</b>.</p> <p>Now let's make a web page. First we need a directory for our website. So create a directory <b>src</b>. In this directory, create a file <b>hi.html.luan</b> containing: -<pre> - local Io = require "luan:Io.luan" - local Http = require "luan:http/Http.luan" - - return function() - Io.stdout = Http.response.text_writer() - %> - <!doctype html> - <html> - <body> - Hello World - </body> - </html> - <% - end -</pre> +<code block> +local Io = require "luan:Io.luan" +local Http = require "luan:http/Http.luan" + +return function() + Io.stdout = Http.response.text_writer() +%> +<!doctype html> +<html> + <body> + Hello World + </body> +</html> +<% +end +</code> <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> @@ -99,9 +99,9 @@ <p>So now you have built your website and you want to publish it to the web. If you have your own domain, create a CNAME record for it pointing to <b>s1.luan.software</b>. If you don't have a domain, just use a domain like <b>bob.s1.luan.software</b> (anything of the form <b>*.s1.luan.software</b>). Assuming your directory is <b>src</b> and you will use the password <b>secret</b>, do the following from the command line: -<pre> - luan luan:host/push.luan bob.s1.luan.software secret src -</pre> +<code block> +luan luan:host/push.luan bob.s1.luan.software secret src +</code> <p>The form is <b>luan luan:host/push.luan domain password directory</b>. If you change your site, just run this again and your site will be updated. To delete your site, do <b>luan luan:host/delete.luan domain password</b>.</p>