changeset 1217:4c2972f4d862

.html in examples
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 20 Mar 2018 15:43:16 -0600
parents 5dbb552075ff
children a50803fde972
files examples/blog/serve.sh examples/blog/src/edit.html.luan examples/blog/src/edit.luan examples/blog/src/index.html.luan examples/blog/src/new.html.luan examples/blog/src/new.luan examples/blog/src/private/tools/backup.html.luan examples/blog/src/private/tools/backup.luan website/src/examples/hi.html.luan website/src/examples/hi.luan website/src/examples/hi2.html.luan website/src/examples/hi2.luan website/src/examples/upload-and-email.html.luan website/src/examples/upload-and-email.luan website/src/tutorial.html.luan
diffstat 15 files changed, 224 insertions(+), 224 deletions(-) [+]
line wrap: on
line diff
--- a/examples/blog/serve.sh	Tue Mar 20 15:27:08 2018 -0600
+++ b/examples/blog/serve.sh	Tue Mar 20 15:43:16 2018 -0600
@@ -1,1 +1,1 @@
-luan luan:http/serve.luan file:src 2>&1 | tee err
+luan luan:http/serve.luan src 2>&1 | tee err
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/blog/src/edit.html.luan	Tue Mar 20 15:43:16 2018 -0600
@@ -0,0 +1,44 @@
+local Luan = require "luan:Luan.luan"
+local error = Luan.error
+local String = require "luan:String.luan"
+local to_number = String.to_number or error()
+local Io = require "luan:Io.luan"
+local Http = require "luan:http/Http.luan"
+local Post = require "site:/lib/Post.luan"
+
+
+return function()
+	local post_id = to_number(Http.request.parameters.post) or error()
+	local post = Post.get_by_id(post_id) or error()
+	if Http.request.parameters.save ~= nil then
+		post.subject = Http.request.parameters.subject
+		post.content = Http.request.parameters.content
+		post.save()
+		Http.response.send_redirect("/#p"..post.id)
+		return
+	end
+
+	Io.stdout = Http.response.text_writer()
+%>
+<!doctype html>
+<html>
+	<head>
+		<style>
+			@import "/site.css";
+		</style>
+	</head>
+	<body>
+		<h1>Make New Post</h1>
+
+		<form method=post>
+			<p>Subject: <input name=subject size=50 type=text value="<%= post.subject %>"></p>
+			<p><textarea name=content rows=20 cols=90><%= post.content %></textarea><br>bbcode works</p>
+			<p>
+				<input type=submit name=save value=Submit>
+			</p>
+		</form>
+
+	</body>
+</html>
+<%
+end
--- a/examples/blog/src/edit.luan	Tue Mar 20 15:27:08 2018 -0600
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,44 +0,0 @@
-local Luan = require "luan:Luan.luan"
-local error = Luan.error
-local String = require "luan:String.luan"
-local to_number = String.to_number or error()
-local Io = require "luan:Io.luan"
-local Http = require "luan:http/Http.luan"
-local Post = require "site:/lib/Post.luan"
-
-
-return function()
-	local post_id = to_number(Http.request.parameters.post) or error()
-	local post = Post.get_by_id(post_id) or error()
-	if Http.request.parameters.save ~= nil then
-		post.subject = Http.request.parameters.subject
-		post.content = Http.request.parameters.content
-		post.save()
-		Http.response.send_redirect("/#p"..post.id)
-		return
-	end
-
-	Io.stdout = Http.response.text_writer()
-%>
-<!doctype html>
-<html>
-	<head>
-		<style>
-			@import "/site.css";
-		</style>
-	</head>
-	<body>
-		<h1>Make New Post</h1>
-
-		<form method=post>
-			<p>Subject: <input name=subject size=50 type=text value="<%= post.subject %>"></p>
-			<p><textarea name=content rows=20 cols=90><%= post.content %></textarea><br>bbcode works</p>
-			<p>
-				<input type=submit name=save value=Submit>
-			</p>
-		</form>
-
-	</body>
-</html>
-<%
-end
--- a/examples/blog/src/index.html.luan	Tue Mar 20 15:27:08 2018 -0600
+++ b/examples/blog/src/index.html.luan	Tue Mar 20 15:43:16 2018 -0600
@@ -31,7 +31,7 @@
 			<input type=submit value=Search>
 		</form>
 
-		<div><a href="new">Make New Post</a></div>
+		<div><a href="new.html">Make New Post</a></div>
 
 		<%
 		local posts = query and Post.search(query) or Post.get_all()
@@ -39,7 +39,7 @@
 			%>
 			<a name="p<%= post.id %>">
 			<h2><%= post.subject %></h2>
