[more progress on the tutorial jeremy@n-heptane.com**20080707225551] { hunk ./HAppSHspTutorial.lhs 11 -

HAppS (the Haskell Application Server framework) recently got a whole lot more awesome because it now supports HTML templating using HSP (Haskell Server Pages).

- +

HAppS (the Haskell Application Server framework) recently got a whole lot more awesome because it now supports HTML templating using HSP (Haskell Server Pages).

hunk ./HAppSHspTutorial.lhs 13 - - hunk ./HAppSHspTutorial.lhs 14 - hunk ./HAppSHspTutorial.lhs 15 - hunk ./HAppSHspTutorial.lhs 18 - hunk ./HAppSHspTutorial.lhs 19 - hunk ./HAppSHspTutorial.lhs 20 - hunk ./HAppSHspTutorial.lhs 21 - hunk ./HAppSHspTutorial.lhs 22 - hunk ./HAppSHspTutorial.lhs 35 - hunk ./HAppSHspTutorial.lhs 40 -
    - +
+ hunk ./HAppSHspTutorial.lhs 46 - hunk ./HAppSHspTutorial.lhs 47 +

This is the basic template for creating a HAppS application using:

+ +

First we have our Main.hs which starts up the dynamic page loading engine, the state engine, and forks of the HTTP service.

+ +> module Main where +> +> import Control.Concurrent +> import HAppS.Server +> import HAppS.State +> import HSP +> import HAppS.Template.HSP +> import HAppS.Template.HSP.Handle +> +> main :: IO () +> main = +> do store <- newStore +> -- control <- startSystemState entryPoint +> tid <- forkIO $ simpleHTTP validateConf $ impl store +> putStrLn "running..." +> waitForTermination +> killThread tid +> -- shutdownSystem control +> destroyStore store + +

The impl function is your typical HAppS-Server impl function, except that it uses the runHSPHandle function provided by happs-hsp-template.

hunk ./HAppSHspTutorial.lhs 78 +> impl :: Store -> [ServerPart Response] +> impl store = +> [ runHSPHandle "pages" "objfiles" store $ multi +> [ method GET $ ok =<< execTemplate Nothing "Index.hs" +> ] +> ] + +

runHSPHandle takes four arguments

+
    +
  1. the directory which holds the templates +
  2. the directory to store the compiled template object files in +
  3. a handle to the store which manages the objects +
  4. a ServerPart a +
+

The execTemplate function is responsible for actually invoking a specific template. It takes two arguments:

+
    +
  1. A default mime-type, doctype, etc, to use if the template does not provide any values. +
  2. The name of the template file relative to the directory passed to runHSPHandle +
hunk ./Makefile 19 -.PHONY: test +.PHONY: test all }