Mercurial Hosting > luan
diff examples/blog/src/index.html.luan @ 779:c38f6619feb9
move blog into examples
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 28 Aug 2016 14:50:47 -0600 |
parents | blog/src/index.html.luan@1460d297e960 |
children | 21d157b153fe |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/blog/src/index.html.luan Sun Aug 28 14:50:47 2016 -0600 @@ -0,0 +1,51 @@ +local Luan = require "luan:Luan.luan" +local error = Luan.error +local ipairs = Luan.ipairs or error() +local Time = require "luan:Time.luan" +local Io = require "luan:Io.luan" +local Parsers = require "luan:Parsers.luan" +local bbcode_to_html = Parsers.bbcode_to_html or error() +local Html = require "luan:Html.luan" +local html_encode = Html.encode or error() +local Http = require "luan:http/Http.luan" +local Post = require "site:/lib/Post.luan" + + +return function() + local query = Http.request.parameter.query + + Io.stdout = Http.response.text_writer() +%> +<html> + <head> + <style> + @import "/site.css"; + </style> + </head> + <body> + <h1><a href="/">Demo Blog App</a></h1> + + <form> + <input name=query type=text value="<%= query or "" %>"> + <input type=submit value=Search> + </form> + + <div><a href="new">Make New Post</a></div> + + <% + local posts = query and Post.search(query) or Post.get_all() + for _, post in ipairs(posts) do + %> + <a name="p<%= post.id %>"> + <h2><%= post.subject %></h2> + <p><%= Time.format(post.date) %> - <a href="edit?post=<%= post.id %>">Edit</a></p> + <pre><%= bbcode_to_html(html_encode(post.content)) %></pre> + <hr> + <% + end + %> + + </body> +</html> +<% +end