-			<p><%= Time.format(post.date) %> - <a href="edit?post=<%= post.id %>">Edit</a></p>
+			<p><%= Time.format(post.date) %> - <a href="edit.html?post=<%= post.id %>">Edit</a></p>
 			<pre><%= bbcode_to_html(html_encode(post.content)) %></pre>
 			<hr>
 			<%
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/blog/src/new.html.luan	Tue Mar 20 15:43:16 2018 -0600
@@ -0,0 +1,41 @@
+local Luan = require "luan:Luan.luan"
+local error = Luan.error
+local Io = require "luan:Io.luan"
+local Http = require "luan:http/Http.luan"
+local Post = require "site:/lib/Post.luan"
+
+
+return function()
+	local subject = Http.request.parameters.subject
+	local content = Http.request.parameters.content
+	if Http.request.parameters.save ~= nil then
+		local post = Post.new{ subject=subject, content=content }
+		post.save()
+		Http.response.send_redirect("/")
+		return
+	end
+
+	Io.stdout = Http.response.text_writer()
+%>
+<!doctype html>
+<html>
+	<head>
+		<style>
+			@import "/site.css";
+		</style>
+	</head>
+	<body>
+		<h1>Make New Post</h1>
+
+		<form method=post>
+			<p>Subject: <input name=subject size=50 type=text></p>
+			<p><textarea name=content rows=20 cols=90></textarea><br>bbcode works</p>
+			<p>
+				<input type=submit name=save value=Submit>
+			</p>
+		</form>
+
+	</body>
+</html>
+<%
+end
--- a/examples/blog/src/new.luan	Tue Mar 20 15:27:08 2018 -0600
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-local Luan = require "luan:Luan.luan"
-local error = Luan.error
-local Io = require "luan:Io.luan"
-local Http = require "luan:http/Http.luan"
-local Post = require "site:/lib/Post.luan"
-
-
-return function()
-	local subject = Http.request.parameters.subject
-	local content = Http.request.parameters.content
-	if Http.request.parameters.save ~= nil then
-		local post = Post.new{ subject=subject, content=content }
-		post.save()
-		Http.response.send_redirect("/")
-		return
-	end
-
-	Io.stdout = Http.response.text_writer()
-%>
-<!doctype html>
-<html>
-	<head>
-		<style>
-			@import "/site.css";
-		</style>
-	</head>
-	<body>
-		<h1>Make New Post</h1>
-
-		<form method=post>
-			<p>Subject: <input name=subject size=50 type=text></p>
-			<p><textarea name=content rows=20 cols=90></textarea><br>bbcode works</p>
-			<p>
-				<input type=submit name=save value=Submit>
-			</p>
-		</form>
-
-	</body>
-</html>
-<%
-end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/blog/src/private/tools/backup.html.luan	Tue Mar 20 15:43:16 2018 -0600
@@ -0,0 +1,20 @@
+local Io = require "luan:Io.luan"
+local Http = require "luan:http/Http.luan"
+local Db = require "site:/lib/Db.luan"
+
+
+return function()
+	local backup = Io.uri "site:/private/local/backup.zip"
+	backup.delete()
+	Db.zip(backup)
+
+	Io.stdout = Http.response.text_writer()
+%>
+<!doctype html>
+<html>
+	<body>
+		backed up to <a href="/private/local/backup.zip">/private/local/backup.zip</a>
+	</body>
+</html>
+<%
+end
--- a/examples/blog/src/private/tools/backup.luan	Tue Mar 20 15:27:08 2018 -0600
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-local Io = require "luan:Io.luan"
-local Http = require "luan:http/Http.luan"
-local Db = require "site:/lib/Db.luan"
-
-
-return function()
-	local backup = Io.uri "site:/private/local/backup.zip"
-	backup.delete()
-	Db.zip(backup)
-
-	Io.stdout = Http.response.text_writer()
-%>
-<!doctype html>
-<html>
-	<body>
-		backed up to <a href="/private/local/backup.zip">/private/local/backup.zip</a>
-	</body>
-</html>
-<%
-end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/website/src/examples/hi.html.luan	Tue Mar 20 15:43:16 2018 -0600
@@ -0,0 +1,15 @@
+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
--- a/website/src/examples/hi.luan	Tue Mar 20 15:27:08 2018 -0600
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/website/src/examples/hi2.html.luan	Tue Mar 20 15:43:16 2018 -0600
@@ -0,0 +1,41 @@
+local Io = require "luan:Io.luan"
+local Http = require "luan:http/Http.luan"
+
+
+local function form()
+%>
+<!doctype html>
+<html>
+	<body>
+		<h1>Hello</h1>
+		<form>
+			What is your name?
+			<input name="name">
+			<input type=submit>
+		</form>
+	</body>
+</html>
+<%
+end
+
+local function hello(name)
+%>
+<!doctype html>
+<html>
+	<body>
+		<h1>Hello</h1>
+		<p>Hi <%= name %>!</p>
+	</body>
+</html>
+<%
+end
+
+return function()
+	Io.stdout = Http.response.text_writer()
+	local name = Http.request.parameters.name
+	if name == nil then
+		form()
+	else
+		hello(name)
+	end
+end
--- a/website/src/examples/hi2.luan	Tue Mar 20 15:27:08 2018 -0600
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-local Io = require "luan:Io.luan"
-local Http = require "luan:http/Http.luan"
-
-
-local function form()
-%>
-<!doctype html>
-<html>
-	<body>
-		<h1>Hello</h1>
-		<form>
-			What is your name?
-			<input name="name">
-			<input type=submit>
-		</form>
-	</body>
-</html>
-<%
-end
-
-local function hello(name)
-%>
-<!doctype html>
-<html>
-	<body>
-		<h1>Hello</h1>
-		<p>Hi <%= name %>!</p>
-	</body>
-</html>
-<%
-end
-
-return function()
-	Io.stdout = Http.response.text_writer()
-	local name = Http.request.parameters.name
-	if name == nil then
-		form()
-	else
-		hello(name)
-	end
-end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/website/src/examples/upload-and-email.html.luan	Tue Mar 20 15:43:16 2018 -0600
@@ -0,0 +1,57 @@
+local Io = require "luan:Io.luan"
+local Http = require "luan:http/Http.luan"
+local Mail = require "luan:mail/Mail.luan"
+
+
+local send = Mail.Sender{
+	host = "smtpcorp.com";
+	username = "smtp@luanhost.com";
+	password = "luanhost";
+	port = 2525;
+}.send
+
+local function form()
+%>
+<!doctype html>
+<html>
+	<body>
+		<h1>Upload and Email</h1>
+		<form method="post" enctype="multipart/form-data">
+			<p>Email: <input name=email></p>
+			<p><input type=file name=file></p>
+			<p><input type=submit></p>
+		</form>
+	</body>
+</html>
+<%
+end
+
+local function sent()
+%>
+<!doctype html>
+<html>
+	<body>
+		<h1>Upload and Email</h1>
+		<p>file sent</p>
+	</body>
+</html>
+<%
+end
+
+return function()
+	Io.stdout = Http.response.text_writer()
+	local email = Http.request.parameters.email
+	if email == nil then
+		form()
+	else
+		local file = Http.request.parameters.file
+		send{
+			from = "smtp@luanhost.com";
+			to = email;
+			subject = "Upload and Email";
+			body = "file should be attached";
+			attachments = {file};
+		}
+		sent()
+	end
+end
--- a/website/src/examples/upload-and-email.luan	Tue Mar 20 15:27:08 2018 -0600
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,57 +0,0 @@
-local Io = require "luan:Io.luan"
-local Http = require "luan:http/Http.luan"
-local Mail = require "luan:mail/Mail.luan"
-
-
-local send = Mail.Sender{
-	host = "smtpcorp.com";
-	username = "smtp@luanhost.com";
-	password = "luanhost";
-	port = 2525;
-}.send
-
-local function form()
-%>
-<!doctype html>
-<html>
-	<body>
-		<h1>Upload and Email</h1>
-		<form method="post" enctype="multipart/form-data">
-			<p>Email: <input name=email></p>
-			<p><input type=file name=file></p>
-			<p><input type=submit></p>
-		</form>
-	</body>
-</html>
-<%
-end
-
-local function sent()
-%>
-<!doctype html>
-<html>
-	<body>
-		<h1>Upload and Email</h1>
-		<p>file sent</p>
-	</body>
-</html>
-<%
-end
-
-return function()
-	Io.stdout = Http.response.text_writer()
-	local email = Http.request.parameters.email
-	if email == nil then
-		form()
-	else
-		local file = Http.request.parameters.file
-		send{
-			from = "smtp@luanhost.com";
-			to = email;
-			subject = "Upload and Email";
-			body = "file should be attached";
-			attachments = {file};
-		}
-		sent()
-	end
-end
--- a/website/src/tutorial.html.luan	Tue Mar 20 15:27:08 2018 -0600
+++ b/website/src/tutorial.html.luan	Tue Mar 20 15:43:16 2018 -0600
@@ -71,7 +71,7 @@
 
 <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>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.html.luan</b> containing:
 
 <pre><%=Html.encode[[
 	local Io = require "luan:Io.luan"
@@ -90,11 +90,11 @@
 	end
 ]]%></pre>
 
-<p>Now go back to the parent directory and do <b>luan luan:http/serve.luan 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>Now go back to the parent directory and do <b>luan luan:http/serve.luan 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.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>
 
 <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>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: