Permalink
Browse files

make the preview render using Post.to_xhtml now, and add the blog pos…

…t listing on the main page
  • Loading branch information...
1 parent d49918a commit d23bca917583840f2bdcf24ebc4a487b75d7c55e Austin Seipp committed Jun 13, 2011
Showing with 32 additions and 9 deletions.
  1. +11 −4 src/admin.opa
  2. +9 −3 src/main.opa
  3. +12 −2 src/post.opa
View
@@ -1,6 +1,8 @@
package opaque.admin
import widgets.loginbox
+import opaque.config
+import opaque.post
import opaque.layout
// plugins
@@ -9,6 +11,7 @@ import opaque.bsl.mathjax
import opaque.bsl.shjs
import opaque.bsl.upskirt
+
// User types and user database
type Admin.user = { passwd: string }
type Admin.status = { loggedin: string } / { notloggedin }
@@ -68,17 +71,21 @@ Admin = {{
/* New posts */
@private @publish update_preview() =
- v = Upskirt.render_to_xhtml(Dom.get_value(#post_entry))
- do Dom.transform([#preview_output <- v])
+ p : Post.post = { title = Dom.get_value(#post_title);
+ date = Date.now();
+ content = Dom.get_value(#post_content);
+ author = Config.author }
+ do Dom.transform([#preview_output <- Post.to_xhtml(p)])
do MathJax.reload(#preview_output)
SHJS.highlight()
newpost() =
post_form() =
<div id=#inputarea>
- <textarea rows=20 cols=80 id=#post_entry /><br/>
+ <input cols=80 id=#post_title /><br />
+ <textarea rows=20 cols=80 id=#post_content /><br />
<button type="button" onclick={_ -> update_preview()}>Preview</button><br />
- <button type="button" >Publish</button>
+ <button type="button" >Publish</button><br />
<h3><a href="/admin">Go back to admin page</a></h3>
</div>
<br/>
View
@@ -1,12 +1,18 @@
package opaque.main
+import stdlib.map
+import stdlib.date
+
import opaque.admin
import opaque.layout
import opaque.config
+import opaque.post
-mainpage() = Layout.styled_page(Config.title,
+mainpage() =
+ toListItem(v) = <li><span>{Date.to_string(v.date)}</span> - {v.title}</li>
+ Layout.styled_page(Config.title,
<h1>Blog Posts</h1>
<ul class="posts">
- <li>TODO</li>
+ {Xml.list_to_xml(toListItem, Post.posts_to_list())}
</ul>
<h1>A section of things you want to list, like interviews</h1>
@@ -18,7 +24,7 @@ mainpage() = Layout.styled_page(Config.title,
<ul class="posts">
<li><a href="http://github.com">blah:</a> my foobar project.</li>
</ul>
-)
+ )
start =
| {path = [] ... } -> mainpage()
View
@@ -1,5 +1,7 @@
package opaque.post
import stdlib.date
+import stdlib.map
+
import opaque.bsl.upskirt
type Post.post = { title: string;
@@ -9,10 +11,18 @@ type Post.post = { title: string;
db /posts : intmap(Post.post)
-Post = {{
+@server Post = {{
+
+ insert_post(p) = /posts[?] <- p
+ get_posts() = /posts
+ get_post(i) = ?/posts[i]
+
+ posts_to_list() =
+ Map_make(Int.order).To.val_list(get_posts())
+
to_xhtml(p) =
content = Upskirt.render_to_xhtml(p.content)
<h1>{p.title}</h1>
- <p class="meta">{Date.to_string(p.date)}</p>
+ <p class="meta">{Date.to_string(p.date)}, by {p.author}</p>
<>{content}</>
}}

0 comments on commit d23bca9

Please sign in to comment.