Permalink
Browse files

add ability to view posts!

  • Loading branch information...
1 parent e169a76 commit 29127e52126a3fe5452f8d250d4fd7b4200de5c1 Austin Seipp committed Jun 13, 2011
Showing with 30 additions and 15 deletions.
  1. +7 −8 src/layout.opa
  2. +4 −3 src/main.opa
  3. +19 −4 src/post.opa
View
@@ -1,16 +1,13 @@
package opaque.layout
-import opaque.post
-import opaque.bsl.native
import opaque.config
+import opaque.bsl.native
Layout = {{
- @private styles = [ "res/style.css"
- , "res/sh_nedit.min.css" ]
+ @private styles = [ "/res/style.css"
+ , "/res/sh_nedit.min.css" ]
styled_page(t, p) = Resource.styled_page(t, styles, default_layout(p))
- post_layout(p) =
- <div id=#post>{Post.to_xhtml(p)}</div>
@client transform_content(s) =
Dom.transform([#page_content <- s])
@@ -22,8 +19,8 @@ Layout = {{
release = get_sys_release()
machine = get_sys_machine()
- <script type="text/javascript" src="res/sh_main.min.js"/>
- <script type="text/javascript" src="res/sh_haskell.min.js"/>
+ <script type="text/javascript" src="/res/sh_main.min.js"/>
+ <script type="text/javascript" src="/res/sh_haskell.min.js"/>
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"/>
<body>
<div class="site">
@@ -58,4 +55,6 @@ Layout = {{
</div>
</div>
</body>
+
+
}}
View
@@ -27,9 +27,10 @@ mainpage() =
)
start =
- | {path = [] ... } -> mainpage()
- | {path = ["admin" | _] ...} -> Admin.mainpage()
- | {path = _ ...} -> mainpage()
+ | {path = [] ... } -> mainpage()
+ | {path = ["admin" | _] ...} -> Admin.mainpage()
+ | {path = ["post", x | _] ...} -> Post.postpage(x)
+ | {path = _ ...} -> mainpage()
server = Server.of_bundle([@static_resource_directory("res")])
server = Server.simple_dispatch(start)
View
@@ -2,7 +2,10 @@ package opaque.post
import stdlib.date
import stdlib.map
+import opaque.layout
+
import opaque.bsl.upskirt
+import opaque.bsl.shjs
type Post.post = { title: string;
date: Date.date
@@ -13,17 +16,29 @@ db /posts : intmap(Post.post)
@server Post = {{
+ /* Utility functions, mostly */
insert_new_post(p) = /posts[?] <- p
update_post(i,p) = /posts[i] <- p
get_posts() = /posts
get_post(i) = ?/posts[i]
-
posts_to_list() =
List.rev(Map_make(Int.order).To.val_list(get_posts()))
+ postpage(x) =
+ match Parser.int(x) with
+ | {none} -> Layout.styled_page("Invalid URL",<h1>Invalid URL</h1>)
+ | {some = i} -> render_page(i)
+
+ render_page(i) =
+ match get_post(i) with
+ | {none} -> Layout.styled_page("Invalid post number",<h1>Invalid post number</h1>)
+ | {some = p} -> Layout.styled_page(p.title, to_xhtml(p))
+
to_xhtml(p) =
content = Upskirt.render_to_xhtml(p.content)
- <h1>{p.title}</h1>
- <p class="meta">{Date.to_string(p.date)}, by {p.author}</p>
- <>{content}</>
+ <div id=#post onready={_ -> SHJS.highlight()}>
+ <h1>{p.title}</h1>
+ <p class="meta">{Date.to_string(p.date)}, by {p.author}</p>
+ <>{content}</>
+ </div>
}}

0 comments on commit 29127e5

Please sign in to comment.