Mercurial Hosting > luan
diff website/src/tutorial.html.luan @ 562:7cc9d4a53d3b
remove SimplyHTML from documentation
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 24 Jun 2015 14:20:00 -0600 |
parents | d96944467ffc |
children | 33f1b4ad2c9d |
line wrap: on
line diff
--- a/website/src/tutorial.html.luan Tue Jun 23 16:45:16 2015 -0600 +++ b/website/src/tutorial.html.luan Wed Jun 24 14:20:00 2015 -0600 @@ -9,43 +9,45 @@ %> <html> <head> - <% Html.simply_html_head() %> <title>Luan Tutorial</title> + <style> + @import "/site.css"; + </style> </head> <body> <div container> <% Shared.header() %> -<h1 margin-bottom="1em">Luan Tutorial</h1> +<h1>Luan Tutorial</h1> <p>Create a file <b>hello.luan</b> containing:</p> -<p><tt><pre><%=Html.encode[[ +<pre><%=Html.encode[[ %> Hello World <% -]]%></pre></tt></p> +]]%></pre> <p>To run this, type <b>luan file:hello</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> -<p><tt><pre><%=Html.encode[[ +<pre><%=Html.encode[[ name = "Bob" %> Hello <%= name %> <% -]]%></pre></tt></p> +]]%></pre> <p>This should print <b>Hello Bob</b>. Now let's try a more conventional approach:</p> -<p><tt><pre> +<pre> local Io = require "luan:Io" local print = Io.print print("Hello World") -</pre></tt></p> +</pre> <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"</b> is the same as <b>require("luan:Io")</b>. Both <b>require</b> and <b>print</b> are functions.</p> @@ -55,7 +57,7 @@ <p>Let's a make fancier version:</p> -<p><tt><pre> +<pre> local Io = require "luan:Io" local print = Io.print @@ -64,13 +66,13 @@ end hello("Bob") -</pre></tt></p> +</pre> <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>site</b>. In this directory, create a file <b>hi.luan</b> containing: -<p><tt><pre><%=Html.encode[[ +<pre><%=Html.encode[[ local Io = require "luan:Io" local Http = require "luan:http/Http" @@ -84,19 +86,19 @@ </html> <% end -]]%></pre></tt></p> +]]%></pre> <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> -<p>The Luan webserver expects the file to return a function 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 the returned function 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> +<p>The Luan webserver expects the file to return a function 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 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> <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> <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.luanhost.com</b>. If you don't have a domain, just use a domain like <b>bob.s1.luanhost.com</b> (anything of the form <b>*.s1.luanhost.com</b>). Assuming your directory is <b>site</b> and you will use the password <b>secret</b>, do the following from the command line: -<p><tt><pre> +<pre> luan luan:host/push bob.s1.luanhost.com secret site -</pre></tt></p> +</pre> <p>The form is <b>luan luan:host/push 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 domain password</b>.</p> @@ -104,7 +106,6 @@ </div> -<% Html.simply_html_body_bottom() %> </body> </html> <%