» "Hello World" for Perpubplat #

Paul R. Brown @ 2008-01-04

Setting up perpubplat to talk to a web server takes a bit of work, but once you've got the code, bootstrapping a post can be done with just ghci.

The perpubplat configuration in the Darcs repository expects to find posts and comments stored under /tmp/content and drafts stored under /tmp/drafts. (Clearly, a different configuration would be desirable for production use...) Create those directories and then a file /tmp/drafts/hello-world.draft with the following contents:

title: Hello, World!
tags: one two three

--- START BODY ---

<p>Hello, World!</p>

--- END BODY ---

Next, load up the code in ghci:

$ cd perpubplat/perpubplat/src
$ ghci Blog.BackEnd.IoOperations Blog.Model.Entry \
  Blog.BackEnd.ModelTransformations Blog.FrontEnd.Presentation \
  Blog.FrontEnd.Views
GHCi, version 6.8.2: http://www.haskell.org/ghc/  :? for help
Loading package base ... linking ... done.
[ 1 of 13] Compiling Blog.Widgets.FlickrBadge ( Blog/Widgets/FlickrBadge.hs, interpreted )
[...]
Ok, modules loaded: Utilities, Blog.Constants, Blog.Model.Entry, [...]
*Blog.BackEnd.IoOperations> :set prompt "> "
> :m + Blog.BackEnd.ModelTransformations Blog.FrontEnd.Views Blog.FrontEnd.Presentation
> m <- boot
> (s,m') <- ingest_draft m "hello-world.draft"

The ingest_draft function does the work of adding the post parsed from the draft to the internal data structure (some maps and lists bundled together) and storing the new post in the content directory. You can find it in /tmp/content/hello-world/content.ppp.

For a little more exercise, here's how to render the "all posts" view containing the new post:

> assemble_view (All Nothing) m'
Loading package xhtml-3000.0.2.1 ... linking ... done.
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" [...]

Which is the XHTML that would be displayed in the browser. As to the content of the internal data model for the post we just created:

> :m + Blog.Model.Entry
> s
"hello-world"
> post_by_permatitle m' s
Item {internal_id = 0, kind = Post, title = "Hello, World!" [...]

And that's all there is to it.

 

← 2008-01-04 — Darcs Repository for Perpubplat
→ 2008-01-08 — A Little Love for Io