view blog/src/edit.luan @ 658:e038905512d3

compile ReturnStmt
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 05 Apr 2016 18:38:29 -0600
parents 6bb0c83116e9
children ca169567ce07
line wrap: on
line source

local Luan = require "luan:Luan"
local error = Luan.error
local String = require "luan:String"
local to_number = String.to_number or error()
local Io = require "luan:Io"
local Http = require "luan:http/Http"
local Post = require "site:/lib/Post"


return function()
	local post_id = to_number(Http.request.parameter.post) or error()
	local post = Post.get_by_id(post_id) or error()
	if Http.request.parameter.save ~= nil then
		post.subject = Http.request.parameter.subject
		post.content = Http.request.parameter.content
		post.save()
		Http.response.send_redirect("/#p"..post.id)
		return
	end

	Io.stdout = Http.response.text_writer()
%>
<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></p>
			<p>
				<input type=submit name=save value=Submit>
			</p>
		</form>

	</body>
</html>
<%
end