File: example2.hs

package info (click to toggle)
haskell-hsx-jmacro 7.3.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 88 kB
  • sloc: haskell: 252; makefile: 2
file content (36 lines) | stat: -rw-r--r-- 1,018 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{-# LANGUAGE FlexibleInstances, QuasiQuotes #-}
{-# OPTIONS_GHC -F -pgmFtrhsx #-}
module Main where

import Language.Javascript.JMacro
import HSX.JMacro
import HSX.JMacroT
import HSP
import HSP.ServerPartT
import Happstack.Server
import Happstack.Server.HSP.HTML
import Happstack.Server.JMacro
import Data.Unique
import Control.Monad.Trans

instance IntegerSupply (ServerPartT IO) where
    nextInteger = fmap (fromIntegral . (`mod` 1024) . hashUnique) (liftIO newUnique)

main :: IO ()
main =
    do let html :: XMLGenT JMacroM JExpr
           html = <p>Generate javascript from <span class="foo" id="h">HTML & XML</span></p>

           js :: JStat
           js = [jmacro| document.getElementById('main').appendChild(`(html)`);
                       |]

           handler :: ServerPart XML
           handler = defaultTemplate "js-example" ()
                       <%>
                         <div id="main" />
                         <% js %>
                       </%>

       simpleHTTP nullConf handler