Very interesting...<p>Made me jot down a non-mini, non-existent web framework I think I might like to use.... It's only just a tad bit more compact than Tir and will take a lot more effort to implement... but (I hope) it is much easier to tell at a glance what it is doing. Must find time for building my own web framework some day.<p>Corresponding Arc Challenge: (cheated a bit, if you want to make this 'proper' you'd need to add a cookie, and maybe another function.)<p><pre><code> require "filter"
require "form"
require "response"
require "route"
said_form = form.default { saying = form.charfield() }
function said_page(args)
return response.http(said_form.render())
end
function said_click(args)
return response.http(
([[<a href="javascript:document.write(%s)">click here</a>]])
:format(args.post.saying))
end
route.set(filter.get, "^/said/$", said_page)
route.set(filter.post, "^/said/$", said_click)
</code></pre>
Login / Logout<p><pre><code> require "filter"
require "template"
require "form"
require "widget"
require "response"
require "route"
require "generic"
require "css"
login_form = form.default({
username = form.charfield(),
password = form.charfield{widget = widget.password}
})
function login_form:clean(args, data)
if authenticate(data.username, data.password) then
return true
end
args:set_error(self, {'username or password is incorrect'})
args:set_data(self, args.post)
return false
end
function login_check(request)
if request.session['user'] then
return nil, response.redirect("/")
end
return filter.get(request)
end
function login_page(args)
return response.http(template.default.render_with {
head = css.link("my.css"),
body = login_form.render()
})
end
function login_auth(args)
if login_form:clean(args, args.post) then
return response.redirect("/")
end
return login_page(args)
end
route.set(login_check, "^/login/$", login_page)
route.set(filter.post, "^/login/$", login_auth)
route.set(filter.any, "", generic.not_found)</code></pre>